Class: Liquid2::TableRowTag
- Inherits:
-
Tag
- Object
- Node
- Tag
- Liquid2::TableRowTag
show all
- Defined in:
- lib/liquid2/nodes/tags/tablerow.rb
Overview
The standard tablerow tag.
Constant Summary
collapse
- END_BLOCK =
Set["endtablerow"]
Instance Attribute Summary
Attributes inherited from Node
#blank, #token
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tag
#name
Methods inherited from Node
#partial_scope, #render_with_disabled_tag_check, #template_scope
Constructor Details
#initialize(token, expression, block) ⇒ TableRowTag
Returns a new instance of TableRowTag.
19
20
21
22
23
24
|
# File 'lib/liquid2/nodes/tags/tablerow.rb', line 19
def initialize(token, expression, block)
super(token)
@expression = expression
@block = block
@blank = false
end
|
Class Method Details
.parse(token, parser) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/liquid2/nodes/tags/tablerow.rb', line 10
def self.parse(token, parser)
expression = parser.parse_loop_expression
parser.carry_whitespace_control
parser.eat(:token_tag_end)
block = parser.parse_block(END_BLOCK)
parser.eat_empty_tag("endtablerow")
new(token, expression, block)
end
|
Instance Method Details
#block_scope ⇒ Object
71
72
73
74
|
# File 'lib/liquid2/nodes/tags/tablerow.rb', line 71
def block_scope
[@expression.identifier,
Identifier.new([:token_word, "tablerowloop", @expression.token.last])]
end
|
#children(_static_context, include_partials: true) ⇒ Object
68
|
# File 'lib/liquid2/nodes/tags/tablerow.rb', line 68
def children(_static_context, include_partials: true) = [@block]
|
#expressions ⇒ Object
69
|
# File 'lib/liquid2/nodes/tags/tablerow.rb', line 69
def expressions = [@expression]
|
#render(context, buffer) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/liquid2/nodes/tags/tablerow.rb', line 26
def render(context, buffer)
array = @expression.evaluate(context)
name = @expression.identifier.name
context.raise_for_loop_limit(length: array.length)
cols = if @expression.cols
Liquid2.to_liquid_int(context.evaluate(@expression.cols))
else
array.length
end
drop = TableRow.new(@expression.name, array.length, cols)
namespace = { "tablerowloop" => drop }
buffer << "<tr class=\"row1\">\n"
context.extend(namespace) do
index = 0
while index < array.length
namespace[name] = array[index]
index += 1
drop.next
buffer << "<td class=\"col#{drop.col}\">"
@block.render(context, buffer)
buffer << "</td>"
buffer << "</tr>\n<tr class=\"row#{drop.row + 1}\">" if drop.col_last && !drop.last
case context.interrupts.pop
when :continue
next
when :break
break
end
end
buffer << "</tr>\n"
end
end
|