diff options
Diffstat (limited to 'app/helpers/diff_helper.rb')
-rw-r--r-- | app/helpers/diff_helper.rb | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 32431959851..7b733c496eb 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -16,7 +16,7 @@ module DiffHelper def diff_view @diff_view ||= begin - diff_views = %w(inline parallel) + diff_views = %w[inline parallel] diff_view = params[:view] || cookies[:diff_view] diff_view = diff_views.first unless diff_views.include?(diff_view) diff_view.to_sym @@ -24,9 +24,9 @@ module DiffHelper end def diff_options - options = { ignore_whitespace_change: hide_whitespace?, expanded: diffs_expanded? } + options = {ignore_whitespace_change: hide_whitespace?, expanded: diffs_expanded?} - if action_name == 'diff_for_path' + if action_name == "diff_for_path" options[:expanded] = true options[:paths] = params.values_at(:old_path, :new_path) end @@ -34,23 +34,23 @@ module DiffHelper options end - def diff_match_line(old_pos, new_pos, text: '', view: :inline, bottom: false) + def diff_match_line(old_pos, new_pos, text: "", view: :inline, bottom: false) content_line_class = %w[line_content match] - content_line_class << 'parallel' if view == :parallel + content_line_class << "parallel" if view == :parallel line_num_class = %w[diff-line-num unfold js-unfold] - line_num_class << 'js-unfold-bottom' if bottom + line_num_class << "js-unfold-bottom" if bottom html = [] if old_pos - html << content_tag(:td, '...', class: [*line_num_class, 'old_line'], data: { linenumber: old_pos }) - html << content_tag(:td, text, class: [*content_line_class, 'left-side']) if view == :parallel + html << content_tag(:td, "...", class: [*line_num_class, "old_line"], data: {linenumber: old_pos}) + html << content_tag(:td, text, class: [*content_line_class, "left-side"]) if view == :parallel end if new_pos - html << content_tag(:td, '...', class: [*line_num_class, 'new_line'], data: { linenumber: new_pos }) - html << content_tag(:td, text, class: [*content_line_class, ('right-side' if view == :parallel)]) + html << content_tag(:td, "...", class: [*line_num_class, "new_line"], data: {linenumber: new_pos}) + html << content_tag(:td, text, class: [*content_line_class, ("right-side" if view == :parallel)]) end html.join.html_safe @@ -61,7 +61,7 @@ module DiffHelper " ".html_safe else # We can't use `sub` because the HTML-safeness of `line` will not survive. - line[0] = '' if line.start_with?('+', '-', ' ') + line[0] = "" if line.start_with?("+", "-", " ") line end end @@ -71,12 +71,12 @@ module DiffHelper discussions_left = discussions_right = nil - if left && left.discussable? && (left.unchanged? || left.removed?) + if left&.discussable? && (left&.unchanged? || left&.removed?) line_code = diff_file.line_code(left) discussions_left = @grouped_diff_discussions[line_code] end - if right && right.discussable? && right.added? + if right&.discussable? && right&.added? line_code = diff_file.line_code(right) discussions_right = @grouped_diff_discussions[line_code] end @@ -85,26 +85,26 @@ module DiffHelper end def inline_diff_btn - diff_btn('Inline', 'inline', diff_view == :inline) + diff_btn("Inline", "inline", diff_view == :inline) end def parallel_diff_btn - diff_btn('Side-by-side', 'parallel', diff_view == :parallel) + diff_btn("Side-by-side", "parallel", diff_view == :parallel) end def submodule_link(blob, ref, repository = @repository) project_url, tree_url = submodule_links(blob, ref, repository) commit_id = if tree_url.nil? - Commit.truncate_sha(blob.id) - else - link_to Commit.truncate_sha(blob.id), tree_url - end + Commit.truncate_sha(blob.id) + else + link_to Commit.truncate_sha(blob.id), tree_url + end [ content_tag(:span, link_to(truncate(blob.name, length: 40), project_url)), - '@', - content_tag(:span, commit_id, class: 'commit-sha') - ].join(' ').html_safe + "@", + content_tag(:span, commit_id, class: "commit-sha"), + ].join(" ").html_safe end def diff_file_blob_raw_url(diff_file, only_path: false) @@ -129,8 +129,8 @@ module DiffHelper def diff_file_html_data(project, diff_file_path, diff_commit_id) { blob_diff_path: project_blob_diff_path(project, - tree_join(diff_commit_id, diff_file_path)), - view: diff_view + tree_join(diff_commit_id, diff_file_path)), + view: diff_view, } end @@ -165,7 +165,7 @@ module DiffHelper # Always use HTML to handle case where JSON diff rendered this button params_copy.delete(:format) - link_to url_for(params_copy), id: "#{name}-diff-btn", class: (selected ? 'btn active' : 'btn'), data: { view_type: name } do + link_to url_for(params_copy), id: "#{name}-diff-btn", class: (selected ? "btn active" : "btn"), data: {view_type: name} do title end end @@ -186,7 +186,7 @@ module DiffHelper end def hide_whitespace? - params[:w] == '1' + params[:w] == "1" end # rubocop: disable CodeReuse/ActiveRecord @@ -196,8 +196,8 @@ module DiffHelper # rubocop: enable CodeReuse/ActiveRecord def toggle_whitespace_link(url, options) - options[:class] = [*options[:class], 'btn btn-default'].join(' ') - link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class] + options[:class] = [*options[:class], "btn btn-default"].join(" ") + link_to "#{hide_whitespace? ? "Show" : "Hide"} whitespace changes", url, class: options[:class] end def render_overflow_warning?(diff_files) |