Sha256: 0ec0bfe61a6c3e6bede6beee74483971b57a721b4450f8902e5998b29b3de122

Contents?: true

Size: 1003 Bytes

Versions: 41

Compression:

Stored size: 1003 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

41 entries across 41 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.1.2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/liquid/tags/session_assign.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/liquid/tags/session_assign.rb