Class: Liquid::Case
Constant Summary collapse
- Syntax =
/(#{QuotedFragment})/
- WhenSyntax =
/(#{QuotedFragment})/
Instance Attribute Summary
Attributes inherited from Tag
Instance Method Summary collapse
-
#initialize(markup, tokens) ⇒ Case
constructor
A new instance of Case.
- #render(context) ⇒ Object
- #unknown_tag(tag, markup, tokens) ⇒ Object
Methods inherited from Block
#block_delimiter, #block_name, #create_variable, #end_tag, #parse
Methods inherited from Tag
Constructor Details
#initialize(markup, tokens) ⇒ Case
Returns a new instance of Case.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/liquid/tags/case.rb', line 6 def initialize(markup, tokens) @blocks = [] if markup =~ Syntax @left = $1 else raise SyntaxError.new("Syntax Error in tag 'case' - Valid syntax: case [condition]") end push_block('case', markup) super end |
Instance Method Details
#render(context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/liquid/tags/case.rb', line 28 def render(context) @blocks.inject([]) do |output, block| if block.else? return render_all(block., context) if output.empty? || output.join !~ /\S/ else if block.evaluate(context) context.stack do output += render_all(block., context) end end end output end.join end |
#unknown_tag(tag, markup, tokens) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/liquid/tags/case.rb', line 20 def unknown_tag(tag, markup, tokens) if ['when', 'else'].include?(tag) push_block(tag, markup) else super end end |