Class: SyntaxTree::Haml::Format::HTMLAttributesPart
- Inherits:
-
Object
- Object
- SyntaxTree::Haml::Format::HTMLAttributesPart
- Defined in:
- lib/syntax_tree/haml/format.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.
183 184 185 186 187 188 |
# File 'lib/syntax_tree/haml/format.rb', line 183 def initialize(raw) @values = raw[1...-1] .split(",") .to_h { |keypair| keypair[1..-1].split("\" => ") } end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
181 182 183 |
# File 'lib/syntax_tree/haml/format.rb', line 181 def values @values end |
Instance Method Details
#format(q, align) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/syntax_tree/haml/format.rb', line 190 def format(q, align) q.group do q.text("(") q.nest(align) do q.seplist( values, -> { q.fill_breakable }, :each_pair ) { |key, value| q.text("#{key}=#{value}") } end q.text(")") end end |
#length ⇒ Object
204 205 206 |
# File 'lib/syntax_tree/haml/format.rb', line 204 def length values.sum { |key, value| key.length + value.length + 3 } end |