Class: PrawnHtml::Tag
- Inherits:
-
Object
- Object
- PrawnHtml::Tag
- Extended by:
- Forwardable
- Defined in:
- lib/prawn_html/tag.rb
Direct Known Subclasses
PrawnHtml::Tags::A, PrawnHtml::Tags::B, PrawnHtml::Tags::Blockquote, PrawnHtml::Tags::Body, PrawnHtml::Tags::Br, PrawnHtml::Tags::Code, PrawnHtml::Tags::Del, PrawnHtml::Tags::Div, PrawnHtml::Tags::H, PrawnHtml::Tags::Hr, PrawnHtml::Tags::I, PrawnHtml::Tags::Img, PrawnHtml::Tags::Li, PrawnHtml::Tags::Mark, PrawnHtml::Tags::Ol, PrawnHtml::Tags::P, PrawnHtml::Tags::Pre, PrawnHtml::Tags::Small, PrawnHtml::Tags::Span, PrawnHtml::Tags::Sub, PrawnHtml::Tags::Sup, PrawnHtml::Tags::U, PrawnHtml::Tags::Ul
Constant Summary collapse
- CALLBACKS =
{ 'Background' => Callbacks::Background, 'StrikeThrough' => Callbacks::StrikeThrough }.freeze
- TAG_CLASSES =
%w[A B Blockquote Body Br Code Del Div H Hr I Img Li Mark Ol P Pre Small Span Sub Sup U Ul].freeze
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Class Method Summary collapse
-
.class_for(tag_name) ⇒ Tag
Evaluate the Tag class from a tag name.
Instance Method Summary collapse
-
#block? ⇒ Boolean
Is a block tag?.
-
#block_styles ⇒ Hash
Styles to apply to the block.
-
#initialize(tag, attributes: {}, options: {}) ⇒ Tag
constructor
Init the Tag.
-
#process_styles(element_styles: nil) ⇒ Object
Process tag styles.
-
#tag_close_styles ⇒ Hash
Styles to apply on tag closing.
-
#tag_open_styles ⇒ Hash
Styles to apply on tag opening.
Constructor Details
#initialize(tag, attributes: {}, options: {}) ⇒ Tag
Init the Tag
24 25 26 27 28 |
# File 'lib/prawn_html/tag.rb', line 24 def initialize(tag, attributes: {}, options: {}) @tag = tag @options = @attrs = Attributes.new(attributes) end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
17 18 19 |
# File 'lib/prawn_html/tag.rb', line 17 def attrs @attrs end |
#parent ⇒ Object
Returns the value of attribute parent.
16 17 18 |
# File 'lib/prawn_html/tag.rb', line 16 def parent @parent end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
17 18 19 |
# File 'lib/prawn_html/tag.rb', line 17 def tag @tag end |
Class Method Details
.class_for(tag_name) ⇒ Tag
Evaluate the Tag class from a tag name
76 77 78 79 80 81 82 83 |
# File 'lib/prawn_html/tag.rb', line 76 def class_for(tag_name) @tag_classes ||= TAG_CLASSES.each_with_object({}) do |tag_class, res| klass = const_get("PrawnHtml::Tags::#{tag_class}") k = [klass] * klass::ELEMENTS.size res.merge!(klass::ELEMENTS.zip(k).to_h) end @tag_classes[tag_name] end |
Instance Method Details
#block? ⇒ Boolean
Is a block tag?
33 34 35 |
# File 'lib/prawn_html/tag.rb', line 33 def block? false end |
#block_styles ⇒ Hash
Styles to apply to the block
40 41 42 43 44 |
# File 'lib/prawn_html/tag.rb', line 40 def block_styles block_styles = styles.slice(*Attributes::STYLES_APPLY[:block]) block_styles[:mode] = attrs.data['mode'].to_sym if attrs.data.include?('mode') block_styles end |
#process_styles(element_styles: nil) ⇒ Object
Process tag styles
49 50 51 52 53 54 |
# File 'lib/prawn_html/tag.rb', line 49 def process_styles(element_styles: nil) attrs.merge_text_styles!(tag_styles, options: ) if respond_to?(:tag_styles) attrs.merge_text_styles!(element_styles, options: ) if element_styles attrs.merge_text_styles!(attrs.style, options: ) attrs.merge_text_styles!(extra_styles, options: ) if respond_to?(:extra_styles) end |
#tag_close_styles ⇒ Hash
Styles to apply on tag closing
59 60 61 |
# File 'lib/prawn_html/tag.rb', line 59 def tag_close_styles styles.slice(*Attributes::STYLES_APPLY[:tag_close]) end |
#tag_open_styles ⇒ Hash
Styles to apply on tag opening
66 67 68 |
# File 'lib/prawn_html/tag.rb', line 66 def tag_open_styles styles.slice(*Attributes::STYLES_APPLY[:tag_open]) end |