Class: Hexp::Node::Domize

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

Overview

Turn nodes into DOM objects

Constant Summary

DEFAULT_OPTIONS =
{
  :include_doctype => true
}.freeze

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Domize) initialize(hexp, options = {})

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: {})

    :include_doctype defaults to true



22
23
24
25
26
# File 'lib/hexp/node/domize.rb', line 22

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

Instance Attribute Details

- (Nokogiri::HTML::Document) dom (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

- (Nokogiri::HTML::Document) call

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)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hexp/node/domize.rb', line 33

def call
  @doc  = dom::Document.new
  @root = domize(@raw)
  @doc << @root

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