mirror of
https://github.com/kemko/liquid.git
synced 2026-01-06 18:25:41 +03:00
@@ -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 @@ module Liquid
|
||||
end
|
||||
|
||||
def render(context)
|
||||
context.scopes.last[@to] = context[@from]
|
||||
context.scopes.last[@to] = @from.render(context)
|
||||
''
|
||||
end
|
||||
|
||||
|
||||
@@ -12,4 +12,10 @@ class AssignTest < Test::Unit::TestCase
|
||||
'{% 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
|
||||
|
||||
Reference in New Issue
Block a user