Class: SyntaxTree::Haml::Tag::HTMLAttributesPart
- Inherits:
-
Object
- Object
- SyntaxTree::Haml::Tag::HTMLAttributesPart
- Defined in:
- lib/syntax_tree/haml/tag.rb
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #format(q, align) ⇒ Object
-
#initialize(raw) ⇒ HTMLAttributesPart
constructor
A new instance of HTMLAttributesPart.
- #length ⇒ Object
Constructor Details
#initialize(raw) ⇒ HTMLAttributesPart
Returns a new instance of HTMLAttributesPart.
46 47 48 49 50 51 |
# File 'lib/syntax_tree/haml/tag.rb', line 46 def initialize(raw) @values = raw[1...-1].split(",").to_h do |keypair| keypair[1..-1].split("\" => ") end end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
44 45 46 |
# File 'lib/syntax_tree/haml/tag.rb', line 44 def values @values end |
Instance Method Details
#format(q, align) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/syntax_tree/haml/tag.rb', line 53 def format(q, align) q.group do q.text("(") q.nest(align) do q.seplist(values, -> { q.fill_breakable }, :each_pair) do |key, value| q.text("#{key}=#{value}") end end q.text(")") end end |
#length ⇒ Object
65 66 67 |
# File 'lib/syntax_tree/haml/tag.rb', line 65 def length values.sum { |key, value| key.length + value.length + 3 } end |