forgot to add files to the repo
did
committed Aug 19, 2013
commit 967d9f1f33ef49dbe42678a5e826c5009159f92a
Showing 4
changed files with
97 additions
and 0 deletions
locomotive/wagon/liquid/drops/session_proxy.rb b/lib/locomotive/wagon/liquid/drops/session_proxy.rb
+18
-0
| @@ | @@ -0,0 +1,18 @@ |
| + | module Locomotive |
| + | module Wagon |
| + | module Liquid |
| + | module Drops |
| + | |
| + | class SessionProxy < ::Liquid::Drop |
| + | |
| + | def before_method(meth) |
| + | request = @context.registers[:request] |
| + | request.session[meth.to_sym] |
| + | end |
| + | |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotive/wagon/liquid/tags/session_assign.rb b/lib/locomotive/wagon/liquid/tags/session_assign.rb
+41
-0
| @@ | @@ -0,0 +1,41 @@ |
| + | 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, context) |
| + | if markup =~ Syntax |
| + | @to = $1 |
| + | @from = $2 |
| + | else |
| + | raise ::Liquid::SyntaxError.new("Syntax Error in 'session_assign' - Valid syntax: 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', SessionAssign) |
| + | end |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotive/wagon/misc/mounter.rb b/lib/locomotive/wagon/misc/mounter.rb
+20
-0
| @@ | @@ -0,0 +1,20 @@ |
| + | module Locomotive |
| + | module Mounter |
| + | module Models |
| + | class Page |
| + | |
| + | def render(context) |
| + | mounting_point = context.registers[:mounting_point] |
| + | |
| + | template = ::Liquid::Template.parse(self.source, { |
| + | page: self, |
| + | mounting_point: mounting_point |
| + | }) |
| + | |
| + | template.render(context) |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
spec/fixtures/default/app/views/pages/contest.liquid.haml
+18
-0
| @@ | @@ -0,0 +1,18 @@ |
| + | --- |
| + | title: A sample contest |
| + | listed: false |
| + | --- |
| + | {% extends 'parent' %} |
| + | |
| + | {% block content %} |
| + | |
| + | %h1 Contest sample |
| + | |
| + | {% if session.already_participated %} |
| + | %p You've already participated to that contest ! Come back later. |
| + | {% else %} |
| + | %p Your code is: HELLO WORLD |
| + | {% session_assign already_participated = true %} |
| + | {% endif %} |
| + | |
| + | {% endblock %} |
| \ No newline at end of file | |