Class: SyntaxTree::Haml::Format::PartList
- Inherits:
-
Object
- Object
- SyntaxTree::Haml::Format::PartList
- Defined in:
- lib/syntax_tree/haml/format.rb
Overview
When formatting a tag, there are a lot of different kinds of things that can be printed out. There’s the tag name, the attributes, the content, etc. This object is responsible for housing all of those parts.
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #<<(part) ⇒ Object
- #empty? ⇒ Boolean
- #format(q) ⇒ Object
-
#initialize(node) ⇒ PartList
constructor
A new instance of PartList.
Constructor Details
#initialize(node) ⇒ PartList
Returns a new instance of PartList.
177 178 179 180 |
# File 'lib/syntax_tree/haml/format.rb', line 177 def initialize(node) @node = node @parts = [] end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
175 176 177 |
# File 'lib/syntax_tree/haml/format.rb', line 175 def node @node end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
175 176 177 |
# File 'lib/syntax_tree/haml/format.rb', line 175 def parts @parts end |
Instance Method Details
#<<(part) ⇒ Object
182 183 184 |
# File 'lib/syntax_tree/haml/format.rb', line 182 def <<(part) parts << part end |
#empty? ⇒ Boolean
186 187 188 |
# File 'lib/syntax_tree/haml/format.rb', line 186 def empty? parts.empty? end |
#format(q) ⇒ 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) if empty? && node.value[:name] == "div" # If we don't have any other parts to print and the tag is a div # then we need to make sure to add that to the beginning. Otherwise # it's implied by the presence of other operators. q.text("%div") else parts.inject(0) do |align, part| part.format(q, align) align + part.length end end end |