Module: Haml::AttributeParser

Defined in:
lib/haml/attribute_parser.rb

Overview

Haml::AttriubuteParser parses Hash literal to { String (key name) => String (value literal) }.

Defined Under Namespace

Classes: UnexpectedKeyError, UnexpectedTokenError

Class Method Summary collapse

Class Method Details

.available?Boolean

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

Returns:

  • (Boolean)
    • return true if AttributeParser.parse can be used.


21
22
23
# File 'lib/haml/attribute_parser.rb', line 21

def available?
  defined?(Ripper) && Temple::StaticAnalyzer.available?
end

.parse(exp) ⇒ Hash<String, String>?

Returns - Return parsed attribute Hash whose values are Ruby literals, or return nil if argument is not a single Hash literal.

Parameters:

  • exp (String)
    • Old attributes literal or Hash literal generated from new attributes.

Returns:

  • (Hash<String, String>, nil)
    • Return parsed attribute Hash whose values are Ruby literals, or return nil if argument is not a single Hash literal.


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/haml/attribute_parser.rb', line 27

def parse(exp)
  return nil unless hash_literal?(exp)

  hash = {}
  each_attribute(exp) do |key, value|
    hash[key] = value
  end
  hash
rescue UnexpectedTokenError, UnexpectedKeyError
  nil
end