Class: Luoma::WithTag
- Inherits:
-
Markup
show all
- Defined in:
- lib/luoma/tags/with.rb,
sig/luoma/tags/with.rbs
Constant Summary
collapse
- END_WITH_BLOCK =
Set["endwith"]
Instance Attribute Summary
Attributes inherited from Markup
#blank, #tag_name, #token
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Markup
#partial, #template_scope
Constructor Details
#initialize(token, tag_name, args, block) ⇒ WithTag
(t_token, String, Array, t_block) -> void
18
19
20
21
22
23
24
|
# File 'lib/luoma/tags/with.rb', line 18
def initialize(token, tag_name, args, block)
super(token)
@tag_name = tag_name
@args = args
@block = block
@blank = Luoma.blank_block?(block)
end
|
Class Method Details
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup
8
9
10
11
12
13
14
15
|
# File 'lib/luoma/tags/with.rb', line 8
def self.parse(token, tag_name, parser)
args = parser.parse_keyword_arguments(require_commas: true)
parser.carry_whitespace_control
parser.eat(:token_tag_end)
block = parser.parse_block(stop: END_WITH_BLOCK)
parser.eat_empty_tag("endwith")
new(token, tag_name, args, block)
end
|
Instance Method Details
#block_scope ⇒ Object
51
52
53
|
# File 'lib/luoma/tags/with.rb', line 51
def block_scope
@args.map(&:name)
end
|
#children(static_context) ⇒ Object
41
42
43
|
# File 'lib/luoma/tags/with.rb', line 41
def children(static_context)
@block.grep_v(String) end
|
#expressions ⇒ Object
46
47
48
|
# File 'lib/luoma/tags/with.rb', line 46
def expressions
@args.map(&:expression)
end
|
#render(context, buffer) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/luoma/tags/with.rb', line 27
def render(context, buffer)
scope = {}
context.extends(scope) do
@args.each do |arg|
scope[arg.name.value] = arg.expression.evaluate(context)
end
Luoma.render_block(@block, context, buffer)
end
end
|