Module: Hamlit::Parsers::Tag
- Includes:
- Concerns::Error, Concerns::Indentable
- Included in:
- Hamlit::Parser
- Defined in:
- lib/hamlit/parsers/tag.rb
Constant Summary collapse
- TAG_ID_CLASS_REGEXP =
/[a-zA-Z0-9_-]+/
- TAG_REGEXP =
/[a-zA-Z0-9\-_:]+/
- DEFAULT_TAG =
'div'
Instance Method Summary collapse
Methods included from Concerns::Indentable
#count_indent, #count_width, #indent_label, #next_indent, #next_width, #replace_hard_tabs, #reset_indent, #same_indent?, #validate_indentation!, #with_indented
Methods included from Concerns::Error
#assert_scan!, #copmile_error!, #syntax_error, #syntax_error!
Instance Method Details
#parse_tag(scanner) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hamlit/parsers/tag.rb', line 15 def parse_tag(scanner) tag = DEFAULT_TAG tag = scanner.scan(TAG_REGEXP) if scanner.scan(/%/) attrs = [:haml, :attrs] attrs += parse_tag_id_and_class(scanner) attrs += parse_attributes(scanner) inner_removal = parse_whitespace_removal(scanner) ast = [:html, :tag, tag, attrs] if scanner.match?(/=/) ast << parse_script(scanner) return ast elsif scanner.scan(/\//) return ast elsif scanner.rest.match(/[^ ]/) ast << parse_text(scanner) return ast elsif next_indent <= @current_indent return ast << [:multi] end content = [:multi, [:static, "\n"]] if inner_removal || Helpers::DEFAULT_PRESERVE_TAGS.include?(tag) content[0, 1] = [:haml, :strip] end content += with_indented { parse_lines } ast << content ast end |