Class: Liquid::Case
Defined Under Namespace
Classes: ParseTreeVisitor
Constant Summary collapse
- Syntax =
/(#{QuotedFragment})/o
- WhenSyntax =
/(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
Constants inherited from Block
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
Attributes inherited from Tag
#line_number, #parse_context, #tag_name
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Case
constructor
A new instance of Case.
- #nodelist ⇒ Object
- #parse(tokens) ⇒ Object
- #render(context) ⇒ Object
- #unknown_tag(tag, markup, tokens) ⇒ Object
Methods inherited from Block
#blank?, #block_delimiter, #block_name
Methods inherited from Tag
Methods included from ParserSwitching
Constructor Details
#initialize(tag_name, markup, options) ⇒ Case
Returns a new instance of Case.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/liquid/tags/case.rb', line 8 def initialize(tag_name, markup, ) super @blocks = [] if markup =~ Syntax @left = Expression.parse($1) else raise SyntaxError.new([:locale].t("errors.syntax.case".freeze)) end end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
6 7 8 |
# File 'lib/liquid/tags/case.rb', line 6 def blocks @blocks end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
6 7 8 |
# File 'lib/liquid/tags/case.rb', line 6 def left @left end |
Instance Method Details
#nodelist ⇒ Object
26 27 28 |
# File 'lib/liquid/tags/case.rb', line 26 def nodelist @blocks.map(&:attachment) end |
#parse(tokens) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/liquid/tags/case.rb', line 19 def parse(tokens) body = BlockBody.new while parse_body(body, tokens) body = @blocks.last. end end |
#render(context) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/liquid/tags/case.rb', line 41 def render(context) context.stack do execute_else_block = true output = '' @blocks.each do |block| if block.else? return block..render(context) if execute_else_block elsif block.evaluate(context) execute_else_block = false output << block..render(context) end end output end end |
#unknown_tag(tag, markup, tokens) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/liquid/tags/case.rb', line 30 def unknown_tag(tag, markup, tokens) case tag when 'when'.freeze record_when_condition(markup) when 'else'.freeze record_else_condition(markup) else super end end |