Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow filters in assign.

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 #79.
  • Loading branch information...
commit 975b17b5290468fd2b69487c426c3ffb74a23ed4 1 parent 745d875
@ROFISH ROFISH authored
Showing with 9 additions and 3 deletions.
  1. +3 −3 lib/liquid/tags/assign.rb
  2. +6 −0 test/liquid/assign_test.rb
View
6 lib/liquid/tags/assign.rb
@@ -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
@@ -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
View
6 test/liquid/assign_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.