Class: Liquid::If

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

Direct Known Subclasses

Unless

Constant Summary collapse

Syntax =
/(#{QuotedFragment})\s*([=!<>]+)?\s*(#{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) ⇒ If

Returns a new instance of If.



5
6
7
8
9
10
11
# File 'lib/liquid/tags/if.rb', line 5

def initialize(markup, tokens)    
  @blocks = []
  
  push_block('if', markup)
  
  super      
end

Instance Method Details

#render(context) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/liquid/tags/if.rb', line 21

def render(context)
  context.stack do
    @blocks.each do |block|
      if block.evaluate(context)            
        return render_all(block.attachment, context)            
      end
    end 
    ''
  end
end

#unknown_tag(tag, markup, tokens) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/liquid/tags/if.rb', line 13

def unknown_tag(tag, markup, tokens)
  if ['elsif', 'else'].include?(tag)
    push_block(tag, markup)
  else
    super
  end
end