Class: SyntaxTree::Haml::Tag::HTMLAttributesPart

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#valuesObject (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

#lengthObject



65
66
67
# File 'lib/syntax_tree/haml/tag.rb', line 65

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