Class: Liquid::Case

Inherits:
Block show all
Defined in:
lib/liquid/tags/case.rb

Constant Summary collapse

Syntax =
/(#{QuotedFragment})/
WhenSyntax =
/(#{QuotedFragment})/

Instance Attribute Summary

Attributes inherited from Tag

#nodelist

Instance Method Summary collapse

Methods inherited from Block

#block_delimiter, #block_name, #create_variable, #end_tag, #parse

Methods inherited from Tag

#name, #parse

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.attachment, context) if output.empty? || output.join !~ /\S/
    else
      
      if block.evaluate(context)
        context.stack do          
          output += render_all(block.attachment, 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