Class: FastHaml::ElementParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_haml/element_parser.rb

Constant Summary collapse

ELEMENT_REGEXP =
/\A%([-:\w]+)([-:\w.#]*)(.+)?\z/o

Instance Method Summary collapse

Constructor Details

#initialize(line_parser) ⇒ ElementParser

Returns a new instance of ElementParser.



10
11
12
# File 'lib/fast_haml/element_parser.rb', line 10

def initialize(line_parser)
  @line_parser = line_parser
end

Instance Method Details

#parse(text) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fast_haml/element_parser.rb', line 16

def parse(text)
  m = text.match(ELEMENT_REGEXP)
  unless m
    syntax_error!('Invalid element declaration')
  end

  element = Ast::Element.new
  element.tag_name = m[1]
  element.static_class, element.static_id = parse_class_and_id(m[2])
  rest = m[3] || ''

  element.attributes, rest = parse_attributes(rest)
  element.nuke_inner_whitespace, element.nuke_outer_whitespace, rest = parse_nuke_whitespace(rest)
  element.self_closing, rest = parse_self_closing(rest)
  element.oneline_child = ScriptParser.new(@line_parser).parse(rest)

  element
end