trellis 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,9 @@
1
+ == 0.0.6
2
+ * 2 major enhancement:
3
+ * added dup.call for thread safety
4
+ * added ability to select Rack::Session middleware implementation
5
+ between cookie, pool and memcached
6
+
1
7
  == 0.0.5
2
8
  * 2 major enhancements:
3
9
  * template can now use erb (erubis using Processing Instructions (PI))
@@ -84,6 +84,7 @@ examples/hilo/html/guess.xhtml
84
84
  examples/hilo/html/start.xhtml
85
85
  examples/hilo/source/hilo.rb
86
86
  examples/routing/source/routing.rb
87
+ examples/sessions/source/sessions.rb
87
88
  examples/simplest/source/simplest.rb
88
89
  examples/stateful_counters/html/counters.xhtml
89
90
  examples/stateful_counters/html/style/main.css
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'trellis'
3
+
4
+ include Trellis
5
+
6
+ module Sessions
7
+
8
+ class Sessions < Application
9
+ home :start
10
+
11
+ session :pool, { :key => 'rack.session', :path => '/', :expire_after => 2592000 }
12
+ end
13
+
14
+ class Start < Page
15
+ persistent :results
16
+
17
+ def on_select
18
+ logger.info "processing on_select"
19
+ @results = rand(9)
20
+ self
21
+ end
22
+
23
+ template do # using Markaby
24
+ xhtml_strict {
25
+ head { title "Simplest Trellis Application" }
26
+ body {
27
+ h1 "Persistent Fields via Session"
28
+ p "This application uses Rack::Session::Pool for in-memory, cookie backed HTTP sessions"
29
+ p {
30
+ text "The value is: "
31
+ text %[<trellis:value name="results">${results}.</trellis:value>]
32
+ }
33
+ p {
34
+ text %[[<trellis:action_link>Click Me</trellis:action_link>]]
35
+ }
36
+ }
37
+ }
38
+ end
39
+ end
40
+
41
+ Sessions.new.start 3012 if __FILE__ == $PROGRAM_NAME
42
+ end
@@ -40,6 +40,7 @@ require 'bluecloth'
40
40
  require 'facets'
41
41
  require 'directory_watcher'
42
42
  require 'erubis'
43
+ require 'ostruct'
43
44
 
44
45
  module Trellis
45
46
 
@@ -54,8 +55,10 @@ module Trellis
54
55
  # holding homepage, dependent pages, static resource routing paths
55
56
  def self.inherited(child) #:nodoc:
56
57
  child.class_attr_reader(:homepage)
58
+ child.class_attr_reader(:session_config)
57
59
  child.attr_array(:static_routes)
58
60
  child.meta_def(:logger) { Application.logger }
61
+ child.instance_variable_set(:@session_config, OpenStruct.new({:impl => :cookie}))
59
62
  super
60
63
  end
61
64
 
@@ -63,6 +66,10 @@ module Trellis
63
66
  # the entry point is the URL pattern / where the application is mounted
64
67
  def self.home(sym)
65
68
  @homepage = sym
69
+ end
70
+
71
+ def self.session(sym, options={})
72
+ @session_config = OpenStruct.new({:impl => sym, :options => options})
66
73
  end
67
74
 
68
75
  # define url paths for static resources
@@ -77,7 +84,7 @@ module Trellis
77
84
  directory_watcher = configure_directory_watcher
78
85
  directory_watcher.start
79
86
 
80
- Rack::Handler::Mongrel.run configured_instance, :Port => port do |server|
87
+ Rack::Handler::Mongrel.run configured, :Port => port do |server|
81
88
  trap(:INT) do
82
89
  Application.logger.info "Exiting Trellis Application #{self.class}"
83
90
  directory_watcher.stop
@@ -88,13 +95,23 @@ module Trellis
88
95
  Application.logger.warn "#{ e } (#{ e.class })!"
89
96
  end
90
97
 
91
- def configured_instance
98
+ def configured
92
99
  # configure rack middleware
93
100
  application = Rack::ShowStatus.new(self)
94
101
  application = Rack::ShowExceptions.new(application)
95
102
  application = Rack::Reloader.new(application)
96
103
  application = Rack::CommonLogger.new(application, Application.logger)
97
- application = Rack::Session::Cookie.new(application)
104
+
105
+ # configure rack session
106
+ session_config = self.class.session_config
107
+ case session_config.impl
108
+ when :pool
109
+ application = Rack::Session::Pool.new(application, session_config.options)
110
+ when :memcached
111
+ application = Rack::Session::Memcache.new(application, session_config.options)
112
+ else
113
+ application = Rack::Session::Cookie.new(application)
114
+ end
98
115
 
99
116
  # set all static resource paths
100
117
  self.class.static_routes.each do |path|
@@ -109,8 +126,13 @@ module Trellis
109
126
  match ? match.router : DefaultRouter.new(:application => self)
110
127
  end
111
128
 
112
- # implements the rack specification
129
+ # Rack call interface.
113
130
  def call(env)
131
+ dup.call!(env)
132
+ end
133
+
134
+ # implements the rack specification
135
+ def call!(env)
114
136
  response = Rack::Response.new
115
137
  request = Rack::Request.new(env)
116
138
 
@@ -654,7 +676,6 @@ module Trellis
654
676
  unless @page.class.format == :eruby
655
677
  @parser.parse(@page.class.parsed_template.to_html)
656
678
  else
657
- puts "eruby context is #{@eruby_context}"
658
679
  preprocessed = Erubis::PI::Eruby.new(@page.class.parsed_template.to_html, :trim => false).evaluate(@eruby_context)
659
680
  @parser.parse(preprocessed)
660
681
  end
@@ -28,7 +28,7 @@ module Trellis
28
28
  module VERSION #:nodoc:
29
29
  MAJOR = 0
30
30
  MINOR = 0
31
- TINY = 5
31
+ TINY = 6
32
32
 
33
33
  STRING = [MAJOR, MINOR, TINY].join('.')
34
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trellis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Sam-Bodden
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-08 00:00:00 -07:00
12
+ date: 2009-11-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -313,6 +313,7 @@ files:
313
313
  - examples/hilo/html/start.xhtml
314
314
  - examples/hilo/source/hilo.rb
315
315
  - examples/routing/source/routing.rb
316
+ - examples/sessions/source/sessions.rb
316
317
  - examples/simplest/source/simplest.rb
317
318
  - examples/stateful_counters/html/counters.xhtml
318
319
  - examples/stateful_counters/html/style/main.css