Improve cross project label look and feel

This commit is contained in:
Grzegorz Bizon 2016-02-26 10:52:00 +01:00
parent 7183a7da6d
commit 62dcdef969
2 changed files with 14 additions and 7 deletions

View file

@ -50,22 +50,23 @@ module LabelsHelper
@project.labels.pluck(:title)
end
def render_colored_label(label, label_prefix = '')
def render_colored_label(label, label_suffix = '')
label_color = label.color || Label::DEFAULT_COLOR
text_color = text_color_for_bg(label_color)
# Intentionally not using content_tag here so that this method can be called
# by LabelReferenceFilter
span = %(<span class="label color-label") +
%( style="background-color: #{label_color}; color: #{text_color}">) +
label_prefix + escape_once(label.name) + '</span>'
%(style="background-color: #{label_color}; color: #{text_color}">) +
%(#{escape_once(label.name)}#{label_suffix}</span>)
span.html_safe
end
def render_colored_cross_project_label(label)
label_prefix = "#{label.project.path_with_namespace} &raquo; "
render_colored_label(label, label_prefix)
label_suffix = label.project.name
label_suffix = " <i>&laquo; #{label_suffix}</i>"
render_colored_label(label, label_suffix)
end
def suggested_colors

View file

@ -178,7 +178,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
describe 'cross project label references' do
let(:another_project) { create(:empty_project, :public) }
let(:project_name) { 'Some project' }
let(:another_project) { create(:empty_project, :public, name: project_name) }
let(:label) { create(:label, project: another_project, color: '#00ff00') }
let(:reference) { label.to_reference(project) }
@ -192,7 +193,12 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
it 'has valid color' do
expect(result.css('a span').first.attr('style')).to match /background-color: #00ff00/
expect(result.css('a span').first.attr('style'))
.to match /background-color: #00ff00/
end
it 'contains cross project content' do
expect(result.css('a').first.text).to eq "#{label.name} « #{project_name}"
end
end
end