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(buffer, template_language: :html) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ Object
- #nodes_with_type(*type) ⇒ Object
- #parser_errors ⇒ Object
Constructor Details
#initialize(buffer, template_language: :html) ⇒ Parser
Returns a new instance of Parser.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/better_html/parser.rb', line 26 def initialize(buffer, template_language: :html) raise ArgumentError, "first argument must be Parser::Source::Buffer" unless buffer.is_a?(::Parser::Source::Buffer) @buffer = buffer @template_language = template_language @erb = case template_language when :html Tokenizer::HtmlErb.new(@buffer) when :lodash Tokenizer::HtmlLodash.new(@buffer) when :javascript Tokenizer::JavascriptErb.new(@buffer) 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.
14 15 16 |
# File 'lib/better_html/parser.rb', line 14 def template_language @template_language end |
Instance Method Details
#ast ⇒ Object
48 49 50 |
# File 'lib/better_html/parser.rb', line 48 def ast @ast ||= build_document_node end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/better_html/parser.rb', line 61 def inspect "#<#{self.class.name} ast=#{ast.inspect}>" end |
#nodes_with_type(*type) ⇒ Object
43 44 45 46 |
# File 'lib/better_html/parser.rb', line 43 def nodes_with_type(*type) types = Array.wrap(type) ast.children.select { |node| node.is_a?(::AST::Node) && types.include?(node.type) } end |