From b8fcaa7f4126ce2b5fe0436197b2aacc1be84e96 Mon Sep 17 00:00:00 2001 From: Zertrin Date: Tue, 21 Oct 2014 09:59:03 +0200 Subject: revert using the extension of the blob to determine the syntax highlighting language nohighlight functionality for a hardcoded set of filenames is kept --- app/helpers/blob_helper.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'app/helpers/blob_helper.rb') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 11fbf1baae7..420ac3f77c7 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,14 +1,9 @@ module BlobHelper def highlightjs_class(blob_name) - if blob_name.include?('.') - ext = blob_name.split('.').last - return 'language-' + ext + if no_highlight_files.include?(blob_name.downcase) + 'no-highlight' else - if no_highlight_files.include?(blob_name.downcase) - 'no-highlight' - else - blob_name.downcase - end + blob_name.downcase end end -- cgit v1.2.1 From 80497793355f8b8c735f40dd25c20c2ac989b6e1 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Wed, 3 Dec 2014 12:50:00 +0100 Subject: Added "news" to no_highlight_files --- app/helpers/blob_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/helpers/blob_helper.rb') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 420ac3f77c7..b7c1db6964c 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -8,6 +8,6 @@ module BlobHelper end def no_highlight_files - %w(credits changelog copying copyright license authors) + %w(credits changelog news copying copyright license authors) end end -- cgit v1.2.1 From bf079c24afb8ad2991a4eaf60a71a7bc45dd775d Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Wed, 3 Dec 2014 15:27:31 +0100 Subject: Replace highlight.js with rouge-fork rugments I decided to create a fork of rouge as rouge lacks a HTML formatter with the required options such as wrapping a line with tags. Furthermore I was not really convinced about the clarity of rouge's source code. Rugments 1.0.0beta3 for now only includes some basic linting and a new HTML formatter. Everything else should behave the same. --- app/helpers/blob_helper.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'app/helpers/blob_helper.rb') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 420ac3f77c7..3a282803963 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,10 +1,19 @@ module BlobHelper - def highlightjs_class(blob_name) - if no_highlight_files.include?(blob_name.downcase) - 'no-highlight' - else - blob_name.downcase + def highlight(blob_name, blob_content, nowrap = false) + formatter = Rugments::Formatters::HTML.new( + nowrap: nowrap, + cssclass: 'code highlight', + lineanchors: true, + lineanchorsid: 'LC' + ) + + begin + lexer = Rugments::Lexer.guess(filename: blob_name, source: blob_content) + rescue Rugments::Lexer::AmbiguousGuess + lexer = Rugments::Lexers::PlainText end + + formatter.format(lexer.lex(blob_content)).html_safe end def no_highlight_files -- cgit v1.2.1 From 21297e78afd5ddfbfdf62f471acf1ab2f0c2a892 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 26 Jan 2015 15:03:14 -0800 Subject: Refactor blob helpers --- app/helpers/blob_helper.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'app/helpers/blob_helper.rb') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 3a282803963..e75eebd2da9 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -19,4 +19,42 @@ module BlobHelper def no_highlight_files %w(credits changelog copying copyright license authors) end + + def edit_blob_link(project, ref, path, options = {}) + blob = + begin + project.repository.blob_at(ref, path) + rescue + nil + end + + if blob && blob.text? + text = 'Edit' + after = options[:after] || '' + from_mr = options[:from_merge_request_id] + link_opts = {} + link_opts[:from_merge_request_id] = from_mr if from_mr + cls = 'btn btn-small' + if allowed_tree_edit?(project, ref) + link_to text, project_edit_blob_path(project, tree_join(ref, path), + link_opts), class: cls + else + content_tag :span, text, class: cls + ' disabled' + end + after.html_safe + else + '' + end + end + + def leave_edit_message + "Leave edit mode?\nAll unsaved changes will be lost." + end + + def editing_preview_title(filename) + if Gitlab::MarkdownHelper.previewable?(filename) + 'Preview' + else + 'Preview changes' + end + end end -- cgit v1.2.1 From 76aad9b76ed756ca9ba2cbcdb399c815e542b3ae Mon Sep 17 00:00:00 2001 From: Vinnie Okada Date: Sat, 24 Jan 2015 11:02:58 -0700 Subject: Upgrade to Rails 4.1.9 Make the following changes to deal with new behavior in Rails 4.1.2: * Use nested resources to avoid slashes in arguments to path helpers. --- app/helpers/blob_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/helpers/blob_helper.rb') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index e75eebd2da9..f5f27223d5b 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -36,8 +36,12 @@ module BlobHelper link_opts[:from_merge_request_id] = from_mr if from_mr cls = 'btn btn-small' if allowed_tree_edit?(project, ref) - link_to text, project_edit_blob_path(project, tree_join(ref, path), - link_opts), class: cls + link_to(text, + namespace_project_edit_blob_path(project.namespace, project, + tree_join(ref, path), + link_opts), + class: cls + ) else content_tag :span, text, class: cls + ' disabled' end + after.html_safe -- cgit v1.2.1