Sha256: 8843dd0b4c56c25aed4d402b65be0a021280ed7b9f5bea4a15a81af3fce44e57

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

module Locomotive
  module Wagon
    module Liquid
      module Tags

        # Assign sets a variable in your session.
        #
        #   {% session_assign foo = 'monkey' %}
        #
        # You can then use the variable later in the page.
        #
        #   {{ session.foo }}
        #
        class SessionAssign < ::Liquid::Tag
          Syntax = /(#{::Liquid::VariableSignature}+)\s*=\s*(#{::Liquid::QuotedFragment}+)/

          def initialize(tag_name, markup, tokens, options)
            if markup =~ Syntax
              @to = $1
              @from = $2
            else
              raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.session_assign"), options[:line])
            end

            super
          end

          def render(context)
            request = context.registers[:request]

            request.session[@to.to_sym] = context[@from]
            ''
          end

        end

        ::Liquid::Template.register_tag('session_assign', SessionAssign)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.5.8 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.7 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.6 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.5 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.4 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.3 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.2 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.1 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.0 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.5.0.rc1 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.4.0 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.3.3 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.3.2 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.3.1 lib/locomotive/wagon/liquid/tags/session_assign.rb
locomotivecms_wagon-1.3.0 lib/locomotive/wagon/liquid/tags/session_assign.rb