Sha256: 8f17342967b7820238aa338e605f7545efd1c9301b4cafc0982108efe717c070

Contents?: true

Size: 697 Bytes

Versions: 37

Compression:

Stored size: 697 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*(#{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] = context[@from]
       ''
    end 
  
  end  
  
  Template.register_tag('assign', Assign)  
end

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/liquid-2.2.2/lib/liquid/tags/assign.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/liquid-2.2.2/lib/liquid/tags/assign.rb
liquid-2.3.0 lib/liquid/tags/assign.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/liquid-2.2.2/lib/liquid/tags/assign.rb
liquid_cms-0.3.2.0 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.2.0 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.1.1 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.3.1.0 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.1.0 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.0.13 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.3.0.10 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.3.0.9 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.0.12 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.0.11 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.0.10 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.3.0.8 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.0.9 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.3.0.7 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.3.0.6 lib/generators/liquid_cms/templates/vendor/plugins/liquid/lib/liquid/tags/assign.rb
liquid_cms-0.2.0.8 generators/liquid_cms/templates/vendor/plugins/cms_plugins/liquid/lib/liquid/tags/assign.rb