Class: BetterHtml::Parser
- Inherits:
-
Object
- Object
- BetterHtml::Parser
- Defined in:
- lib/better_html/parser.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#template_language ⇒ Object
readonly
Returns the value of attribute template_language.
Instance Method Summary collapse
- #ast ⇒ Object
-
#initialize(document, template_language: :html) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ Object
- #nodes_with_type(*type) ⇒ Object
- #parser_errors ⇒ Object
Constructor Details
#initialize(document, template_language: :html) ⇒ Parser
Returns a new instance of Parser.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/better_html/parser.rb', line 22 def initialize(document, template_language: :html) @document = document @template_language = template_language @erb = case template_language when :html Tokenizer::HtmlErb.new(@document) when :lodash Tokenizer::HtmlLodash.new(@document) when :javascript Tokenizer::JavascriptErb.new(@document) else raise ArgumentError, "template_language can be :html or :javascript" end end |
Instance Attribute Details
#template_language ⇒ Object (readonly)
Returns the value of attribute template_language.
10 11 12 |
# File 'lib/better_html/parser.rb', line 10 def template_language @template_language end |
Instance Method Details
#ast ⇒ Object
42 43 44 |
# File 'lib/better_html/parser.rb', line 42 def ast @ast ||= build_document_node end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/better_html/parser.rb', line 55 def inspect "#<#{self.class.name} ast=#{ast.inspect}>" end |
#nodes_with_type(*type) ⇒ Object
37 38 39 40 |
# File 'lib/better_html/parser.rb', line 37 def nodes_with_type(*type) types = Array.wrap(type) ast.children.select{ |node| node.is_a?(::AST::Node) && types.include?(node.type) } end |