# Class: Haml::AttributeCompiler

Inherits:
  Object
  - Object
  - Haml::AttributeCompiler
  show all

Defined in:
  lib/haml/attribute_compiler.rb

## Instance Method Summary collapse

- #compile(node)
- #initialize(identity, options) ⇒ AttributeCompiler constructor

  A new instance of AttributeCompiler.

## Constructor Details

### #initialize(identity, options) ⇒ `AttributeCompiler`

Returns a new instance of AttributeCompiler.

    16
    17
    18
    19
    20
    21

    # File 'lib/haml/attribute_compiler.rb', line 16

    def initialize(identity, options)
      @identity = identity
      @quote  = options[:attr_quote]
      @format = options[:format]
      @escape_attrs = options[:escape_attrs]
    end

## Instance Method Details

### #compile(node)

    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34

    # File 'lib/haml/attribute_compiler.rb', line 23

    def compile(node)
      hashes = []
      if node.value[:object_ref] != :nil || !AttributeParser.available?
        return runtime_compile(node)
      end
      [node.value[:dynamic_attributes].new, node.value[:dynamic_attributes].old].compact.each do |attribute_str|
        hash = AttributeParser.parse(attribute_str)
        return runtime_compile(node) if hash.nil? || hash.any? { |_key, value| value.empty? }
        hashes << hash
      end
      static_compile(node.value[:attributes], hashes)
    end