mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 17:15:12 -07:00
committed by
Tobias Lütke
parent
37580976db
commit
8d27864845
@@ -87,7 +87,6 @@ module Liquid
|
||||
end
|
||||
|
||||
def interpret_condition(left, right, op, context)
|
||||
|
||||
# If the operator is empty this means that the decision statement is just
|
||||
# a single variable. We can just poll this variable from the context and
|
||||
# return this as the result.
|
||||
@@ -95,7 +94,6 @@ module Liquid
|
||||
|
||||
left, right = context[left], context[right]
|
||||
|
||||
|
||||
operation = self.class.operators[op] || raise(ArgumentError.new("Unknown operator #{op}"))
|
||||
|
||||
if operation.respond_to?(:call)
|
||||
@@ -110,7 +108,6 @@ module Liquid
|
||||
|
||||
|
||||
class ElseCondition < Condition
|
||||
|
||||
def else?
|
||||
true
|
||||
end
|
||||
|
||||
+3
-2
@@ -29,7 +29,9 @@ module Liquid
|
||||
|
||||
# called by liquid to invoke a drop
|
||||
def invoke_drop(method)
|
||||
if self.class.public_instance_methods.include?(method.to_s)
|
||||
# for backward compatibility with Ruby 1.8
|
||||
methods = self.class.public_instance_methods.map { |m| m.to_s }
|
||||
if methods.include?(method.to_s)
|
||||
send(method.to_sym)
|
||||
else
|
||||
before_method(method)
|
||||
@@ -46,5 +48,4 @@ module Liquid
|
||||
|
||||
alias :[] :invoke_drop
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+10
-11
@@ -190,9 +190,10 @@ class ContextTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
context = Context.new(@template)
|
||||
methods = context.strainer.methods
|
||||
methods_before = context.strainer.methods.map { |method| method.to_s }
|
||||
context.add_filters(filter)
|
||||
assert_equal (methods + ['hi']).sort, context.strainer.methods.sort
|
||||
methods_after = context.strainer.methods.map { |method| method.to_s }
|
||||
assert_equal (methods_before + ["hi"]).sort, methods_after.sort
|
||||
end
|
||||
|
||||
def test_add_item_in_outer_scope
|
||||
@@ -289,11 +290,9 @@ class ContextTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_access_hashes_with_hash_notation
|
||||
|
||||
@context['products'] = {'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
||||
@context['product'] = {'variants' => [ {'title' => 'draft151cm'}, {'title' => 'element151cm'} ]}
|
||||
|
||||
|
||||
assert_equal 5, @context['products["count"]']
|
||||
assert_equal 'deepsnow', @context['products["tags"][0]']
|
||||
assert_equal 'deepsnow', @context['products["tags"].first']
|
||||
@@ -417,25 +416,25 @@ class ContextTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_lambda_as_variable
|
||||
@context['dynamic'] = lambda { 'Hello' }
|
||||
@context['dynamic'] = proc { 'Hello' }
|
||||
|
||||
assert_equal 'Hello', @context['dynamic']
|
||||
end
|
||||
|
||||
def test_nested_lambda_as_variable
|
||||
@context['dynamic'] = { "lambda" => lambda { 'Hello' } }
|
||||
@context['dynamic'] = { "lambda" => proc { 'Hello' } }
|
||||
|
||||
assert_equal 'Hello', @context['dynamic.lambda']
|
||||
end
|
||||
|
||||
def test_array_containing_lambda_as_variable
|
||||
@context['dynamic'] = [1,2, lambda { 'Hello' } ,4,5]
|
||||
@context['dynamic'] = [1,2, proc { 'Hello' } ,4,5]
|
||||
|
||||
assert_equal 'Hello', @context['dynamic[2]']
|
||||
end
|
||||
|
||||
def test_lambda_is_called_once
|
||||
@context['callcount'] = lambda { @global ||= 0; @global += 1; @global.to_s }
|
||||
@context['callcount'] = proc { @global ||= 0; @global += 1; @global.to_s }
|
||||
|
||||
assert_equal '1', @context['callcount']
|
||||
assert_equal '1', @context['callcount']
|
||||
@@ -445,7 +444,7 @@ class ContextTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_nested_lambda_is_called_once
|
||||
@context['callcount'] = { "lambda" => lambda { @global ||= 0; @global += 1; @global.to_s } }
|
||||
@context['callcount'] = { "lambda" => proc { @global ||= 0; @global += 1; @global.to_s } }
|
||||
|
||||
assert_equal '1', @context['callcount.lambda']
|
||||
assert_equal '1', @context['callcount.lambda']
|
||||
@@ -455,7 +454,7 @@ class ContextTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_lambda_in_array_is_called_once
|
||||
@context['callcount'] = [1,2, lambda { @global ||= 0; @global += 1; @global.to_s } ,4,5]
|
||||
@context['callcount'] = [1,2, proc { @global ||= 0; @global += 1; @global.to_s } ,4,5]
|
||||
|
||||
assert_equal '1', @context['callcount[2]']
|
||||
assert_equal '1', @context['callcount[2]']
|
||||
@@ -467,7 +466,7 @@ class ContextTest < Test::Unit::TestCase
|
||||
def test_access_to_context_from_proc
|
||||
@context.registers[:magic] = 345392
|
||||
|
||||
@context['magic'] = lambda { @context.registers[:magic] }
|
||||
@context['magic'] = proc { @context.registers[:magic] }
|
||||
|
||||
assert_equal 345392, @context['magic']
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user