Sha256: 824181821b2100b8fdddbfbefeee409f953aade775a92ac43a2b5546bc630e16

Contents?: true

Size: 704 Bytes

Versions: 6

Compression:

Stored size: 704 Bytes

Contents

module Liquid

  # Assign sets a variable in your template.
  #
  #   {% assign foo = 'monkey' %}
  #
  # You can then use the variable later in the page.
  #
  #  {{ monkey }}
  #
  class Assign < Tag
    Syntax = /(#{VariableSignature}+)\s*=\s*(#{QuotedFragment}+)/   
  
    def initialize(tag_name, markup, tokens)          
      if markup =~ Syntax
        @to = $1
        @from = $2
      else
        raise SyntaxError.new("Syntax Error in 'assign' - Valid syntax: assign [var] = [source]")
      end
      
      super      
    end
  
    def render(context)
       context.scopes.last[@to.to_s] = context[@from]
       ''
    end 
  
  end  
  
  Template.register_tag('assign', Assign)  
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
tobi-liquid-2.0.1 lib/liquid/tags/assign.rb
liquid-2.1.2 lib/liquid/tags/assign.rb
liquid-2.1.0 lib/liquid/tags/assign.rb
agilitic-liquid-2.0.1 lib/liquid/tags/assign.rb
drnic-liquid-2.1.0 lib/liquid/tags/assign.rb
liquid-1.9.0 lib/liquid/tags/assign.rb