summaryrefslogtreecommitdiff
path: root/app/helpers/blob_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/blob_helper.rb')
-rw-r--r--app/helpers/blob_helper.rb116
1 files changed, 62 insertions, 54 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 3e1bb9af5cc..62da4a47afd 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -8,18 +8,18 @@ module BlobHelper
end
def no_highlight_files
- %w(credits changelog news copying copyright license authors)
+ %w[credits changelog news copying copyright license authors]
end
def edit_blob_path(project = @project, ref = @ref, path = @path, options = {})
project_edit_blob_path(project,
- tree_join(ref, path),
- options[:link_opts])
+ tree_join(ref, path),
+ options[:link_opts])
end
def ide_edit_path(project = @project, ref = @ref, path = @path, options = {})
- segments = [ide_path, 'project', project.full_path, 'edit', ref]
- segments.concat(['-', path]) if path.present?
+ segments = [ide_path, "project", project.full_path, "edit", ref]
+ segments.concat(["-", path]) if path.present?
File.join(segments)
end
@@ -29,11 +29,11 @@ module BlobHelper
common_classes = "btn js-edit-blob #{options[:extra_class]}"
edit_button_tag(blob,
- common_classes,
- _('Edit'),
- Feature.enabled?(:web_ide_default) ? ide_edit_path(project, ref, path, options) : edit_blob_path(project, ref, path, options),
- project,
- ref)
+ common_classes,
+ _("Edit"),
+ Feature.enabled?(:web_ide_default) ? ide_edit_path(project, ref, path, options) : edit_blob_path(project, ref, path, options),
+ project,
+ ref)
end
def ide_edit_button(project = @project, ref = @ref, path = @path, options = {})
@@ -41,28 +41,32 @@ module BlobHelper
return unless blob = readable_blob(options, path, project, ref)
edit_button_tag(blob,
- 'btn btn-default',
- _('Web IDE'),
- ide_edit_path(project, ref, path, options),
- project,
- ref)
+ "btn btn-default",
+ _("Web IDE"),
+ ide_edit_path(project, ref, path, options),
+ project,
+ ref)
end
def modify_file_button(project = @project, ref = @ref, path = @path, label:, action:, btn_class:, modal_type:)
return unless current_user
- blob = project.repository.blob_at(ref, path) rescue nil
+ blob = begin
+ project.repository.blob_at(ref, path)
+ rescue
+ nil
+ end
return unless blob
common_classes = "btn btn-#{btn_class}"
if !on_top_of_branch?(project, ref)
- button_tag label, class: "#{common_classes} disabled has-tooltip", title: "You can only #{action} files when you are on a branch", data: { container: 'body' }
+ button_tag label, class: "#{common_classes} disabled has-tooltip", title: "You can only #{action} files when you are on a branch", data: {container: "body"}
elsif blob.stored_externally?
- button_tag label, class: "#{common_classes} disabled has-tooltip", title: "It is not possible to #{action} files that are stored in LFS using the web interface", data: { container: 'body' }
+ button_tag label, class: "#{common_classes} disabled has-tooltip", title: "It is not possible to #{action} files that are stored in LFS using the web interface", data: {container: "body"}
elsif can_modify_blob?(blob, project, ref)
- button_tag label, class: "#{common_classes}", 'data-target' => "#modal-#{modal_type}-blob", 'data-toggle' => 'modal'
+ button_tag label, :class => common_classes.to_s, "data-target" => "#modal-#{modal_type}-blob", "data-toggle" => "modal"
elsif can?(current_user, :fork_project, project) && can?(current_user, :create_merge_request_in, project)
edit_fork_button_tag(common_classes, project, label, edit_modify_file_fork_params(action), action)
end
@@ -73,9 +77,9 @@ module BlobHelper
project,
ref,
path,
- label: "Replace",
- action: "replace",
- btn_class: "default",
+ label: "Replace",
+ action: "replace",
+ btn_class: "default",
modal_type: "upload"
)
end
@@ -85,9 +89,9 @@ module BlobHelper
project,
ref,
path,
- label: "Delete",
- action: "delete",
- btn_class: "remove",
+ label: "Delete",
+ action: "delete",
+ btn_class: "remove",
modal_type: "remove"
)
end
@@ -102,9 +106,9 @@ module BlobHelper
def editing_preview_title(filename)
if Gitlab::MarkupHelper.previewable?(filename)
- 'Preview'
+ "Preview"
else
- 'Preview changes'
+ "Preview changes"
end
end
@@ -113,7 +117,7 @@ module BlobHelper
# mode - File unix mode
# mode - File name
def blob_icon(mode, name)
- icon("#{file_type_icon_class('file', mode, name)} fw")
+ icon("#{file_type_icon_class("file", mode, name)} fw")
end
def blob_raw_url(**kwargs)
@@ -150,9 +154,9 @@ module BlobHelper
categories = grouped.keys
categories.each_with_object({}) do |category, hash|
- hash[category] = grouped[category].map do |item|
- { name: item.name, id: item.key }
- end
+ hash[category] = grouped[category].map { |item|
+ {name: item.name, id: item.key}
+ }
end
end
private :template_dropdown_names
@@ -175,16 +179,16 @@ module BlobHelper
def blob_editor_paths(project)
{
- 'relative-url-root' => Rails.application.config.relative_url_root,
- 'assets-prefix' => Gitlab::Application.config.assets.prefix,
- 'blob-filename' => @blob && @blob.path,
- 'project-id' => project.id,
- 'is-markdown' => @blob && @blob.path && Gitlab::MarkupHelper.gitlab_markdown?(@blob.path)
+ "relative-url-root" => Rails.application.config.relative_url_root,
+ "assets-prefix" => Gitlab::Application.config.assets.prefix,
+ "blob-filename" => @blob&.path,
+ "project-id" => project.id,
+ "is-markdown" => @blob&.path && Gitlab::MarkupHelper.gitlab_markdown?(@blob.path),
}
end
def copy_file_path_button(file_path)
- clipboard_button(text: file_path, gfm: "`#{file_path}`", class: 'btn-clipboard btn-transparent prepend-left-5', title: 'Copy file path to clipboard')
+ clipboard_button(text: file_path, gfm: "`#{file_path}`", class: "btn-clipboard btn-transparent prepend-left-5", title: "Copy file path to clipboard")
end
def copy_blob_source_button(blob)
@@ -197,15 +201,15 @@ module BlobHelper
return if blob.empty?
return if blob.binary? || blob.stored_externally?
- title = 'Open raw'
- link_to icon('file-code-o'), blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ title = "Open raw"
+ link_to icon("file-code-o"), blob_raw_path, class: "btn btn-sm has-tooltip", target: "_blank", rel: "noopener noreferrer", title: title, data: {container: "body"}
end
def download_blob_button(blob)
return if blob.empty?
- title = 'Download'
- link_to sprite_icon('download'), blob_raw_path(inline: false), download: @path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ title = "Download"
+ link_to sprite_icon("download"), blob_raw_path(inline: false), download: @path, class: "btn btn-sm has-tooltip", target: "_blank", rel: "noopener noreferrer", title: title, data: {container: "body"}
end
def blob_render_error_reason(viewer)
@@ -217,11 +221,11 @@ module BlobHelper
when :server_side_but_stored_externally
case viewer.blob.external_storage
when :lfs
- 'it is stored in LFS'
+ "it is stored in LFS"
when :build_artifact
- 'it is stored as a job artifact'
+ "it is stored as a job artifact"
else
- 'it is stored externally'
+ "it is stored externally"
end
end
end
@@ -231,16 +235,16 @@ module BlobHelper
options = []
if error == :collapsed
- options << link_to('load it anyway', url_for(safe_params.merge(viewer: viewer.type, expanded: true, format: nil)))
+ options << link_to("load it anyway", url_for(safe_params.merge(viewer: viewer.type, expanded: true, format: nil)))
end
# If the error is `:server_side_but_stored_externally`, the simple viewer will show the same error,
# so don't bother switching.
if viewer.rich? && viewer.blob.rendered_as_text? && error != :server_side_but_stored_externally
- options << link_to('view the source', '#', class: 'js-blob-viewer-switch-btn', data: { viewer: 'simple' })
+ options << link_to("view the source", "#", class: "js-blob-viewer-switch-btn", data: {viewer: "simple"})
end
- options << link_to('download it', blob_raw_path, target: '_blank', rel: 'noopener noreferrer')
+ options << link_to("download it", blob_raw_path, target: "_blank", rel: "noopener noreferrer")
options
end
@@ -262,7 +266,11 @@ module BlobHelper
def readable_blob(options, path, project, ref)
blob = options.delete(:blob)
- blob ||= project.repository.blob_at(ref, path) rescue nil
+ blob ||= begin
+ project.repository.blob_at(ref, path)
+ rescue
+ nil
+ end
blob if blob&.readable_text?
end
@@ -271,7 +279,7 @@ module BlobHelper
{
to: path,
notice: edit_in_new_fork_notice,
- notice_now: edit_in_new_fork_notice_now
+ notice_now: edit_in_new_fork_notice_now,
}
end
@@ -279,20 +287,20 @@ module BlobHelper
{
to: request.fullpath,
notice: edit_in_new_fork_notice_action(action),
- notice_now: edit_in_new_fork_notice_now
+ notice_now: edit_in_new_fork_notice_now,
}
end
- def edit_fork_button_tag(common_classes, project, label, params, action = 'edit')
+ def edit_fork_button_tag(common_classes, project, label, params, action = "edit")
fork_path = project_forks_path(project, namespace_key: current_user.namespace.id, continue: params)
button_tag label,
- class: "#{common_classes} js-edit-blob-link-fork-toggler",
- data: { action: action, fork_path: fork_path }
+ class: "#{common_classes} js-edit-blob-link-fork-toggler",
+ data: {action: action, fork_path: fork_path}
end
def edit_disabled_button_tag(button_text, common_classes)
- button_tag(button_text, class: "#{common_classes} disabled has-tooltip", title: _('You can only edit files when you are on a branch'), data: { container: 'body' })
+ button_tag(button_text, class: "#{common_classes} disabled has-tooltip", title: _("You can only edit files when you are on a branch"), data: {container: "body"})
end
def edit_link_tag(link_text, edit_path, common_classes)