diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-06 18:15:27 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-07-08 13:53:51 +0100 |
commit | ff55398aafa2feccaba4ed470becabc526b4df48 (patch) | |
tree | 8e1ed3913312e48f9d9857afb5f603923fbfeff3 /app/controllers/concerns | |
parent | 6a46926f88d504778ae49f7824d2b1284a1c62ff (diff) | |
download | gitlab-ce-ff55398aafa2feccaba4ed470becabc526b4df48.tar.gz |
DRY up diff_for_path actions
1. Move render method to a concern, not a helper.
2. Let DiffHelper#diff_options automatically add the path option.
3. Move more instance var definitions to before filters.
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/diff_for_path.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/controllers/concerns/diff_for_path.rb b/app/controllers/concerns/diff_for_path.rb new file mode 100644 index 00000000000..b9b5d136bd9 --- /dev/null +++ b/app/controllers/concerns/diff_for_path.rb @@ -0,0 +1,23 @@ +module DiffForPath + extend ActiveSupport::Concern + + def render_diff_for_path(diffs, diff_refs, project) + diff_file = safe_diff_files(diffs, diff_refs: diff_refs, repository: project.repository).first + + return render_404 unless diff_file + + diff_commit = commit_for_diff(diff_file) + blob = diff_file.blob(diff_commit) + @expand_all = true + + locals = { + diff_file: diff_file, + diff_commit: diff_commit, + diff_refs: diff_refs, + blob: blob, + project: project + } + + render json: { html: view_to_html_string('projects/diffs/_content', locals) } + end +end |