Sha256: 04864ae000aba698e3146e402eb684c66c5cabac467f427be07c9803c6b6013e

Contents?: true

Size: 1004 Bytes

Versions: 13

Compression:

Stored size: 1004 Bytes

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}+)/o

          def initialize(tag_name, markup, options)
            if markup =~ Syntax
              @to, @from = $1, $2
            else
              raise ::Liquid::SyntaxError.new("Valid syntax: session_assign [var] = [source]")
            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'.freeze, SessionAssign)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/liquid/tags/session_assign.rb