Sha256: 234bb9392d027871468e41c57ad3e1ed8e70f8a1e184c1b0720e40fa2ce065d8

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

module Locomotive
  module Steam
    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

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms_steam-0.1.2.pre.beta lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-0.1.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-0.1.0 lib/locomotive/steam/liquid/tags/session_assign.rb