diff options
author | http://jneen.net/ <jneen@jneen.net> | 2016-06-22 12:53:58 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2016-06-27 14:17:49 -0700 |
commit | 66b37149eb72179e1b6329221b8a92e226e4e563 (patch) | |
tree | 1f1b9e12320bf54301964f0bc8f11b2970a9ea47 | |
parent | e7b512efa65aebe26cd0240a4d077475c42761c1 (diff) | |
download | gitlab-ce-66b37149eb72179e1b6329221b8a92e226e4e563.tar.gz |
support cgi style options, such as erb?parent=json
-rw-r--r-- | lib/gitlab/highlight.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/highlight_spec.rb | 17 | ||||
-rw-r--r-- | spec/support/test_env.rb | 2 |
3 files changed, 18 insertions, 7 deletions
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 7f8cfe706de..41296415e35 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -40,11 +40,11 @@ module Gitlab private def custom_language - return nil if @repository.nil? + language_name = @repository && @repository.gitattribute(@blob_name, 'gitlab-language') - language_name = @repository.gitattribute(@blob_name, 'gitlab-language') + return nil unless language_name - Rouge::Lexer.find(language_name) + Rouge::Lexer.find_fancy(language_name) end def rouge_formatter(options = {}) diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index c84911e8f0b..364532e94e3 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -21,7 +21,6 @@ describe Gitlab::Highlight, lib: true do describe 'custom highlighting from .gitattributes' do let(:branch) { 'gitattributes' } - let(:path) { 'custom-highlighting/test.gitlab-custom' } let(:blob) { repository.blob_at_branch(branch, path) } let(:highlighter) do @@ -30,8 +29,20 @@ describe Gitlab::Highlight, lib: true do before { project.change_head('gitattributes') } - it 'highlights as ruby' do - expect(highlighter.lexer.tag).to eq 'ruby' + describe 'basic language selection' do + let(:path) { 'custom-highlighting/test.gitlab-custom' } + it 'highlights as ruby' do + expect(highlighter.lexer.tag).to eq 'ruby' + end + end + + describe 'cgi options' do + let(:path) { 'custom-highlighting/test.gitlab-cgi' } + + it 'highlights as json with erb' do + expect(highlighter.lexer.tag).to eq 'erb' + expect(highlighter.lexer.parent.tag).to eq 'json' + end end end end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 8246be357a5..426bf53f198 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -17,7 +17,7 @@ module TestEnv "'test'" => 'e56497b', 'orphaned-branch' => '45127a9', 'binary-encoding' => '7b1cf43', - 'gitattributes' => '281d3a76' + 'gitattributes' => '5a62481', } # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily |