Class: Hexp::Node::Domize

Inherits:
Object
  • Object
show all
Defined in:
lib/hexp/node/domize.rb

Overview

Turn nodes into DOM objects

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :include_doctype => true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hexp, options = {}) ⇒ Domize

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instanitiate a Domizer

Parameters:

  • hexp (Hexp::Node)
  • options (Hash) (defaults to: {})


24
25
26
27
28
# File 'lib/hexp/node/domize.rb', line 24

def initialize(hexp, options = {})
  @dom     = Hexp::DOM
  @raw     = hexp
  @options = DEFAULT_OPTIONS.merge(options).freeze
end

Instance Attribute Details

#domNokogiri::HTML::Document (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The resulting DOM Document

Returns:

  • (Nokogiri::HTML::Document)


14
15
16
# File 'lib/hexp/node/domize.rb', line 14

def dom
  @dom
end

Instance Method Details

#callNokogiri::HTML::Document

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Turn the hexp into a DOM

Returns:

  • (Nokogiri::HTML::Document)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hexp/node/domize.rb', line 35

def call
  @doc  = dom::Document.new
  if @options[:html5]
    @doc.children = dom::NodeSet.new(@doc, [])
    @doc.create_internal_subset(nil, nil, nil)
  end
  @root = domize(@raw)
  @doc << @root

  if @options[:include_doctype]
    @doc
  else
    @root
  end
end