Class: Haml::AttributeParser

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

Defined Under Namespace

Classes: ParseSkip

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available?TrueClass, FalseClass

Returns - return true if AttributeParser.parse can be used.

Returns:

  • (TrueClass, FalseClass)
    • return true if AttributeParser.parse can be used.


10
11
12
13
# File 'lib/haml/attribute_parser.rb', line 10

def self.available?
  # TruffleRuby doesn't have Ripper.lex
  defined?(Ripper) && Ripper.respond_to?(:lex) && Temple::StaticAnalyzer.available?
end

.parse(text)



15
16
17
# File 'lib/haml/attribute_parser.rb', line 15

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

Instance Method Details

#parse(text)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/haml/attribute_parser.rb', line 19

def parse(text)
  exp = wrap_bracket(text)
  return if Temple::StaticAnalyzer.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