Class: SyntaxTree::Haml::Format::HTMLAttributesPart

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/haml/format.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ HTMLAttributesPart

Returns a new instance of HTMLAttributesPart.



206
207
208
209
210
211
# File 'lib/syntax_tree/haml/format.rb', line 206

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.



204
205
206
# File 'lib/syntax_tree/haml/format.rb', line 204

def values
  @values
end

Instance Method Details

#format(q, align) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/syntax_tree/haml/format.rb', line 213

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



227
228
229
# File 'lib/syntax_tree/haml/format.rb', line 227

def length
  values.sum { |key, value| key.length + value.length + 3 }
end