Class: RubyUIConverter::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ui_converter/parser.rb

Overview

Builds a unified HTML + ERB tree from a source template.

The tricky part is that HTML nesting (tags) and Ruby nesting (if/each/do … end) interleave. We track both on a single stack and pop tolerantly so that well-formed templates produce a correct tree and slightly malformed ones degrade gracefully instead of raising.

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



11
12
13
# File 'lib/ruby_ui_converter/parser.rb', line 11

def initialize(source)
  @html, @registry = Lexer.new(source).tokenize_with_placeholders
end

Instance Method Details

#parseObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_ui_converter/parser.rb', line 15

def parse
  root = Nodes::Document.new
  stack = [root]

  HtmlTokenizer.new(@html).tokens.each do |token|
    dispatch(token, stack)
  end

  root
end