summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-06-20 16:59:44 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-06-20 16:59:44 +0200
commit58e3798c12dd9343855668f01a433f6dbc6a2e51 (patch)
treef98bd8525349324872c2f54c154d9a73a7a1be73 /examples
parentf8922272bbf9816dec7fe4c57002afb54d353f50 (diff)
downloadzorglub-58e3798c12dd9343855668f01a433f6dbc6a2e51.zip
zorglub-58e3798c12dd9343855668f01a433f6dbc6a2e51.tar.gz
update examples, use session
Diffstat (limited to 'examples')
-rw-r--r--examples/sample.ru22
-rw-r--r--examples/view/url1/alt.haml1
2 files changed, 22 insertions, 1 deletions
diff --git a/examples/sample.ru b/examples/sample.ru
index a7d6b16..e05aebe 100644
--- a/examples/sample.ru
+++ b/examples/sample.ru
@@ -10,6 +10,7 @@ Zorglub::Config.register_engine 'haml', 'haml', HAML_PROC
Zorglub::Config.register_engine 'temp-engine', 'haml', HAML_PROC
#
Zorglub::Config.engine = 'haml'
+Zorglub::Config.session_on = true
Zorglub::Config.root = File.dirname( File.absolute_path(__FILE__) )
#
class Node1 < Zorglub::Node
@@ -50,7 +51,20 @@ class Node2 < Zorglub::Node
engine 'temp-engine' # haml renamed
layout 'other' # use layout/other.haml template
view File.join( 'url1','alt') # use view/url1/alt.haml template
- "<title>Node2:alt</title>#{html}"
+ if not session.exists?
+ @data = "NO SESSION"
+ else
+ t = Time.now
+ if session[:now].nil?
+ session[:now] = t
+ @data = "#{t.strftime('%H:%M:%S')} FIRST"
+ elsif t-session[:now]>5
+ session[:now] = t
+ @data = "#{t.strftime('%H:%M:%S')} UPDATE"
+ else
+ @data = "#{session[:now].strftime('%H:%M:%S')} CURRENT"
+ end
+ end
end
#
end
@@ -58,7 +72,13 @@ end
puts APP.to_hash.inspect
#
map '/' do
+ use Rack::Lint
use Rack::ShowExceptions
+ use Rack::Session::Cookie, :key=>Zorglub::Session.session_key,
+ :secret=>'my-secret-secret',
+ :path=>'/',
+ :http_only=>true,
+ :expire_after=>30
run APP
end
#
diff --git a/examples/view/url1/alt.haml b/examples/view/url1/alt.haml
index ca990e4..dfd04d5 100644
--- a/examples/view/url1/alt.haml
+++ b/examples/view/url1/alt.haml
@@ -12,3 +12,4 @@
%a{:href=>Node2.r('alt')}="Node2::alt"
%p
%a{:href=>Node1.r('pour', 'voir')}="nowhere"
+%p="Time #{@data}"