ramaze 0.0.7 → 0.0.8

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.
Files changed (193) hide show
  1. data/Rakefile +52 -19
  2. data/bin/ramaze +19 -6
  3. data/doc/CHANGELOG +33 -0
  4. data/doc/COPYING +1 -1
  5. data/doc/FAQ +92 -0
  6. data/doc/GPL +340 -0
  7. data/doc/INSTALL +34 -0
  8. data/doc/ProjectInfo +53 -0
  9. data/doc/README +187 -110
  10. data/doc/readme_chunks/appendix.txt +13 -0
  11. data/doc/readme_chunks/examples.txt +38 -0
  12. data/doc/readme_chunks/features.txt +82 -0
  13. data/doc/readme_chunks/getting_help.txt +5 -0
  14. data/doc/readme_chunks/getting_started.txt +18 -0
  15. data/doc/readme_chunks/installing.txt +41 -0
  16. data/doc/readme_chunks/introduction.txt +18 -0
  17. data/doc/readme_chunks/principles.txt +41 -0
  18. data/doc/readme_chunks/thanks.txt +59 -0
  19. data/doc/tutorial/todolist.txt +546 -0
  20. data/examples/blog/main.rb +1 -1
  21. data/examples/blog/src/controller.rb +13 -11
  22. data/examples/blog/src/element.rb +11 -6
  23. data/examples/blog/src/model.rb +8 -23
  24. data/examples/blog/template/edit.xhtml +3 -1
  25. data/examples/blog/template/index.xhtml +4 -4
  26. data/examples/caching.rb +4 -4
  27. data/examples/element.rb +10 -7
  28. data/examples/hello.rb +3 -4
  29. data/examples/simple.rb +5 -3
  30. data/examples/templates/template/external.amrita +19 -0
  31. data/examples/templates/template/{external.rmze → external.zmr} +2 -2
  32. data/examples/templates/template_amrita2.rb +48 -0
  33. data/examples/templates/template_erubis.rb +5 -2
  34. data/examples/templates/{template_ramaze.rb → template_ezamar.rb} +13 -7
  35. data/examples/templates/template_haml.rb +4 -1
  36. data/examples/templates/template_liquid.rb +2 -1
  37. data/examples/templates/template_markaby.rb +2 -1
  38. data/examples/todolist/conf/benchmark.yaml +35 -0
  39. data/examples/todolist/conf/debug.yaml +34 -0
  40. data/examples/todolist/conf/live.yaml +33 -0
  41. data/examples/todolist/conf/silent.yaml +31 -0
  42. data/examples/todolist/conf/stage.yaml +33 -0
  43. data/examples/todolist/main.rb +18 -0
  44. data/examples/todolist/public/404.jpg +0 -0
  45. data/examples/todolist/public/css/coderay.css +105 -0
  46. data/examples/todolist/public/css/ramaze_error.css +42 -0
  47. data/{lib/proto → examples/todolist}/public/error.xhtml +0 -0
  48. data/examples/todolist/public/favicon.ico +0 -0
  49. data/examples/todolist/public/js/jquery.js +1923 -0
  50. data/examples/todolist/public/ramaze.png +0 -0
  51. data/examples/todolist/src/controller/main.rb +56 -0
  52. data/examples/todolist/src/element/page.rb +26 -0
  53. data/examples/todolist/src/model.rb +14 -0
  54. data/examples/todolist/template/index.xhtml +17 -0
  55. data/examples/todolist/template/new.xhtml +7 -0
  56. data/examples/todolist/todolist.db +9 -0
  57. data/examples/whywiki/main.rb +3 -8
  58. data/examples/whywiki/template/show.xhtml +4 -0
  59. data/lib/proto/public/error.zmr +77 -0
  60. data/lib/proto/src/controller/main.rb +2 -1
  61. data/lib/proto/src/element/page.rb +2 -1
  62. data/lib/proto/src/model.rb +3 -2
  63. data/lib/ramaze.rb +7 -9
  64. data/lib/ramaze/adapter.rb +51 -0
  65. data/lib/ramaze/adapter/cgi.rb +23 -0
  66. data/lib/ramaze/adapter/fcgi.rb +22 -0
  67. data/lib/ramaze/adapter/mongrel.rb +7 -86
  68. data/lib/ramaze/adapter/webrick.rb +14 -133
  69. data/lib/ramaze/cache/memcached.rb +6 -0
  70. data/lib/ramaze/cache/yaml_store.rb +3 -1
  71. data/lib/ramaze/controller.rb +292 -2
  72. data/lib/ramaze/dispatcher.rb +85 -213
  73. data/lib/ramaze/error.rb +10 -0
  74. data/lib/ramaze/global.rb +8 -0
  75. data/lib/ramaze/helper/aspect.rb +30 -7
  76. data/lib/ramaze/helper/auth.rb +16 -9
  77. data/lib/ramaze/helper/cache.rb +40 -35
  78. data/lib/ramaze/helper/feed.rb +1 -1
  79. data/lib/ramaze/helper/flash.rb +34 -0
  80. data/lib/ramaze/helper/link.rb +8 -2
  81. data/lib/ramaze/helper/openid.rb +63 -0
  82. data/lib/ramaze/helper/redirect.rb +12 -11
  83. data/lib/ramaze/helper/stack.rb +5 -7
  84. data/lib/ramaze/inform.rb +12 -1
  85. data/lib/ramaze/snippets/kernel/aquire.rb +1 -1
  86. data/lib/ramaze/snippets/kernel/{self_method.rb → method.rb} +3 -18
  87. data/lib/ramaze/snippets/kernel/{rescue_require.rb → pretty_inspect.rb} +7 -6
  88. data/lib/ramaze/snippets/method/name.rb +22 -0
  89. data/lib/ramaze/snippets/{kernel → ramaze}/autoreload.rb +0 -0
  90. data/lib/ramaze/snippets/ramaze/caller_info.rb +14 -0
  91. data/lib/ramaze/snippets/{kernel → ramaze}/caller_lines.rb +3 -10
  92. data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +49 -23
  93. data/lib/ramaze/snippets/string/DIVIDE.rb +0 -1
  94. data/lib/ramaze/store/default.rb +58 -2
  95. data/lib/ramaze/store/yaml.rb +161 -0
  96. data/lib/ramaze/template.rb +27 -86
  97. data/lib/ramaze/template/amrita2.rb +14 -19
  98. data/lib/ramaze/template/erubis.rb +15 -38
  99. data/lib/ramaze/template/ezamar.rb +100 -0
  100. data/lib/ramaze/template/ezamar/element.rb +166 -0
  101. data/lib/ramaze/template/ezamar/engine.rb +124 -0
  102. data/lib/ramaze/template/ezamar/morpher.rb +155 -0
  103. data/lib/ramaze/template/haml.rb +16 -43
  104. data/lib/ramaze/template/liquid.rb +11 -51
  105. data/lib/ramaze/template/markaby.rb +44 -42
  106. data/lib/ramaze/tool/mime.rb +18 -0
  107. data/lib/ramaze/tool/mime_types.yaml +615 -0
  108. data/lib/ramaze/trinity/request.rb +20 -196
  109. data/lib/ramaze/trinity/response.rb +4 -33
  110. data/lib/ramaze/trinity/session.rb +150 -72
  111. data/lib/ramaze/version.rb +1 -1
  112. data/spec/adapter_spec.rb +20 -0
  113. data/spec/public/favicon.ico +0 -0
  114. data/spec/public/ramaze.png +0 -0
  115. data/spec/public/test_download.css +141 -0
  116. data/spec/{tc_request.rb → request_tc_helper.rb} +45 -21
  117. data/spec/spec_all.rb +77 -34
  118. data/spec/spec_helper.rb +8 -157
  119. data/spec/spec_helper_context.rb +72 -0
  120. data/spec/spec_helper_requester.rb +52 -0
  121. data/spec/spec_helper_simple_http.rb +433 -0
  122. data/spec/tc_adapter_mongrel.rb +3 -15
  123. data/spec/tc_adapter_webrick.rb +4 -14
  124. data/spec/tc_cache.rb +3 -5
  125. data/spec/tc_controller.rb +22 -12
  126. data/spec/tc_dependencies.rb +13 -0
  127. data/spec/tc_element.rb +8 -7
  128. data/spec/tc_error.rb +13 -7
  129. data/spec/tc_global.rb +16 -18
  130. data/spec/tc_helper_aspect.rb +2 -4
  131. data/spec/tc_helper_auth.rb +15 -14
  132. data/spec/tc_helper_cache.rb +5 -7
  133. data/spec/tc_helper_feed.rb +0 -2
  134. data/spec/tc_helper_flash.rb +103 -0
  135. data/spec/tc_helper_form.rb +4 -6
  136. data/spec/tc_helper_link.rb +1 -3
  137. data/spec/tc_helper_redirect.rb +23 -8
  138. data/spec/tc_helper_stack.rb +31 -15
  139. data/spec/tc_morpher.rb +1 -3
  140. data/spec/tc_params.rb +48 -7
  141. data/spec/tc_request_mongrel.rb +9 -0
  142. data/spec/tc_request_webrick.rb +5 -0
  143. data/spec/tc_session.rb +41 -25
  144. data/spec/tc_store.rb +55 -6
  145. data/spec/tc_store_yaml.rb +71 -0
  146. data/spec/tc_template_amrita2.rb +3 -3
  147. data/spec/tc_template_erubis.rb +2 -3
  148. data/spec/{tc_template_ramaze.rb → tc_template_ezamar.rb} +15 -5
  149. data/spec/tc_template_haml.rb +4 -3
  150. data/spec/tc_template_liquid.rb +3 -4
  151. data/spec/tc_template_markaby.rb +4 -6
  152. data/spec/tc_tidy.rb +1 -3
  153. data/spec/template/amrita2/{data.html → data.amrita} +0 -0
  154. data/spec/template/amrita2/{index.html → index.amrita} +0 -0
  155. data/spec/template/amrita2/{sum.html → sum.amrita} +0 -0
  156. data/spec/template/ezamar/another/long/action.zmr +1 -0
  157. data/spec/template/ezamar/combined.zmr +1 -0
  158. data/spec/template/{ramaze/file_only.rmze → ezamar/file_only.zmr} +0 -0
  159. data/spec/template/{ramaze/index.rmze → ezamar/index.zmr} +0 -0
  160. data/spec/template/{ramaze/nested.rmze → ezamar/nested.zmr} +0 -0
  161. data/spec/template/ezamar/some__long__action.zmr +1 -0
  162. data/spec/template/{ramaze/sum.rmze → ezamar/sum.zmr} +0 -0
  163. metadata +181 -123
  164. data/doc/allison/LICENSE +0 -184
  165. data/doc/allison/README +0 -37
  166. data/doc/allison/allison.css +0 -300
  167. data/doc/allison/allison.gif +0 -0
  168. data/doc/allison/allison.js +0 -307
  169. data/doc/allison/allison.rb +0 -287
  170. data/doc/allison/cache/BODY +0 -588
  171. data/doc/allison/cache/CLASS_INDEX +0 -4
  172. data/doc/allison/cache/CLASS_PAGE +0 -1
  173. data/doc/allison/cache/FILE_INDEX +0 -4
  174. data/doc/allison/cache/FILE_PAGE +0 -1
  175. data/doc/allison/cache/FONTS +0 -1
  176. data/doc/allison/cache/FR_INDEX_BODY +0 -1
  177. data/doc/allison/cache/IMGPATH +0 -1
  178. data/doc/allison/cache/INDEX +0 -1
  179. data/doc/allison/cache/JAVASCRIPT +0 -307
  180. data/doc/allison/cache/METHOD_INDEX +0 -4
  181. data/doc/allison/cache/METHOD_LIST +0 -1
  182. data/doc/allison/cache/SRC_PAGE +0 -1
  183. data/doc/allison/cache/STYLE +0 -322
  184. data/doc/allison/cache/URL +0 -1
  185. data/doc/changes.txt +0 -2021
  186. data/doc/changes.xml +0 -2024
  187. data/lib/ramaze/snippets/kernel/silently.rb +0 -13
  188. data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +0 -11
  189. data/lib/ramaze/template/haml/actionview_stub.rb +0 -20
  190. data/lib/ramaze/template/ramaze.rb +0 -177
  191. data/lib/ramaze/template/ramaze/element.rb +0 -166
  192. data/lib/ramaze/template/ramaze/morpher.rb +0 -156
  193. data/spec/tc_test.rb +0 -17
@@ -2,6 +2,7 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  require 'timeout'
5
+ require 'ramaze/tool/mime'
5
6
 
6
7
  module Ramaze
7
8
 
@@ -15,21 +16,30 @@ module Ramaze
15
16
  # find any examples of how this is done exactly yet.
16
17
 
17
18
  module Dispatcher
19
+ trait :filters => [
20
+ lambda{|path| handle_file path },
21
+ lambda{|path| handle_action path },
22
+ ]
23
+
24
+ trait :handle_error => {
25
+ Exception => '/error',
26
+ Ramaze::Error::NoAction => '/error',
27
+ }
28
+
18
29
  class << self
19
30
  include Trinity
20
31
 
21
32
  # handle a request/response pair as given by the adapter.
22
33
  # has to answer with a response.
23
34
  #
24
- # It is built so it will catch _all_ errors and exceptions
35
+ # It is built so it will rescue _all_ errors and exceptions
25
36
  # thrown during processing of the request and #handle_error if
26
37
  # a problem occurs.
27
38
 
28
- def handle orig_request, orig_response
29
- @orig_request, @orig_response = orig_request, orig_response
30
- respond(orig_response, orig_request)
39
+ def handle rack_request, rack_response
40
+ setup_environment rack_request, rack_response
41
+ respond
31
42
  rescue Object => exception
32
- error(exception)
33
43
  handle_error(exception)
34
44
  end
35
45
 
@@ -53,249 +63,111 @@ module Ramaze
53
63
  # anyway, the solution might be simple?
54
64
 
55
65
  def handle_error exception
56
- meth_debug :handle_error, exception
66
+ Informer.error exception
67
+ Informer.meth_debug :handle_error, exception
57
68
  Thread.current[:exception] = exception
58
69
 
70
+ handle_error = trait[:handle_error]
71
+
59
72
  case exception
60
- when nil #Error::NoAction, Error::NoController
61
- build_response(exception.message, STATUS_CODE[:not_found])
73
+ when *handle_error.keys
74
+ error_path = handle_error[exception.class]
75
+ error_path ||= handle_error.find{|k,v| k === exception}.last
76
+
77
+ request.path_info = error_path
78
+ respond
62
79
  else
63
80
  if Global.error_page
64
- req = Thread.current[:request]
65
-
66
- unless ((req.request_uri.path = '/error') rescue false)
67
- req.request.params['REQUEST_PATH'] = '/error'
68
- end
69
-
70
- fill_out
81
+ request.path_info = '/error'
82
+ respond
71
83
  else
72
84
  build_response(exception.message, STATUS_CODE[:internal_server_error])
73
85
  end
74
86
  end
75
- end
76
-
77
- # setup the #setup_environment (Trinity) and start #fill_out
78
-
79
- def respond orig_response, orig_request
80
- setup_environment orig_response, orig_request
81
- fill_out
82
- end
83
-
84
- #
85
-
86
- def build_response out = '', code = STATUS_CODE[:internal_server_error], head = {}
87
- default_head = {
88
- 'Content-Type' => 'text/plain',
89
- }
90
-
91
- if Global.cookies
92
- default_head['Set-Cookie'] = session.export
93
- else
94
- head.delete('Set-Cookie')
95
- end
96
-
97
- head = default_head.merge(head)
98
87
 
99
- Response.new(out, code, head)
88
+ respond
89
+ rescue Object => ex
90
+ Informer.error ex
91
+ build_response(ex.message, STATUS_CODE[:internal_server_error])
100
92
  end
101
93
 
102
-
103
94
  # Obtain the path requested from the request and search for a static
104
95
  # file matching the request, #respond_file is called if it finds one,
105
96
  # otherwise the path is given on to #respond_action.
106
97
  # Answers with a response
107
98
 
108
- def fill_out
109
- path = request.request_path.squeeze('/')
110
- info "Request from #{request.remote_addr}: #{path}"
111
-
112
- the_paths = $:.map{|way| (way/'public'/path) }
113
- if file = the_paths.find{|way| File.exist?(way) and File.file?(way)}
114
- respond_file file
115
- else
116
- respond_action path
117
- end
118
- response
119
- end
120
-
121
- # takes a file and sets the response.out to the contents of the file
122
- # If you are running mongrel as your adapter it will take advantage of
123
- # mongrels #send_file
124
-
125
- def respond_file file
126
- debug "Responding with static file: #{file}"
99
+ def respond
100
+ path = request.path_info.squeeze('/')
101
+ Informer.info "Request from #{request.remote_addr}: #{path}"
127
102
 
128
- response.head['Content-Type'] = ''
129
- if @orig_response.respond_to?(:send_file)
130
- @orig_response.send_file(file)
131
- else
132
- response.out = File.read(file)
133
- end
134
- end
135
-
136
- # Takes the path, figures out the controller by asking #resolve_controller
137
- # for the controller, action and params for the path.
138
- #
139
- # Sets the cookies in the response.head if Global.cookies is set
140
- #
141
- # finally it runs #handle_controller
142
-
143
- def respond_action path
144
- debug "Responding with action: #{path}"
103
+ catch(:respond) do
104
+ redirection = catch(:redirect) do
105
+ filtered = [filter(path)].flatten.first
106
+ throw(:respond, build_response(filtered, response.status))
107
+ end
145
108
 
146
- controller, action, params = resolve_controller(path)
147
- catch :respond do
148
- response.out = handle_controller(controller, action, params)
109
+ body, status, head = redirection.values_at(:body, :status, :head)
110
+ Informer.info("Redirect to `#{head['Location']}'")
111
+ throw(:respond, build_response(body, status, head))
149
112
  end
150
113
  end
151
114
 
152
- # find out which controller should be used based on the path.
153
- # it will answer [controller, action, params] or raise an
154
- #
155
- # Ramaze::Error::NoController # if no controller is found
156
- # Ramaze::Error::NoAction # if no action but a controller is found
157
- #
158
- # It actually uses #resolve_action on almost every combination of
159
- # so-called paractions (yet unsplit but possible combination of action
160
- # and parameters for the action)
161
- #
162
- # If your templating is action-less, which means it does not depend on
163
- # methods on the controller, but rather on templates or just dynamically
164
- # calculated stuff you can set trait[:actionless] for your templating.
165
- #
166
- # Please see the documentation for Ramaze::Template::Amrita2 for an more
167
- # specific example of how it is used in practice.
168
- #
169
- # Further it uses the Global.mapping to look up the controller to be used.
170
- #
171
- # Also, the action '/' will be expanded to 'index'
172
- #
173
- # Parameters are CGI.unescaped
174
-
175
- def resolve_controller path
176
- meth_debug :resolve_controller, path
177
- track = path.split('/')
178
- controller = false
179
- action = false
180
- tracks = []
181
-
182
- track.unshift '/'
115
+ def filter path
116
+ last_error = $!
117
+ ancestral_trait[:filters].each do |filter|
118
+ filtered = run_filter(filter, path)
183
119
 
184
- track.each do |atom|
185
- tracks << (tracks.last.to_s / atom)
120
+ next unless filtered
121
+ return filtered unless filtered.is_a?(Exception)
122
+ last_error = filtered
186
123
  end
187
124
 
188
- until controller and action or tracks.empty?
189
- current = Regexp.escape(tracks.pop.to_s)
190
- paraction = path.gsub(/^#{current}/, '').split('/').map{|e| CGI.unescape(e)}
191
- paraction.delete('')
192
- if controller = Ramaze::Global.mapping[current]
193
- if controller.ancestral_trait[:actionless] or paraction == ['error']
194
-
195
- action = paraction.shift
196
- params = paraction
197
- action = 'index' if action == nil
198
- else
199
- action, params = resolve_action controller, paraction
200
- end
201
- end
202
- end
203
-
204
- raise Ramaze::Error::NoController, "No Controller found for #{path}" unless controller
205
- raise Ramaze::Error::NoAction, "No Action found for #{path}" unless action
206
-
207
- return controller, action, params
125
+ throw(:respond, handle_error(last_error))
208
126
  end
209
127
 
210
- # Resolve the method to be called and the number of parameters
211
- # it will receive for a specific class (the controller) given the
212
- # paraction (like 'foo/bar' => controller.call('foo', 'bar'))
213
- # in case arity is 1 and a public instance-method named foo is defined.
214
- #
215
- # TODO:
216
- # - find a solution for def x(a = :a) which has arity -1
217
- # identical to def x(*a) for some odd reason
218
-
219
- def resolve_action controller, paraction
220
- meth_debug :resolve_action, controller, paraction
221
-
222
- meths =
223
- (controller.ancestors - [Kernel, Object]).inject([]) do |sum, klass|
224
- sum | (klass.is_a?(Module) ? klass.instance_methods(false) : sum)
225
- end
226
-
227
- track = paraction.dup
228
- tracks = []
229
- action = false
128
+ def run_filter filter, path
129
+ filter[path]
130
+ rescue Object => ex
131
+ ex
132
+ end
230
133
 
231
- track.each do |atom|
232
- atom = [tracks.last.to_s, atom]
233
- atom.delete('')
234
- tracks << atom.join('__')
235
- end
134
+ def handle_action path
135
+ handler = Controller.handle(path)
136
+ end
236
137
 
237
- tracks.unshift 'index'
238
-
239
- until action or tracks.empty?
240
- current = tracks.pop
241
- if meths.include?(current)
242
- arity = controller.instance_method(current).arity
243
- params = (paraction - current.split('__'))
244
-
245
- if params.size == arity
246
- return current, params
247
- elsif arity < 0 and arity + params.size >= 0
248
- return current, params
249
- elsif arity == -1
250
- return current, params
251
- end
252
- end
138
+ def handle_file path
139
+ custom_publics = Global.controllers.map{|c| c.trait[:public]}.compact
140
+ the_paths = $:.map{|way| (way/'public'/path) }
141
+ the_paths << (BASEDIR/'proto'/'public'/path)
142
+ the_paths += custom_publics.map{|c| c/path }
143
+ file = the_paths.find{|way| File.file?(way)}
144
+
145
+ if file
146
+ response['Content-Type'] = Tool::MIME.type_for(file)
147
+ Informer.debug("Serving static: #{file}")
148
+ File.open(file)
253
149
  end
254
150
  end
255
151
 
256
- # Depending on Global.cache_all and Global.cache_actions it will
257
- # call either #handle_uncached_controller or #handle_cached_controller
258
- # takes the controller, action and params and just passes them on.
152
+ # takes the content, code and head for a new response, will set the cookies
153
+ # if Global.cookies is true (which it is by default) and set the default
154
+ # Content-Type to 'text/plain'
259
155
 
260
- def handle_controller controller, action, params
261
- if Global.cache_all or Global.cache_actions[controller].include?(action.to_s)
262
- handle_cached_controller(controller, action, *params)
263
- else
264
- handle_uncached_controller(controller, action, *params)
156
+ def build_response body = '', status = STATUS_CODE[:internal_server_error], head = {}
157
+ set_cookie if Global.cookies
158
+ head.each do |key, value|
159
+ response[key] = value
265
160
  end
266
- end
267
161
 
268
- # Call the class-method handle_request with action and *params, all
269
- # the controller has to do is to respond with a string.
162
+ response.body, response.status = body, status
270
163
 
271
- def handle_uncached_controller controller, action, *params
272
- controller.handle_request(action, *params)
164
+ return response
273
165
  end
274
166
 
275
- # Call the class-method handle_request with action and *params, all
276
- # the controller has to do is to respond with a string.
277
- #
278
- # To add a method for caching you can either use the CacheHelper
279
- # or directly
280
- # Global.cache_actions[self] << 'index'
281
- #
282
- # Caching is done for [action, params] pairs per controller.
283
-
284
- def handle_cached_controller controller, action, *params
285
- Global.cached_actions ||= Global.cache.new
286
-
287
- key = [action, params].inspect
288
-
289
- Global.cached_actions[controller] ||= {key => nil}
290
-
291
- if out = Global.cached_actions[controller][key]
292
- debug "Using Cached version for #{key.inspect}"
293
- return out
294
- end
295
-
296
- debug "Compiling Action: #{action} #{params.join(', ')}"
297
- Global.cached_actions[controller][key] =
298
- handle_uncached_controller(controller, action, *params)
167
+ def set_cookie
168
+ session.finalize
169
+ hash = {:value => session.session_id, :path => '/'}
170
+ response.set_cookie(Session::SESSION_KEY, hash)
299
171
  end
300
172
 
301
173
  # Setup the Trinity (Request, Response, Session) and store them as
@@ -304,11 +176,11 @@ module Ramaze
304
176
  # Thread.current[:response] == Response.current
305
177
  # Thread.current[:session] == Session.current
306
178
 
307
- def setup_environment orig_response, orig_request
179
+ def setup_environment rack_request, rack_response
308
180
  this = Thread.current
309
- this[:request] = Request.new(orig_request)
181
+ this[:request] = Request.new(rack_request)
310
182
  this[:session] = Session.new(request)
311
- this[:response] = build_response('', STATUS_CODE[:ok], 'Content-Type' => 'text/html')
183
+ this[:response] = rack_response
312
184
  end
313
185
  end
314
186
  end
@@ -2,10 +2,20 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
+
6
+ # The general Namespace for Ramazes Errorclasses
7
+
5
8
  module Error
9
+ # No action found on Controller
6
10
  class NoAction < StandardError; end
11
+
12
+ # No Controller found for request
7
13
  class NoController < StandardError; end
14
+
15
+ # Wrong parameter count for action
8
16
  class WrongParameterCount < StandardError; end
17
+
18
+ # Error while transformation in template
9
19
  class Template < StandardError; end
10
20
  end
11
21
  end
@@ -113,6 +113,14 @@ module Ramaze
113
113
  yield(e)
114
114
  end
115
115
  end
116
+
117
+ def inspect
118
+ table.inspect
119
+ end
120
+
121
+ def pretty_inspect
122
+ table.pretty_inspect
123
+ end
116
124
  end
117
125
 
118
126
  Thread.current[:global] = GlobalStruct.new(GlobalStruct::DEFAULT)
@@ -2,10 +2,13 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
+
5
6
  # A helper that provides the means to wrap actions of the controller with
6
7
  # other methods.
8
+ #
7
9
  # For examples please look at the test/tc_aspect.rb
8
- # this is not a default helper due to the possible performance-issues.
10
+ #
11
+ # This is not a default helper due to the possible performance-issues.
9
12
  # However, it should be only an overhead of about 6-8 calls, so if you
10
13
  # want this feature it shouldn't have too large impact ;)
11
14
 
@@ -19,12 +22,28 @@ module Ramaze
19
22
  unless defined?(Traits[klass][:aspects]) and Traits[klass][:aspects]
20
23
  Traits[klass] = {:aspects => {:pre => {}, :post => {}, :wrap => {}}}
21
24
  unless defined?(klass.old_render)
22
- klass.send(:alias_method, :old_render, :render)
23
- klass.send(:alias_method, :render, :new_render)
25
+ klass.class_eval do
26
+ class << self
27
+ include AspectHelperMixin
28
+ alias_method :old_render, :render
29
+ alias_method :render, :new_render
30
+
31
+ public :render
32
+ end
33
+ end
24
34
  end
25
35
  end
26
36
  end
37
+ end
38
+
39
+ # This is the actual Module to be included into the Controller you call
40
+ # helper :aspect
41
+ # from.
42
+ #
43
+ # The reason for that is to avoid recursion of inclusion in AspectHelper
44
+ # which does the aliasing and predefinition of the traits for the aspects.
27
45
 
46
+ module AspectHelperMixin
28
47
  private
29
48
 
30
49
  # define pre-aspect which calls render(:your_pre_aspect)
@@ -47,7 +66,7 @@ module Ramaze
47
66
  # With great power comes great responsibility
48
67
  #
49
68
  # Example:
50
- # class FooController < Template::Ramaze
69
+ # class FooController < Controller
51
70
  #
52
71
  # def index
53
72
  # 'foo'
@@ -93,7 +112,7 @@ module Ramaze
93
112
  # With great power comes great responsibility
94
113
  #
95
114
  # Example:
96
- # class FooController < Template::Ramaze
115
+ # class FooController < Controller
97
116
  #
98
117
  # def index
99
118
  # 'foo'
@@ -175,12 +194,16 @@ module Ramaze
175
194
 
176
195
  if pre
177
196
  arity = arity_for[pre].abs
178
- pre_content = old_render(pre, *params[0,arity]) if pre
197
+ pre_content = old_render(pre, *params[0,arity])
179
198
  end
180
199
 
181
200
  unless (pre_content.delete(:skip_next_aspects) rescue false)
182
201
  content = old_render(action, *params)
183
- post_content = old_render(post, *params) if post
202
+
203
+ if post
204
+ arity = arity_for[post].abs
205
+ post_content = old_render(post, *params[0,arity])
206
+ end
184
207
  end
185
208
 
186
209
  [pre_content, content, post_content].join