public
Description: Liquid markup language. Save, customer facing template language for flexible web apps.
Homepage: http://www.liquidmarkup.org
Clone URL: git://github.com/tobi/liquid.git
Click here to lend your support to: liquid and make a donation at www.pledgie.com !
liquid / lib / liquid / tags / assign.rb
1d647361 » tobi 2008-05-08 Initial github import of li... 1 module Liquid
2
3 # Assign sets a variable in your template.
4 #
5 # {% assign foo = 'monkey' %}
6 #
7 # You can then use the variable later in the page.
8 #
9 # {{ monkey }}
10 #
11 class Assign < Tag
edcc14f1 » tobi 2009-04-06 Reverted james filter in ta... 12 Syntax = /(#{VariableSignature}+)\s*=\s*(#{QuotedFragment}+)/
1d647361 » tobi 2008-05-08 Initial github import of li... 13
14 def initialize(tag_name, markup, tokens)
15 if markup =~ Syntax
16 @to = $1
17 @from = $2
18 else
19 raise SyntaxError.new("Syntax Error in 'assign' - Valid syntax: assign [var] = [source]")
20 end
21
22 super
23 end
24
25 def render(context)
26 context.scopes.last[@to.to_s] = context[@from]
27 ''
28 end
29
30 end
31
32 Template.register_tag('assign', Assign)
33 end