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
-
.available? ⇒ Boolean
- return true if AttributeParser.parse can be used.
-
.parse(exp) ⇒ Hash<String, String>?
- Return parsed attribute Hash whose values are Ruby literals, or return nil if argument is not a single Hash literal.
Class Method Details
.available? ⇒ Boolean
Returns - return true if AttributeParser.parse can be used.
23 24 25 |
# File 'lib/haml/attribute_parser.rb', line 23
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.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/haml/attribute_parser.rb', line 29
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
|