Class: Luoma::IfTag
- Defined in:
- lib/luoma/tags/if.rb,
sig/luoma/tags/if.rbs
Constant Summary collapse
- END_IF_BLOCK =
Set["else", "elif", "elsif", "endif"]
- ELSE_IF_TAGS =
Set["elif", "elsif"]
Instance Attribute Summary
Attributes inherited from Markup
Class Method Summary collapse
-
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup.
Instance Method Summary collapse
-
#children(static_context) ⇒ Array[Markup]
(RenderContext) -> Array.
-
#initialize(token, tag_name, alts) ⇒ IfTag
constructor
A new instance of IfTag.
-
#render(context, buffer) ⇒ void
(RenderContext, String) -> void.
Methods inherited from Markup
#block_scope, #expressions, #partial, #template_scope
Constructor Details
#initialize(token, tag_name, alts) ⇒ IfTag
Returns a new instance of IfTag.
39 40 41 42 43 44 45 |
# File 'lib/luoma/tags/if.rb', line 39 def initialize(token, tag_name, alts) super(token) @tag_name = tag_name @alts = alts @blank = alts.all?(&:blank) @alts.each(&:filter_strings) if @blank end |
Class Method Details
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/luoma/tags/if.rb', line 9 def self.parse(token, tag_name, parser) blocks = [] #: Array[IfBlock | ElseBlock] parser.expect_expression expression = parser.parse_expression parser.carry_whitespace_control parser.eat(:token_tag_end) block = parser.parse_block(stop: END_IF_BLOCK) blocks << IfBlock.new(token, "if", expression, block) loop do inner_tag_name = parser.(ELSE_IF_TAGS) break unless inner_tag_name blocks << IfBlock.parse(inner_tag_name, parser) end if parser.tag?("else") name_token = parser.eat_empty_tag("else") blocks << ElseBlock.new( name_token, "else", parser.parse_block(stop: END_IF_BLOCK) ) end parser.eat_empty_tag("endif") IfTag.new(token, tag_name, blocks) end |
Instance Method Details
#children(static_context) ⇒ Array[Markup]
(RenderContext) -> Array
60 61 62 |
# File 'lib/luoma/tags/if.rb', line 60 def children(static_context) @alts end |
#render(context, buffer) ⇒ void
This method returns an undefined value.
(RenderContext, String) -> void
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/luoma/tags/if.rb', line 48 def render(context, buffer) index = 0 while (alt = @alts[index]) if context.env.truthy?(alt.expression.evaluate(context), context) Luoma.render_block(alt.block, context, buffer) break end index += 1 end end |