Skip to content

Commit

Permalink
IF tag
Browse files Browse the repository at this point in the history
  - now properly allows operands to have conditions (eg and, or) [closes Shopify#13]
  • Loading branch information
DBA authored and Tobias Lütke committed Aug 24, 2010
1 parent 8579807 commit 4819eb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/liquid/tags/if.rb
Expand Up @@ -14,7 +14,7 @@ module Liquid
class If < Block
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
ExpressionsAndOperators = /(?:\b(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/

def initialize(tag_name, markup, tokens)
@blocks = []
Expand Down Expand Up @@ -56,7 +56,7 @@ def push_block(tag, markup)
condition = Condition.new($1, $2, $3)

while not expressions.empty?
operator = expressions.shift
operator = (expressions.shift).to_s.strip

raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax

Expand Down
11 changes: 6 additions & 5 deletions test/lib/liquid/tags/if_else_test.rb
Expand Up @@ -151,9 +151,10 @@ def test_if_with_custom_condition
Condition.operators.delete 'contains'
end

# def test_operators_are_ignored_unless_isolated
# Condition.operators['contains'] = :[]
#
# assert_template_result('yes', %({% if 'gnomeslab' == 'gnomeslab' %}yes{% endif %}))
# end
def test_operators_are_ignored_unless_isolated
Condition.operators['contains'] = :[]

assert_template_result('yes',
%({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
end
end # IfElseTest

0 comments on commit 4819eb1

Please sign in to comment.