class Haml::Parser
def parse_static_hash(text)
-
(Hash, nil)
- - Return nil if text is not static Hash literal
Parameters:
-
text
(String
) -- - Hash literal or text inside old attributes
def parse_static_hash(text) attributes = {} return attributes if text.empty? text = text[1...-1] # strip brackets scanner = StringScanner.new(text) scanner.scan(/\s+/) until scanner.eos? return unless key = scanner.scan(LITERAL_VALUE_REGEX) return unless scanner.scan(/\s*=>\s*/) return unless value = scanner.scan(LITERAL_VALUE_REGEX) return unless scanner.scan(/\s*(?:,|$)\s*/) attributes[eval(key).to_s] = eval(value).to_s end attributes end