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
- SEPARATOR =
Separator.new
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.
227 228 229 230 231 232 |
# File 'lib/syntax_tree/haml/format.rb', line 227 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.
225 226 227 |
# File 'lib/syntax_tree/haml/format.rb', line 225 def values @values end |
Instance Method Details
#format(q, align) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/syntax_tree/haml/format.rb', line 234 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
246 247 248 |
# File 'lib/syntax_tree/haml/format.rb', line 246 def length values.sum { |key, value| key.length + value.length + 3 } end |