Class: Sablon::HTMLConverter::ASTBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sablon/html/ast_builder.rb

Overview

Converts a nokogiri HTML fragment into an equivalent AST structure

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



5
6
7
# File 'lib/sablon/html/ast_builder.rb', line 5

def nodes
  @nodes
end

Class Method Details

.any_block_tags?(nodes) ⇒ Boolean

Checks if there are any block level tags in the current node set this is used at the root level to determine if top level text nodes should be removed

Returns:

  • (Boolean)


15
16
17
# File 'lib/sablon/html/ast_builder.rb', line 15

def self.any_block_tags?(nodes)
  nodes.detect { |node| fetch_tag(node.name).type == :block }
end

.fetch_tag(tag_name) ⇒ Object

Retrieves a HTMLTag instance from the permitted_html_tags hash or raises an ArgumentError if the tag is not registered



21
22
23
24
25
26
27
# File 'lib/sablon/html/ast_builder.rb', line 21

def self.fetch_tag(tag_name)
  tag_name = tag_name.to_sym
  unless Sablon::Configuration.instance.permitted_html_tags[tag_name]
    raise ArgumentError, "Don't know how to handle HTML tag: #{tag_name}"
  end
  Sablon::Configuration.instance.permitted_html_tags[tag_name]
end

.html_to_ast(env, nodes, properties) ⇒ Object



7
8
9
10
# File 'lib/sablon/html/ast_builder.rb', line 7

def self.html_to_ast(env, nodes, properties)
  builder = new(env, nodes, properties)
  builder.nodes
end