Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/prawn_html/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def process_styles(element_styles: nil)
attrs.merge_text_styles!(tag_styles, options: options) if respond_to?(:tag_styles)
attrs.merge_text_styles!(element_styles, options: options) if element_styles
attrs.merge_text_styles!(attrs.style, options: options)
attrs.merge_text_styles!(extra_styles, options: options) if respond_to?(:extra_styles)
end

# Styles to apply on tag closing
Expand Down
7 changes: 4 additions & 3 deletions lib/prawn_html/tags/a.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ module Tags
class A < Tag
ELEMENTS = [:a].freeze

def tag_styles
return unless attrs.href
def extra_styles
attrs.href ? "href: #{attrs.href}" : nil
end

def tag_styles
<<~STYLES
color: #00E;
href: #{attrs.href};
text-decoration: underline;
STYLES
end
Expand Down
43 changes: 43 additions & 0 deletions spec/units/prawn_html/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,49 @@
end
end

describe '#process_styles' do
subject(:process_styles) { tag.process_styles(element_styles: element_styles) }

let(:element_styles) { nil }

before do
allow(tag.attrs).to receive(:merge_text_styles!)
end

it 'merges the inline styles' do
process_styles
expect(tag.attrs).to have_received(:merge_text_styles!).with('color: #0088ff', options: {})
end

context 'with some additional styles' do
let(:some_tag_class) do
Class.new(described_class) do
def extra_styles
'color: green; text-decoration: underline'
end

def tag_styles
'color: yellow; font-style: italic'
end
end
end

let(:element_styles) { 'color: red; font-weight: bold' }
let(:tag) { some_tag_class.new(:some_tag, attributes: attributes) }

it 'merges the tag styles', :aggregate_failures do
process_styles

expected_styles = 'color: yellow; font-style: italic'
expect(tag.attrs).to have_received(:merge_text_styles!).with(expected_styles, options: {}).ordered
expect(tag.attrs).to have_received(:merge_text_styles!).with(element_styles, options: {}).ordered
expect(tag.attrs).to have_received(:merge_text_styles!).with('color: #0088ff', options: {}).ordered
expected_styles = 'color: green; text-decoration: underline'
expect(tag.attrs).to have_received(:merge_text_styles!).with(expected_styles, options: {}).ordered
end
end
end

describe '#styles' do
subject(:styles) { tag.styles }

Expand Down
2 changes: 1 addition & 1 deletion spec/units/prawn_html/tags/a_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it "styles doesn't include the link property" do
expect(a.styles).to eq(color: 'ffbb11')
expect(a.styles).to eq(color: 'ffbb11', styles: [:underline])
end
end

Expand Down