Class: SyntaxTree::Haml::Format::HTMLAttributesPart
- Inherits:
-
Object
- Object
- SyntaxTree::Haml::Format::HTMLAttributesPart
- Defined in:
- lib/syntax_tree/haml/format.rb
Defined Under Namespace
Classes: Separator
Constant Summary collapse
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.
237 238 239 240 241 242 |
# File 'lib/syntax_tree/haml/format.rb', line 237 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.
235 236 237 |
# File 'lib/syntax_tree/haml/format.rb', line 235 def values @values end |
Instance Method Details
#format(q, align) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/syntax_tree/haml/format.rb', line 244 def format(q, align) q.group do q.text("(") q.nest(align) do q.seplist(values, SEPARATOR, :each_pair) do |key, value| q.text("#{key}=#{value}") end end q.text(")") end end |
#length ⇒ Object
256 257 258 |
# File 'lib/syntax_tree/haml/format.rb', line 256 def length values.sum { |key, value| key.length + value.length + 3 } end |