Class: Liquid::Case
Constant Summary collapse
- Syntax =
/(#{QuotedFragment})/o
- WhenSyntax =
/(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
Constants inherited from Block
Block::ContentOfVariable, Block::FullToken, Block::TAGSTART, Block::VARSTART
Instance Attribute Summary
Attributes inherited from Tag
#line_number, #options, #warnings
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Case
constructor
A new instance of Case.
- #nodelist ⇒ Object
- #render(context) ⇒ Object
- #unknown_tag(tag, markup, tokens) ⇒ Object
Methods inherited from Block
#blank?, #block_delimiter, #block_name, #create_variable, #parse, #render_token_with_profiling, #warnings
Methods inherited from Tag
#blank?, #name, #parse, parse, #raw
Methods included from ParserSwitching
Constructor Details
#initialize(tag_name, markup, options) ⇒ Case
Returns a new instance of Case.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/liquid/tags/case.rb', line 6 def initialize(tag_name, markup, ) super @blocks = [] if markup =~ Syntax @left = $1 else raise SyntaxError.new([:locale].t("errors.syntax.case".freeze)) end end |
Instance Method Details
#nodelist ⇒ Object
17 18 19 |
# File 'lib/liquid/tags/case.rb', line 17 def nodelist @blocks.flat_map(&:attachment) end |
#render(context) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/liquid/tags/case.rb', line 33 def render(context) context.stack do execute_else_block = true output = '' @blocks.each do |block| if block.else? return render_all(block., context) if execute_else_block elsif block.evaluate(context) execute_else_block = false output << render_all(block., context) end end output end end |
#unknown_tag(tag, markup, tokens) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/liquid/tags/case.rb', line 21 def unknown_tag(tag, markup, tokens) @nodelist = [] case tag when 'when'.freeze record_when_condition(markup) when 'else'.freeze record_else_condition(markup) else super end end |