Sha256: 361b5bc007d72a2c7841321d87b71c43ab824134356360d95b4eda3c15788cb6

Contents?: true

Size: 776 Bytes

Versions: 11

Compression:

Stored size: 776 Bytes

Contents

require_relative 'if'

module Liquid
  # Unless is a conditional just like 'if' but works on the inverse logic.
  #
  #   {% unless x < 0 %} x is greater than zero {% endunless %}
  #
  class Unless < If
    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
  end

  Template.register_tag('unless'.freeze, Unless)
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
liquid-4.0.4 lib/liquid/tags/unless.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/liquid-4.0.3/lib/liquid/tags/unless.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/liquid-4.0.3/lib/liquid/tags/unless.rb
liquid-4.0.3 lib/liquid/tags/unless.rb
liquid-4.0.2 lib/liquid/tags/unless.rb
liquid-4-0-2-4.0.2 lib/liquid/tags/unless.rb
liquid-4.0.1 lib/liquid/tags/unless.rb
liquid-4.0.0 lib/liquid/tags/unless.rb
liquid-4.0.0.rc3 lib/liquid/tags/unless.rb
liquid-4.0.0.rc2 lib/liquid/tags/unless.rb
liquid-4.0.0.rc1 lib/liquid/tags/unless.rb