From 66b37149eb72179e1b6329221b8a92e226e4e563 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 22 Jun 2016 12:53:58 -0700 Subject: [PATCH] support cgi style options, such as erb?parent=json --- lib/gitlab/highlight.rb | 6 +++--- spec/lib/gitlab/highlight_spec.rb | 17 ++++++++++++++--- 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