Class: Mato::Document
- Inherits:
-
Object
- Object
- Mato::Document
- Defined in:
- lib/mato/document.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_html_filters(*html_filters) ⇒ Nokogiri::HTML4::DocumentFragment
A copy of fragment that are modified by html_filters.
- #css(selector) ⇒ Nokogiri::XML::NodeSet
-
#initialize(fragment) ⇒ Document
constructor
A new instance of Document.
- #marshal_dump ⇒ Object
- #marshal_load(data) ⇒ Object
- #render(renderer) ⇒ Object
- #render_html ⇒ Object
- #render_html_toc ⇒ Object
- #xpath(query) ⇒ Nokogiri::XML::NodeSet
Constructor Details
#initialize(fragment) ⇒ Document
Returns a new instance of Document.
17 18 19 |
# File 'lib/mato/document.rb', line 17 def initialize(fragment) @fragment = fragment end |
Instance Attribute Details
#fragment ⇒ Nokogiri::HTML4::DocumentFragment (readonly)
10 11 12 |
# File 'lib/mato/document.rb', line 10 def fragment @fragment end |
Class Method Details
.empty ⇒ Object
12 13 14 |
# File 'lib/mato/document.rb', line 12 def self.empty new(Nokogiri::HTML4.fragment('')) end |
Instance Method Details
#apply_html_filters(*html_filters) ⇒ Nokogiri::HTML4::DocumentFragment
Returns A copy of fragment that are modified by html_filters.
22 23 24 25 26 27 28 |
# 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) ⇒ Nokogiri::XML::NodeSet
32 33 34 |
# File 'lib/mato/document.rb', line 32 def css(selector) fragment.css(selector) end |
#marshal_dump ⇒ Object
54 55 56 57 58 |
# File 'lib/mato/document.rb', line 54 def marshal_dump { fragment: fragment.to_html(save_with: 0), } end |
#marshal_load(data) ⇒ Object
60 61 62 |
# File 'lib/mato/document.rb', line 60 def marshal_load(data) initialize(Nokogiri::HTML4.fragment(data[:fragment]).freeze) end |
#render(renderer) ⇒ Object
42 43 44 |
# File 'lib/mato/document.rb', line 42 def render(renderer) renderer.call(fragment) end |
#render_html ⇒ Object
46 47 48 |
# File 'lib/mato/document.rb', line 46 def render_html render(Mato::Renderers::HtmlRenderer.new) end |
#render_html_toc ⇒ Object
50 51 52 |
# File 'lib/mato/document.rb', line 50 def render_html_toc render(Mato::Renderers::HtmlTocRenderer.new) end |
#xpath(query) ⇒ Nokogiri::XML::NodeSet
38 39 40 |
# File 'lib/mato/document.rb', line 38 def xpath(query) fragment.xpath(query) end |