Class: Liquid::If

Inherits:
DecisionBlock show all
Defined in:
lib/liquid/standardtags.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 DecisionBlock

#equal_variables, #interpret_condition

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.



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/liquid/standardtags.rb', line 293

def initialize(markup, tokens)
  @nodelist_true = @nodelist = []
  @nodelist_false = []

  super
                   
  if markup =~ Syntax
    @left = $1
    @operator = $2 
    @right = $3
  else
    raise SyntaxError.new("Syntax Error in tag 'if' - Valid syntax: if [condition]")
  end
  
end

Instance Method Details

#render(context) ⇒ Object



317
318
319
320
321
322
323
324
325
# File 'lib/liquid/standardtags.rb', line 317

def render(context)
  context.stack do       
    if interpret_condition(@left, @right, @operator, context)
      render_all(@nodelist_true, context)
    else
      render_all(@nodelist_false, context)
    end
  end
end

#unknown_tag(tag, params, tokens) ⇒ Object



309
310
311
312
313
314
315
# File 'lib/liquid/standardtags.rb', line 309

def unknown_tag(tag, params, tokens)
  if tag == 'else'
    @nodelist = @nodelist_false = []
  else
    super
  end
end