Class: Haml::AttributeCompiler

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

Defined Under Namespace

Classes: AttributeValue

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AttributeCompiler

Returns a new instance of AttributeCompiler.

Parameters:



13
14
15
16
17
18
# File 'lib/haml/attribute_compiler.rb', line 13

def initialize(options)
  @is_html = [:html4, :html5].include?(options[:format])
  @attr_wrapper = options[:attr_wrapper]
  @escape_attrs = options[:escape_attrs]
  @hyphenate_data_attrs = options[:hyphenate_data_attrs]
end

Instance Method Details

#compile(attributes, object_ref, dynamic_attributes) ⇒ Array

Returns Temple expression to render attributes.

Parameters:

Returns:

  • (Array)

    Temple expression



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/haml/attribute_compiler.rb', line 26

def compile(attributes, object_ref, dynamic_attributes)
  if object_ref != :nil || !AttributeParser.available?
    return [:dynamic, compile_runtime_build(attributes, object_ref, dynamic_attributes)]
  end

  parsed_hashes = [dynamic_attributes.new, dynamic_attributes.old].compact.map do |attribute_hash|
    unless (hash = AttributeParser.parse(attribute_hash))
      return [:dynamic, compile_runtime_build(attributes, object_ref, dynamic_attributes)]
    end
    hash
  end
  attribute_values = build_attribute_values(attributes, parsed_hashes)
  AttributeBuilder.verify_attribute_names!(attribute_values.map(&:key))

  [:multi, *group_values_for_sort(attribute_values).map { |value_group|
    compile_attribute_values(value_group)
  }]
end