Sha256: 662d29f4fdf66a1f0d69b695fc2148055b57d2cbca7daf1cb46a6e67fa48075d
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
require 'hamlit/concerns/error' require 'hamlit/concerns/indentable' require 'hamlit/concerns/whitespace' require 'hamlit/helpers' module Hamlit module Parsers module Tag include Concerns::Error include Concerns::Indentable include Concerns::Whitespace TAG_ID_CLASS_REGEXP = /[a-zA-Z0-9_-]+/ TAG_REGEXP = /[a-zA-Z0-9\-_:]+/ DEFAULT_TAG = 'div' 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) ast = [:html, :tag, tag, attrs] inner_removal = parse_whitespace_removal(scanner) if scanner.match?(/=/) return ast << parse_script(scanner) elsif !has_block? return ast if scanner.scan(/\//) return ast << parse_line(scanner, inline: true) end content = [:multi, [:static, "\n"]] if inner_removal || Helpers::DEFAULT_PRESERVE_TAGS.include?(tag) content[0, 1] = [:haml, :strip] end content += with_tag_nested { parse_lines } ast << content ast end private def parse_tag_id_and_class(scanner) attributes = Hash.new { |h, k| h[k] = [] } while prefix = scanner.scan(/[#.]/) name = assert_scan!(scanner, TAG_ID_CLASS_REGEXP) case prefix when '#' attributes['id'] = [name] when '.' attributes['class'] << name end end ast = [] attributes.each do |name, values| ast << [:html, :attr, name, [:static, values.join(' ')]] end ast end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hamlit-1.5.7 | lib/hamlit/parsers/tag.rb |