Module: Hamlit::Compilers::OldAttribute
- Includes:
- Hamlit::Concerns::AttributeBuilder, Hamlit::Concerns::Balanceable, Hamlit::Concerns::Lexable
- 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
- DEFAULT_COUNTS =
{ brace: -1, emb: 0, paren: 0, bracket: 0, }.freeze
- OPEN_TOKEN_TYPES =
{ on_lbrace: :brace, on_embexpr_beg: :emb, on_lparen: :paren, on_lbracket: :bracket, }.freeze
- CLOSE_TOKEN_TYPES =
{ on_rbrace: :brace, on_embexpr_end: :emb, on_rparen: :paren, on_rbracket: :bracket, }.freeze
Constants included from Hamlit::Concerns::Lexable
Hamlit::Concerns::Lexable::TYPE_POSITION
Instance Method Summary collapse
Methods included from Hamlit::Concerns::Lexable
#convert_position, #skip_tokens!, #type_of
Methods included from Hamlit::Concerns::Balanceable
#balanced_braces_exist?, #balanced_embexprs_exist?, #balanced_parens_exist?, #fetch_balanced_braces, #fetch_balanced_embexprs, #fetch_balanced_parentheses
Methods included from Hamlit::Concerns::AttributeBuilder
Instance Method Details
#compile_old_attribute(str) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hamlit/compilers/old_attribute.rb', line 55 def compile_old_attribute(str) raise RuntimeBuild unless valid_hash?(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 |