Class: EZML::AttributeCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/ezml/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.



22
23
24
25
26
27
# File 'lib/ezml/attribute_compiler.rb', line 22

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) ⇒ Object



18
19
20
# File 'lib/ezml/attribute_compiler.rb', line 18

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

Instance Method Details

#compile(attributes, object_ref, dynamic_attributes) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ezml/attribute_compiler.rb', line 29

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