Sha256: 2ecfee8ee7c9bfc279837088de41766d2a2e17917db072074da8714db793863e

Contents?: true

Size: 834 Bytes

Versions: 46

Compression:

Stored size: 834 Bytes

Contents

require File.dirname(__FILE__) + '/if'

module Liquid

  # Unless is a conditional just like 'if' but works on the inverse logic.
  #
  #   {% unless x < 0 %} x is greater than zero {% end %}
  #
  class Unless < If
    def render(context)
      context.stack do
        
        # First condition is interpreted backwards ( if not )
        block = @blocks.first
        unless block.evaluate(context)
          return render_all(block.attachment, context)            
        end
        
        # After the first condition unless works just like if
        @blocks[1..-1].each do |block|
          if block.evaluate(context)            
            return render_all(block.attachment, context)            
          end
        end 
        
        ''
      end
    end    
  end
  

  Template.register_tag('unless', Unless)
end

Version data entries

46 entries across 46 versions & 10 rubygems

Version Path
jeremyf-liquid-2.0.2 lib/liquid/tags/unless.rb
qoobaa-liquid-2.0.1 lib/liquid/tags/unless.rb
tobi-liquid-2.0.1 lib/liquid/tags/unless.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/liquid-2.2.2/lib/liquid/tags/unless.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/liquid-2.2.2/lib/liquid/tags/unless.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/liquid-2.2.2/lib/liquid/tags/unless.rb
liquid_cms-0.3.2.0 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.2.0 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.1.1 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.3.1.0 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.1.0 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.0.13 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.3.0.10 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.3.0.9 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.0.12 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.0.11 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.0.10 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.3.0.8 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.2.0.9 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/unless.rb
liquid_cms-0.3.0.7 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/unless.rb