Class: Haml::AttributeCompiler
- Inherits:
-
Object
- Object
- Haml::AttributeCompiler
- Defined in:
- lib/haml/attribute_compiler.rb
Defined Under Namespace
Classes: AttributeValue
Class Method Summary collapse
-
.runtime_build(attributes, object_ref, dynamic_attributes) ⇒ String
Returns a script to render attributes on runtime.
Instance Method Summary collapse
-
#compile(attributes, object_ref, dynamic_attributes) ⇒ Array
Returns Temple expression to render attributes.
-
#initialize(options) ⇒ AttributeCompiler
constructor
A new instance of AttributeCompiler.
Constructor Details
#initialize(options) ⇒ AttributeCompiler
Returns a new instance of AttributeCompiler.
38 39 40 41 42 43 |
# File 'lib/haml/attribute_compiler.rb', line 38
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.
33 34 35 |
# File 'lib/haml/attribute_compiler.rb', line 33
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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/haml/attribute_compiler.rb', line 51
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))
values_by_base_key = attribute_values.group_by(&:base_key)
[:multi, *values_by_base_key.keys.sort.map { |base_key|
compile_attribute_values(values_by_base_key[base_key])
}]
end
|