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

Constants inherited from Block

Block::MAX_DEPTH

Instance Attribute Summary

Attributes inherited from If

#blocks

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, #raise_tag_never_closed, raise_unknown_tag, #render, #unknown_tag

Methods inherited from Tag

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

Methods included from ParserSwitching

#parse_with_selected_parser, #strict_parse_with_error_mode_fallback

Constructor Details

This class inherits a constructor from Liquid::If

Instance Method Details

#render_to_output_buffer(context, output) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/liquid/tags/unless.rb', line 11

def render_to_output_buffer(context, output)
  # First condition is interpreted backwards ( if not )
  first_block = @blocks.first
  result = Liquid::Utils.to_liquid_value(
    first_block.evaluate(context)
  )

  unless result
    return first_block.attachment.render_to_output_buffer(context, output)
  end

  # After the first condition unless works just like if
  @blocks[1..-1].each do |block|
    result = Liquid::Utils.to_liquid_value(
      block.evaluate(context)
    )

    if result
      return block.attachment.render_to_output_buffer(context, output)
    end
  end

  output
end