Class: Sablon::HTMLConverter::Root

Inherits:
Collection show all
Defined in:
lib/sablon/html/ast.rb

Overview

Stores all of the AST nodes from the current fragment of HTML being parsed

Constant Summary

Constants inherited from Node

Node::PROPERTIES

Instance Attribute Summary

Attributes inherited from Collection

#nodes

Instance Method Summary collapse

Methods inherited from Collection

#<<, #accept, #to_docx

Methods inherited from Node

#accept, convert_style_property, node_name, process_properties, style_conversion, #to_docx

Constructor Details

#initialize(env, node) ⇒ Root

Returns a new instance of Root.



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sablon/html/ast.rb', line 131

def initialize(env, node)
  # strip text nodes from the root level element, these are typically
  # extra whitespace from indenting the markup if there are any
  # block level tags at the top level
  if ASTBuilder.any_block_tags?(node.children)
    node.search('./text()').remove
  end

  # convert children from HTML to AST nodes
  super(ASTBuilder.html_to_ast(env, node.children, {}))
end

Instance Method Details

#grep(pattern) ⇒ Object



143
144
145
146
147
# File 'lib/sablon/html/ast.rb', line 143

def grep(pattern)
  visitor = GrepVisitor.new(pattern)
  accept(visitor)
  visitor.result
end

#inspectObject



149
150
151
# File 'lib/sablon/html/ast.rb', line 149

def inspect
  "<Root: #{super}>"
end