Class: Hamlit::AttributeParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hamlit/attribute_parser.rb

Defined Under Namespace

Classes: ParseSkip

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(text) ⇒ Object


9
10
11
# File 'lib/hamlit/attribute_parser.rb', line 9

def self.parse(text)
  self.new.parse(text)
end

Instance Method Details

#parse(text) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hamlit/attribute_parser.rb', line 13

def parse(text)
  exp = wrap_bracket(text)
  return if RubyExpression.syntax_error?(exp)

  hash = {}
  tokens = Ripper.lex(exp)[1..-2] || []
  each_attr(tokens) do |attr_tokens|
    key = parse_key!(attr_tokens)
    hash[key] = attr_tokens.map { |t| t[2] }.join.strip
  end
  hash
rescue ParseSkip
  nil
end