# Class: Haml::AttributeParser

Inherits:
  Object
  - Object
  - Haml::AttributeParser
  show all

Defined in:
  lib/haml/attribute_parser.rb

## Defined Under Namespace

Classes: ParseSkip

## Class Method Summary collapse

- .available? ⇒ TrueClass, FalseClass
  - return true if AttributeParser.parse can be used.
- .parse(text)

## Instance Method Summary collapse

- #parse(text)

## 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

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

    def self.available?
      Temple::StaticAnalyzer.available?
    end

### .parse(text)

    14
    15
    16

    # File 'lib/haml/attribute_parser.rb', line 14

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

## Instance Method Details

### #parse(text)

    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    # File 'lib/haml/attribute_parser.rb', line 18

    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