Module: Hamlit::Compilers::OldAttribute

Includes:
Hamlit::Concerns::AttributeBuilder, Hamlit::Concerns::Balanceable, Hamlit::Concerns::Ripperable
Included in:
Attributes
Defined in:
lib/hamlit/compilers/old_attribute.rb

Defined Under Namespace

Classes: HashParser

Constant Summary collapse

NESTABLE_ATTRIBUTES =

For performance, only data can be nested.

%w[data].freeze
IGNORED_EXPRESSIONS =
%w[false nil].freeze

Constants included from Hamlit::Concerns::Ripperable

Hamlit::Concerns::Ripperable::TYPE_POSITION

Instance Method Summary collapse

Methods included from Hamlit::Concerns::Ripperable

#skip_tokens!, #type_of

Methods included from Hamlit::Concerns::Balanceable

#balanced_braces_exist?, #balanced_parens_exist?, #fetch_balanced_braces, #fetch_balanced_parentheses

Methods included from Hamlit::Concerns::AttributeBuilder

#flatten_attributes

Instance Method Details

#compile_old_attribute(str) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hamlit/compilers/old_attribute.rb', line 23

def compile_old_attribute(str)
  raise RuntimeBuild unless Ripper.sexp(str)

  attrs = parse_old_attributes(str)
  format_attributes(attrs).map do |key, value|
    next true_attribute(key) if value == 'true'
    assert_static_value!(value) if NESTABLE_ATTRIBUTES.include?(key)

    [:html, :attr, key, [:dynamic, value]]
  end
rescue RuntimeBuild
  return runtime_build(str)
end