File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ def process_styles(element_styles: nil)
4545 attrs . merge_text_styles! ( tag_styles , options : options ) if respond_to? ( :tag_styles )
4646 attrs . merge_text_styles! ( element_styles , options : options ) if element_styles
4747 attrs . merge_text_styles! ( attrs . style , options : options )
48+ attrs . merge_text_styles! ( extra_styles , options : options ) if respond_to? ( :extra_styles )
4849 end
4950
5051 # Styles to apply on tag closing
Original file line number Diff line number Diff line change @@ -5,12 +5,13 @@ module Tags
55 class A < Tag
66 ELEMENTS = [ :a ] . freeze
77
8- def tag_styles
9- return unless attrs . href
8+ def extra_styles
9+ attrs . href ? "href: #{ attrs . href } " : nil
10+ end
1011
12+ def tag_styles
1113 <<~STYLES
1214 color: #00E;
13- href: #{ attrs . href } ;
1415 text-decoration: underline;
1516 STYLES
1617 end
Original file line number Diff line number Diff line change 4141 end
4242 end
4343
44+ describe '#process_styles' do
45+ subject ( :process_styles ) { tag . process_styles ( element_styles : element_styles ) }
46+
47+ let ( :element_styles ) { nil }
48+
49+ before do
50+ allow ( tag . attrs ) . to receive ( :merge_text_styles! )
51+ end
52+
53+ it 'merges the inline styles' do
54+ process_styles
55+ expect ( tag . attrs ) . to have_received ( :merge_text_styles! ) . with ( 'color: #0088ff' , options : { } )
56+ end
57+
58+ context 'with some additional styles' do
59+ let ( :some_tag_class ) do
60+ Class . new ( described_class ) do
61+ def extra_styles
62+ 'color: green; text-decoration: underline'
63+ end
64+
65+ def tag_styles
66+ 'color: yellow; font-style: italic'
67+ end
68+ end
69+ end
70+
71+ let ( :element_styles ) { 'color: red; font-weight: bold' }
72+ let ( :tag ) { some_tag_class . new ( :some_tag , attributes : attributes ) }
73+
74+ it 'merges the tag styles' , :aggregate_failures do
75+ process_styles
76+
77+ expected_styles = 'color: yellow; font-style: italic'
78+ expect ( tag . attrs ) . to have_received ( :merge_text_styles! ) . with ( expected_styles , options : { } ) . ordered
79+ expect ( tag . attrs ) . to have_received ( :merge_text_styles! ) . with ( element_styles , options : { } ) . ordered
80+ expect ( tag . attrs ) . to have_received ( :merge_text_styles! ) . with ( 'color: #0088ff' , options : { } ) . ordered
81+ expected_styles = 'color: green; text-decoration: underline'
82+ expect ( tag . attrs ) . to have_received ( :merge_text_styles! ) . with ( expected_styles , options : { } ) . ordered
83+ end
84+ end
85+ end
86+
4487 describe '#styles' do
4588 subject ( :styles ) { tag . styles }
4689
Original file line number Diff line number Diff line change 1111 end
1212
1313 it "styles doesn't include the link property" do
14- expect ( a . styles ) . to eq ( color : 'ffbb11' )
14+ expect ( a . styles ) . to eq ( color : 'ffbb11' , styles : [ :underline ] )
1515 end
1616 end
1717
You can’t perform that action at this time.
0 commit comments