Class: Liquid::Unless

Inherits:
If show all
Defined in:
lib/liquid/tags/unless.rb

Overview

Unless is a conditional just like ‘if’ but works on the inverse logic.

{% unless x < 0 %} x is greater than zero {% endunless %}

Constant Summary

Constants inherited from If

If::BOOLEAN_OPERATORS, If::ExpressionsAndOperators, If::Syntax

Instance Attribute Summary

Attributes inherited from Tag

#line_number, #nodelist, #parse_context, #tag_name

Instance Method Summary collapse

Methods inherited from If

#initialize, #nodelist, #parse, #unknown_tag

Methods inherited from Block

#blank?, #block_delimiter, #block_name, #initialize, #nodelist, #parse, #unknown_tag

Methods inherited from Tag

#blank?, #initialize, #name, parse, #parse, #raw

Methods included from ParserSwitching

#parse_with_selected_parser

Constructor Details

This class inherits a constructor from Liquid::If

Instance Method Details

#render(context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/liquid/tags/unless.rb', line 9

def render(context)
  context.stack do
    # First condition is interpreted backwards ( if not )
    first_block = @blocks.first
    unless first_block.evaluate(context)
      return first_block.attachment.render(context)
    end

    # After the first condition unless works just like if
    @blocks[1..-1].each do |block|
      if block.evaluate(context)
        return block.attachment.render(context)
      end
    end

    ''.freeze
  end
end