Class: PrawnHtml::Context
- Inherits:
-
Array
- Object
- Array
- PrawnHtml::Context
- Defined in:
- lib/prawn_html/context.rb
Constant Summary collapse
- DEFAULT_STYLES =
{ size: 16 * PX }.freeze
Instance Attribute Summary collapse
-
#last_text_node ⇒ Object
Returns the value of attribute last_text_node.
-
#previous_tag ⇒ Object
readonly
Returns the value of attribute previous_tag.
Instance Method Summary collapse
-
#add(element) ⇒ Context
Add an element to the context.
-
#before_content ⇒ String
Evaluate before content.
-
#block_styles ⇒ Hash
Merges the context block styles.
-
#initialize(*_args) ⇒ Context
constructor
Init the Context.
-
#inspect ⇒ Object
:nocov:.
-
#merged_styles ⇒ Hash
Merge the context styles for text nodes.
-
#remove_last ⇒ Object
Remove the last element from the context.
-
#white_space_pre? ⇒ boolean
White space is equal to ‘pre’?.
Constructor Details
#initialize(*_args) ⇒ Context
Init the Context
13 14 15 16 17 18 |
# File 'lib/prawn_html/context.rb', line 13 def initialize(*_args) super @last_text_node = false @merged_styles = nil @previous_tag = nil end |
Instance Attribute Details
#last_text_node ⇒ Object
Returns the value of attribute last_text_node.
10 11 12 |
# File 'lib/prawn_html/context.rb', line 10 def last_text_node @last_text_node end |
#previous_tag ⇒ Object (readonly)
Returns the value of attribute previous_tag.
9 10 11 |
# File 'lib/prawn_html/context.rb', line 9 def previous_tag @previous_tag end |
Instance Method Details
#add(element) ⇒ Context
Add an element to the context
Set the parent for the previous element in the chain. Run ‘on_context_add` callback method on the added element.
28 29 30 31 32 33 34 |
# File 'lib/prawn_html/context.rb', line 28 def add(element) element.parent = last push(element) element.on_context_add(self) if element.respond_to?(:on_context_add) @merged_styles = nil self end |
#before_content ⇒ String
Evaluate before content
39 40 41 |
# File 'lib/prawn_html/context.rb', line 39 def before_content (last.respond_to?(:before_content) && last.before_content) || '' end |
#block_styles ⇒ Hash
Merges the context block styles
46 47 48 49 50 51 52 |
# File 'lib/prawn_html/context.rb', line 46 def block_styles each_with_object({}) do |element, res| element.block_styles.each do |key, value| Attributes.merge_attr!(res, key, value) end end end |
#inspect ⇒ Object
:nocov:
66 67 68 |
# File 'lib/prawn_html/context.rb', line 66 def inspect map(&:class).map(&:to_s).join(', ') end |
#merged_styles ⇒ Hash
Merge the context styles for text nodes
57 58 59 60 61 62 63 |
# File 'lib/prawn_html/context.rb', line 57 def merged_styles @merged_styles ||= each_with_object(DEFAULT_STYLES.dup) do |element, res| evaluate_element_styles(element, res) element.update_styles(res) end end |
#remove_last ⇒ Object
Remove the last element from the context
72 73 74 75 76 77 78 |
# File 'lib/prawn_html/context.rb', line 72 def remove_last last.on_context_remove(self) if last.respond_to?(:on_context_remove) @merged_styles = nil @last_text_node = false @previous_tag = last pop end |
#white_space_pre? ⇒ boolean
White space is equal to ‘pre’?
83 84 85 |
# File 'lib/prawn_html/context.rb', line 83 def white_space_pre? last && last.styles[:white_space] == :pre end |