Skip to content

Commit

Permalink
Allow filters in assign.
Browse files Browse the repository at this point in the history
A simple attempt, but basically it shifts the parsing of the right hand side of the assign from a simple context lookup to using the Variable parser (that includes filters). Fixes Shopify#79.
  • Loading branch information
ROFISH committed Nov 1, 2011
1 parent 745d875 commit 975b17b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/liquid/tags/assign.rb
Expand Up @@ -9,12 +9,12 @@ module Liquid
# {{ foo }}
#
class Assign < Tag
Syntax = /(#{VariableSignature}+)\s*=\s*(#{QuotedFragment}+)/
Syntax = /(#{VariableSignature}+)\s*=\s*(.*)\s*/

def initialize(tag_name, markup, tokens)
if markup =~ Syntax
@to = $1
@from = $2
@from = Variable.new($2)
else
raise SyntaxError.new("Syntax Error in 'assign' - Valid syntax: assign [var] = [source]")
end
Expand All @@ -23,7 +23,7 @@ def initialize(tag_name, markup, tokens)
end

def render(context)
context.scopes.last[@to] = context[@from]
context.scopes.last[@to] = @from.render(context)
''
end

Expand Down
6 changes: 6 additions & 0 deletions test/liquid/assign_test.rb
Expand Up @@ -12,4 +12,10 @@ def test_assigned_variable
'{% assign foo = values %}.{{ foo[1] }}.',
'values' => %w{foo bar baz})
end

def test_assign_with_filter
assert_template_result('.bar.',
'{% assign foo = values | split: "," %}.{{ foo[1] }}.',
'values' => "foo,bar,baz")
end
end # AssignTest

0 comments on commit 975b17b

Please sign in to comment.