Class: Sablon::HTMLConverter::ASTBuilder
- Inherits:
-
Object
- Object
- Sablon::HTMLConverter::ASTBuilder
- Defined in:
- lib/sablon/html/ast_builder.rb
Overview
Converts a nokogiri HTML fragment into an equivalent AST structure
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Class Method Summary collapse
-
.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.
-
.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.
- .html_to_ast(env, nodes, properties) ⇒ Object
Instance Attribute Details
#nodes ⇒ Object (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
15 16 17 |
# File 'lib/sablon/html/ast_builder.rb', line 15 def self.(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.[tag_name] raise ArgumentError, "Don't know how to handle HTML tag: #{tag_name}" end Sablon::Configuration.instance.[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 |