From 950515ebe41002c1165aa450a2702de873c37ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 18 Jul 2018 12:55:49 +0200 Subject: [PATCH] Fix highlight class being used in rouge highlighting --- app/assets/stylesheets/content/_index.sass | 1 + app/assets/stylesheets/content/_search.sass | 8 ++++++++ app/assets/stylesheets/openproject/_legacy.sass | 9 --------- app/helpers/search_helper.rb | 2 +- spec/helpers/search_helper_spec.rb | 12 ++++++------ 5 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 app/assets/stylesheets/content/_search.sass diff --git a/app/assets/stylesheets/content/_index.sass b/app/assets/stylesheets/content/_index.sass index 0caf59ea98..52ce82f63c 100644 --- a/app/assets/stylesheets/content/_index.sass +++ b/app/assets/stylesheets/content/_index.sass @@ -66,6 +66,7 @@ @import content/hide_section @import content/hide_until_initialized @import content/hidden +@import content/search @import content/menus/_project_autocompletion @import content/editor/index diff --git a/app/assets/stylesheets/content/_search.sass b/app/assets/stylesheets/content/_search.sass new file mode 100644 index 0000000000..7e001e2588 --- /dev/null +++ b/app/assets/stylesheets/content/_search.sass @@ -0,0 +1,8 @@ +span.search-highlight + background-color: #FCFD8D + &.token-1 + background-color: #faa + &.token-2 + background-color: #afa + &.token-3 + background-color: #aaf diff --git a/app/assets/stylesheets/openproject/_legacy.sass b/app/assets/stylesheets/openproject/_legacy.sass index 8cae829f3f..7396d03249 100644 --- a/app/assets/stylesheets/openproject/_legacy.sass +++ b/app/assets/stylesheets/openproject/_legacy.sass @@ -45,15 +45,6 @@ $version-summary-width: 380px &:hover opacity: 1 -span.highlight - background-color: #FCFD8D - &.token-1 - background-color: #faa - &.token-2 - background-color: #afa - &.token-3 - background-color: #aaf - .contextual float: right white-space: nowrap diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 2caef572dd..c3b1856819 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -43,7 +43,7 @@ module SearchHelper result << h(words.length > 100 ? "#{words.slice(0..44)} ... #{words.slice(-45..-1)}" : words) else t = (tokens.index(words.downcase) || 0) % 4 - result << content_tag('span', h(words), class: "highlight token-#{t}") + result << content_tag('span', h(words), class: "search-highlight token-#{t}") end end result.html_safe diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index ecfbaaa669..1f63bdb1dd 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -59,7 +59,7 @@ describe 'search/index', type: :helper do context 'with single token' do let(:tokens) { %w(token) } let(:title) { 'This is a token.' } - let(:expected_title) { 'This is a token.' } + let(:expected_title) { 'This is a token.' } it { is_expected.to eq expected_title } end @@ -67,7 +67,7 @@ describe 'search/index', type: :helper do context 'with multiple tokens' do let(:tokens) { %w(token another) } let(:title) { 'This is a token and another token.' } - let(:expected_title) { 'This is a token and another token.' } + let(:expected_title) { 'This is a token and another token.' } it { is_expected.to eq expected_title } end @@ -75,7 +75,7 @@ describe 'search/index', type: :helper do context 'with huge content' do let(:tokens) { %w(token) } let(:title) { (('1234567890' * 100) + ' token ') * 100 } - let(:highlighted_token) { 'token' } + let(:highlighted_token) { 'token' } it { expect(highlighted_title).to include highlighted_token } @@ -87,7 +87,7 @@ describe 'search/index', type: :helper do context 'with multibyte title' do let(:tokens) { %w(token) } let(:title) { ('й' * 200) + ' token ' + ('й' * 200) } - let(:expected_title) { ('й' * 45) + ' ... ' + ('й' * 44) + ' token ' + ('й' * 44) + ' ... ' + ('й' * 45) } + let(:expected_title) { ('й' * 45) + ' ... ' + ('й' * 44) + ' token ' + ('й' * 44) + ' ... ' + ('й' * 45) } it { is_expected.to eq expected_title } end @@ -102,7 +102,7 @@ describe 'search/index', type: :helper do let(:first) { 'This is a token' } let(:second) { 'I have some token for you' } let(:titles) { [first, second] } - let(:first_highlighted) { 'This is a token' } + let(:first_highlighted) { 'This is a token' } it { is_expected.to eq first_highlighted } end @@ -111,7 +111,7 @@ describe 'search/index', type: :helper do let(:first) { 'This is a book' } let(:second) { 'I have some token for you' } let(:titles) { [first, second] } - let(:second_highlighted) { 'I have some token for you' } + let(:second_highlighted) { 'I have some token for you' } it { is_expected.to eq second_highlighted } end