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 =
Only data can be nested for performance.
%w[data].freeze
- IGNORED_EXPRESSIONS =
%w[false nil].freeze
- JOIN_ATTRIBUTES =
Class and id are joined if the value is an array.
%w[class id].freeze
- JOINABLE_TOKENS =
%i[on_ident on_qwords_beg on_lbracket].freeze
- BOOLEAN_ATTRIBUTES =
Only boolean attributes can be deleted for performance.
%w[disabled readonly multiple checked autobuffer autoplay controls loop selected hidden scoped async defer reversed ismap seamless muted required autofocus novalidate formnovalidate open pubdate itemscope allowfullscreen default inert sortable truespeed typemustmatch data].freeze
Constants included from Hamlit::Concerns::Ripperable
Hamlit::Concerns::Ripperable::TYPE_POSITION
Instance Method Summary collapse
Methods included from Hamlit::Concerns::Ripperable
Methods included from Hamlit::Concerns::Balanceable
#balanced_braces_exist?, #balanced_parens_exist?, #fetch_balanced_braces, #fetch_balanced_parentheses
Methods included from Hamlit::Concerns::AttributeBuilder
Instance Method Details
#compile_old_attribute(str) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hamlit/compilers/old_attribute.rb', line 34 def compile_old_attribute(str) raise RuntimeBuild unless Ripper.sexp(str) attrs = parse_old_attributes(str) assert_no_boolean_attributes!(attrs) format_attributes(attrs).map do |key, value| next true_attribute(key) if value == 'true' assert_static_value!(value) if NESTABLE_ATTRIBUTES.include?(key) detect_joinable_value!(value) if JOIN_ATTRIBUTES.include?(key) [:html, :attr, key, [:dynamic, value]] end rescue RuntimeBuild # Give up static compilation when given string is invalid as ruby hash [[:runtime, str]] end |