Sha256: 27a620bf65ce44ff92809a1ec555e09cbc76cd8d0fcb62ebf542e911ca13208e

Contents?: true

Size: 703 Bytes

Versions: 8

Compression:

Stored size: 703 Bytes

Contents

module Liquid

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
liquid-2.5.5 lib/liquid/tags/assign.rb
liquid-2.5.4 lib/liquid/tags/assign.rb
liquid-2.5.3 lib/liquid/tags/assign.rb
liquid-2.5.1 lib/liquid/tags/assign.rb
wordify_liquid-2.5.1 lib/liquid/tags/assign.rb
liquid-2.5.0 lib/liquid/tags/assign.rb
liquid-2.4.1 lib/liquid/tags/assign.rb
liquid-2.4.0 lib/liquid/tags/assign.rb