Class: Haml::AttributeCompiler

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

Defined Under Namespace

Classes: AttributeValue

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AttributeCompiler

Returns a new instance of AttributeCompiler

Parameters:



32
33
34
35
36
37
# File 'lib/haml/attribute_compiler.rb', line 32

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

Class Method Details

.runtime_build(attributes, object_ref, dynamic_attributes) ⇒ String

Returns a script to render attributes on runtime.

Parameters:

  • attributes (Hash)
  • object_ref (String, :nil)
  • dynamic_attributes (DynamicAttributes)

Returns:

  • (String)

    Attributes rendering code



27
28
29
# File 'lib/haml/attribute_compiler.rb', line 27

def self.runtime_build(attributes, object_ref, dynamic_attributes)
  "_hamlout.attributes(#{Haml::Util.inspect_obj(attributes)}, #{object_ref},#{dynamic_attributes.to_literal})"
end

Instance Method Details

#compile(attributes, object_ref, dynamic_attributes) ⇒ Array

Returns Temple expression to render attributes.

Parameters:

  • attributes (Hash)
  • object_ref (String, :nil)
  • dynamic_attributes (DynamicAttributes)

Returns:

  • (Array)

    Temple expression



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/haml/attribute_compiler.rb', line 45

def compile(attributes, object_ref, dynamic_attributes)
  if object_ref != :nil || !AttributeParser.available?
    return [:dynamic, AttributeCompiler.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, AttributeCompiler.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