diff options
author | haseeb <haseebeqx@yahoo.com> | 2018-02-06 19:03:18 +0530 |
---|---|---|
committer | haseeb <haseebeqx@yahoo.com> | 2018-02-28 18:48:26 +0530 |
commit | 27e8d38cea92d165a2e8400b25df23f408b4dca0 (patch) | |
tree | 0a16f63c8f380c92fb4185ca21ba8a264c572641 /app/helpers/snippets_helper.rb | |
parent | 56af0631c6c6d838301ac068f2e79b8f4de9fda7 (diff) | |
download | gitlab-ce-27e8d38cea92d165a2e8400b25df23f408b4dca0.tar.gz |
embedded snippets support
Diffstat (limited to 'app/helpers/snippets_helper.rb')
-rw-r--r-- | app/helpers/snippets_helper.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb index 00e7e4230b9..830db46d67f 100644 --- a/app/helpers/snippets_helper.rb +++ b/app/helpers/snippets_helper.rb @@ -101,4 +101,39 @@ module SnippetsHelper # Return snippet with chunk array { snippet_object: snippet, snippet_chunks: snippet_chunks } end + + def snippet_embed + "<script src=\"#{url_for(only_path: false, overwrite_params: nil)}.js\"></script>" + end + + def embedded_snippet_raw_button + blob = @snippet.blob + return if blob.empty? || blob.raw_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', data: { container: 'body' } + 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', data: { container: 'body' }, rel: 'noopener noreferrer' + end + + def public_snippet? + if @snippet.project_id? + can?(nil, :read_project_snippet, @snippet) + else + can?(nil, :read_personal_snippet, @snippet) + end + end end |