class PrawnHtml::Context

def add(element)

Returns:
  • (Context) - the context updated

Parameters:
  • element (Tag) -- the element to add
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

def before_content

Returns:
  • (String) - before content string
def before_content
  (last.respond_to?(:before_content) && last.before_content) || ''
end

def block_styles

Returns:
  • (Hash) - the hash of merged styles
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

def evaluate_element_styles(element, res)

def evaluate_element_styles(element, res)
  styles = element.styles.slice(*Attributes::STYLES_APPLY[:text_node])
  styles.each do |key, val|
    if res.include?(key) && res[key].is_a?(Array)
      res[key] += val
    else
      res[key] = val
    end
  end
end

def initialize(*_args)

Init the Context
def initialize(*_args)
  super
  @last_text_node = false
  @merged_styles = nil
  @previous_tag = nil
end

def inspect

:nocov:
def inspect
  map(&:class).map(&:to_s).join(', ')
end

def merged_styles

Returns:
  • (Hash) - the hash of merged styles
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

def remove_last

Remove the last element from the context
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

def white_space_pre?

Returns:
  • (boolean) - white space property of the last element is equal to 'pre'
def white_space_pre?
  last && last.styles[:white_space] == :pre
end