class Mato::Document

Attributes

fragment[R]

@return [Nokogiri::HTML4::DocumentFragment]

Public Class Methods

empty() click to toggle source
# File lib/mato/document.rb, line 12
def self.empty
  new(Nokogiri::HTML4.fragment(''))
end
new(fragment) click to toggle source

@param [Nokogiri::HTML4::DocumentFragment] fragment

# File lib/mato/document.rb, line 17
def initialize(fragment)
  @fragment = fragment
end

Public Instance Methods

apply_html_filters(*html_filters) click to toggle source

@return [Nokogiri::HTML4::DocumentFragment] A copy of fragment that are modified by html_filters

# File lib/mato/document.rb, line 22
def apply_html_filters(*html_filters)
  new_fragment = fragment.dup
  html_filters.each do |html_filter|
    html_filter.call(new_fragment)
  end
  self.class.new(new_fragment.freeze)
end
css(selector) click to toggle source

@param [String] selector @return [Nokogiri::XML::NodeSet]

# File lib/mato/document.rb, line 32
def css(selector)
  fragment.css(selector)
end
marshal_dump() click to toggle source
# File lib/mato/document.rb, line 54
def marshal_dump
  {
    fragment: fragment.to_html(save_with: 0),
  }
end
marshal_load(data) click to toggle source
# File lib/mato/document.rb, line 60
def marshal_load(data)
  initialize(Nokogiri::HTML4.fragment(data[:fragment]).freeze)
end
render(renderer) click to toggle source
# File lib/mato/document.rb, line 42
def render(renderer)
  renderer.call(fragment)
end
render_html() click to toggle source
# File lib/mato/document.rb, line 46
def render_html
  render(Mato::Renderers::HtmlRenderer.new)
end
render_html_toc() click to toggle source
# File lib/mato/document.rb, line 50
def render_html_toc
  render(Mato::Renderers::HtmlTocRenderer.new)
end
xpath(query) click to toggle source

@param [String] query @return [Nokogiri::XML::NodeSet]

# File lib/mato/document.rb, line 38
def xpath(query)
  fragment.xpath(query)
end