Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-08 12:06:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-08 12:06:07 +0300
commitd23b2a0871f3ca507aafa949e0314625f1f0c6a7 (patch)
treeb1e26c7460bdae25f19103e14978a3aaeef52037 /app/helpers/snippets_helper.rb
parent1ef4b65f55f4fc6524a47050b4f6d686beb81d3a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/helpers/snippets_helper.rb')
-rw-r--r--app/helpers/snippets_helper.rb81
1 files changed, 57 insertions, 24 deletions
diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb
index 6ccc1fb2ed1..10e31fb8888 100644
--- a/app/helpers/snippets_helper.rb
+++ b/app/helpers/snippets_helper.rb
@@ -11,22 +11,40 @@ module SnippetsHelper
end
end
- def reliable_snippet_path(snippet, opts = nil)
+ def reliable_snippet_path(snippet, opts = {})
+ reliable_snippet_url(snippet, opts.merge(only_path: true))
+ end
+
+ def reliable_raw_snippet_path(snippet, opts = {})
+ reliable_raw_snippet_url(snippet, opts.merge(only_path: true))
+ end
+
+ def reliable_snippet_url(snippet, opts = {})
if snippet.project_id?
- project_snippet_path(snippet.project, snippet, opts)
+ project_snippet_url(snippet.project, snippet, nil, opts)
else
- snippet_path(snippet, opts)
+ snippet_url(snippet, nil, opts)
end
end
- def download_snippet_path(snippet)
- if snippet.project_id
- raw_project_snippet_path(@project, snippet, inline: false)
+ def reliable_raw_snippet_url(snippet, opts = {})
+ if snippet.project_id?
+ raw_project_snippet_url(snippet.project, snippet, nil, opts)
else
- raw_snippet_path(snippet, inline: false)
+ raw_snippet_url(snippet, nil, opts)
end
end
+ def download_raw_snippet_button(snippet)
+ link_to(icon('download'),
+ reliable_raw_snippet_path(snippet, inline: false),
+ target: '_blank',
+ rel: 'noopener noreferrer',
+ class: "btn btn-sm has-tooltip",
+ title: 'Download',
+ data: { container: 'body' })
+ end
+
# Return the path of a snippets index for a user or for a project
#
# @returns String, path to snippet index
@@ -114,30 +132,45 @@ module SnippetsHelper
{ snippet_object: snippet, snippet_chunks: snippet_chunks }
end
- def snippet_embed
- "<script src=\"#{url_for(only_path: false, overwrite_params: nil)}.js\"></script>"
+ def snippet_embed_tag(snippet)
+ content_tag(:script, nil, src: reliable_snippet_url(snippet, format: :js, only_path: false))
+ end
+
+ def snippet_badge(snippet)
+ return unless attrs = snippet_badge_attributes(snippet)
+
+ css_class, text = attrs
+ tag.span(class: ['badge', 'badge-gray']) do
+ concat(tag.i(class: ['fa', css_class]))
+ concat(' ')
+ concat(text)
+ end
+ end
+
+ def snippet_badge_attributes(snippet)
+ if snippet.private?
+ ['fa-lock', _('private')]
+ end
end
- def embedded_snippet_raw_button
+ def embedded_raw_snippet_button
blob = @snippet.blob
return if blob.empty? || blob.binary? || blob.stored_externally?
- snippet_raw_url = if @snippet.is_a?(PersonalSnippet)
- raw_snippet_url(@snippet)
- else
- raw_project_snippet_url(@snippet.project, @snippet)
- end
-
- link_to external_snippet_icon('doc-code'), snippet_raw_url, class: 'btn', target: '_blank', rel: 'noopener noreferrer', title: 'Open raw'
+ link_to(external_snippet_icon('doc-code'),
+ reliable_raw_snippet_url(@snippet),
+ class: 'btn',
+ target: '_blank',
+ rel: 'noopener noreferrer',
+ title: 'Open raw')
end
def embedded_snippet_download_button
- download_url = if @snippet.is_a?(PersonalSnippet)
- raw_snippet_url(@snippet, inline: false)
- else
- raw_project_snippet_url(@snippet.project, @snippet, inline: false)
- end
-
- link_to external_snippet_icon('download'), download_url, class: 'btn', target: '_blank', title: 'Download', rel: 'noopener noreferrer'
+ link_to(external_snippet_icon('download'),
+ reliable_raw_snippet_url(@snippet, inline: false),
+ class: 'btn',
+ target: '_blank',
+ title: 'Download',
+ rel: 'noopener noreferrer')
end
end