merb 0.0.4 → 0.0.5

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 (81) hide show
  1. data/README +41 -2
  2. data/Rakefile +4 -2
  3. data/TODO +3 -3
  4. data/bin/merb +157 -3
  5. data/doc/rdoc/classes/Hash.html +4 -4
  6. data/doc/rdoc/classes/Merb.html +2 -12
  7. data/doc/rdoc/classes/Merb/Controller.html +347 -156
  8. data/doc/rdoc/classes/Merb/RouteMatcher.html +93 -59
  9. data/doc/rdoc/classes/MerbHandler.html +117 -107
  10. data/doc/rdoc/classes/MerbHash.html +64 -58
  11. data/doc/rdoc/classes/Noroutefound.html +16 -10
  12. data/doc/rdoc/classes/Object.html +5 -5
  13. data/doc/rdoc/classes/String.html +28 -16
  14. data/doc/rdoc/classes/Symbol.html +15 -8
  15. data/doc/rdoc/created.rid +1 -1
  16. data/doc/rdoc/files/README.html +56 -4
  17. data/doc/rdoc/files/TODO.html +4 -4
  18. data/doc/rdoc/files/lib/merb/merb_controller_rb.html +1 -1
  19. data/doc/rdoc/files/lib/merb/merb_handler_rb.html +1 -1
  20. data/doc/rdoc/files/lib/merb/merb_router_rb.html +1 -1
  21. data/doc/rdoc/files/lib/merb/merb_utils_rb.html +1 -1
  22. data/doc/rdoc/files/lib/merb_rb.html +30 -2
  23. data/doc/rdoc/files/lib/{merb_config_rb.html → merb_tasks_rb.html} +4 -4
  24. data/doc/rdoc/fr_class_index.html +0 -2
  25. data/doc/rdoc/fr_file_index.html +1 -3
  26. data/doc/rdoc/fr_method_index.html +21 -21
  27. data/examples/app_skeleton/Rakefile +81 -0
  28. data/examples/app_skeleton/dist/conf/merb_init.rb +15 -0
  29. data/examples/{skeleton → app_skeleton}/dist/conf/router.rb +5 -7
  30. data/examples/app_skeleton/scripts/merb_stop +5 -0
  31. data/examples/app_skeleton/scripts/new_migration +21 -0
  32. data/examples/{skeleton → app_skeleton}/test/test_helper.rb +0 -0
  33. data/examples/sample_app/Rakefile +81 -0
  34. data/examples/sample_app/dist/app/controllers/posts.rb +26 -10
  35. data/examples/sample_app/dist/app/models/comment.rb +3 -0
  36. data/examples/sample_app/dist/app/models/post.rb +2 -11
  37. data/examples/sample_app/dist/app/views/layout/application.rhtml +59 -4
  38. data/examples/sample_app/dist/app/views/posts/_comments.rhtml +11 -0
  39. data/examples/sample_app/dist/app/views/posts/comment.merbjs +1 -0
  40. data/examples/sample_app/dist/app/views/posts/list.rhtml +2 -4
  41. data/examples/sample_app/dist/app/views/posts/new.rhtml +2 -2
  42. data/examples/sample_app/dist/app/views/posts/show.rhtml +35 -3
  43. data/examples/sample_app/dist/conf/merb_init.rb +2 -4
  44. data/examples/sample_app/dist/conf/router.rb +3 -4
  45. data/examples/sample_app/dist/public/images/bg.jpg +0 -0
  46. data/examples/sample_app/dist/public/images/book.gif +0 -0
  47. data/examples/sample_app/dist/public/images/booksmall.gif +0 -0
  48. data/examples/sample_app/dist/public/images/greenright.jpg +0 -0
  49. data/examples/sample_app/dist/public/images/louiecon.gif +0 -0
  50. data/examples/sample_app/dist/public/images/menu.gif +0 -0
  51. data/examples/sample_app/dist/public/images/menuleft.gif +0 -0
  52. data/examples/sample_app/dist/public/images/menuright.gif +0 -0
  53. data/examples/sample_app/dist/public/images/mountain.jpg +0 -0
  54. data/examples/sample_app/dist/public/images/n3.jpg +0 -0
  55. data/examples/sample_app/dist/public/images/nautica.jpg +0 -0
  56. data/examples/sample_app/dist/public/javascripts/application.js +0 -0
  57. data/examples/sample_app/dist/public/javascripts/effects.js +975 -0
  58. data/examples/sample_app/dist/public/javascripts/prototype.js +2264 -0
  59. data/examples/sample_app/dist/public/stylesheets/merb.css +277 -0
  60. data/examples/sample_app/dist/schema/migrations/001_add_comments_to_posts.rb +22 -0
  61. data/examples/sample_app/dist/schema/schema.rb +22 -0
  62. data/examples/sample_app/log/merb.log +164394 -0
  63. data/examples/sample_app/script/merb_stop +9 -0
  64. data/examples/sample_app/script/new_migration +21 -0
  65. data/lib/merb.rb +7 -4
  66. data/lib/merb/merb_controller.rb +83 -4
  67. data/lib/merb/merb_handler.rb +20 -9
  68. data/lib/merb/merb_router.rb +18 -1
  69. data/lib/merb/merb_utils.rb +11 -1
  70. data/lib/merb_tasks.rb +7 -0
  71. data/lib/tasks/db.rake +53 -0
  72. metadata +67 -34
  73. data/doc/rdoc/classes/Merb/Config.html +0 -161
  74. data/doc/rdoc/classes/Merb/Server.html +0 -288
  75. data/doc/rdoc/files/lib/merb/merb_daemon_rb.html +0 -113
  76. data/doc/rdoc/files/lib/merb/noroutefound_rb.html +0 -101
  77. data/examples/sample_app/dist/app/views/layout/posts.rhtml +0 -6
  78. data/examples/skeleton/dist/conf/merb_init.rb +0 -21
  79. data/lib/merb/merb_daemon.rb +0 -91
  80. data/lib/merb/noroutefound.rb +0 -11
  81. data/lib/merb_config.rb +0 -21
@@ -155,14 +155,17 @@ your controller methods. This route maps the default /controller/action and
155
155
  </div>
156
156
 
157
157
  <div class="method-description">
158
+ <p>
159
+ <a href="RouteMatcher.html#M000032">add</a> a route to be compiled
160
+ </p>
158
161
  <p><a class="source-toggle" href="#"
159
162
  onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
160
163
  <div class="method-source-code" id="M000032-source">
161
164
  <pre>
162
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 37</span>
163
- 37: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">route</span>)
164
- 38: <span class="ruby-ivar">@@routes</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>], (<span class="ruby-identifier">route</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">||</span> {})]
165
- 39: <span class="ruby-keyword kw">end</span>
165
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 44</span>
166
+ 44: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">route</span>)
167
+ 45: <span class="ruby-ivar">@@routes</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>], (<span class="ruby-identifier">route</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">||</span> {})]
168
+ 46: <span class="ruby-keyword kw">end</span>
166
169
  </pre>
167
170
  </div>
168
171
  </div>
@@ -178,38 +181,45 @@ your controller methods. This route maps the default /controller/action and
178
181
  </div>
179
182
 
180
183
  <div class="method-description">
184
+ <p>
185
+ <a href="RouteMatcher.html#M000034">compile</a> each individual route into
186
+ a when /&#8230;/ component of the case statement. Takes /:sections if the
187
+ route def that start with : and turns them into placeholders for whatever
188
+ urls match against the route in question. Special case for the default
189
+ /:controller/:action/:id route.
190
+ </p>
181
191
  <p><a class="source-toggle" href="#"
182
192
  onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
183
193
  <div class="method-source-code" id="M000034-source">
184
194
  <pre>
185
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 49</span>
186
- 49: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-identifier">route</span>)
187
- 50: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">String</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>]
188
- 51: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'/:controller/:action/:id'</span>
189
- 52: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">' when /\A\/([^\/;.,?]+)(?:\/?\Z|\/([^\/;.,?]+)\/?)(?:\/?\Z|\/([^\/;.,?]+)\/?)\Z/
190
- 53: @sections[:controller] = $1
191
- 54: @sections[:action] = $2 || \'index\'
192
- 55: @sections[:id] = $3 || nil
193
- 56: return @sections'</span><span class="ruby-operator">&lt;&lt;</span><span class="ruby-value str">&quot;\n&quot;</span>
194
- 57: <span class="ruby-keyword kw">end</span>
195
- 58: <span class="ruby-identifier">code</span>, <span class="ruby-identifier">count</span> = <span class="ruby-value str">''</span>, <span class="ruby-value">0</span>
196
- 59: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">=~</span> <span class="ruby-ivar">@@section_regexp</span>
197
- 60: <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">dup</span>
198
- 61: <span class="ruby-identifier">name</span> = <span class="ruby-identifier">$1</span>
199
- 62: (<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(\*+)(\w+)/</span>) <span class="ruby-operator">?</span> (<span class="ruby-identifier">flag</span> = <span class="ruby-keyword kw">true</span>; <span class="ruby-identifier">name</span> = <span class="ruby-identifier">$2</span>) <span class="ruby-operator">:</span> (<span class="ruby-identifier">flag</span> = <span class="ruby-keyword kw">false</span>)
200
- 63: <span class="ruby-identifier">count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
201
- 64: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flag</span>
202
- 65: <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sub!</span>(<span class="ruby-ivar">@@section_regexp</span>, <span class="ruby-value str">&quot;([^;.,?]+)&quot;</span>)
203
- 66: <span class="ruby-keyword kw">else</span>
204
- 67: <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sub!</span>(<span class="ruby-ivar">@@section_regexp</span>, <span class="ruby-value str">&quot;([^\/;.,?]+)&quot;</span>)
205
- 68: <span class="ruby-keyword kw">end</span>
206
- 69: <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot; @sections[:#{name}] = $#{count}\n&quot;</span>
207
- 70: <span class="ruby-keyword kw">end</span>
208
- 71: <span class="ruby-identifier">condition</span> = <span class="ruby-node">&quot; when Regexp.new('#{route[0]}')&quot;</span>
209
- 72: <span class="ruby-identifier">statement</span> = <span class="ruby-node">&quot;#{condition}\n#{code}&quot;</span>
210
- 73: <span class="ruby-identifier">statement</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot; return #{route[1].inspect}.merge(@sections)\n&quot;</span>
211
- 74: <span class="ruby-identifier">statement</span>
212
- 75: <span class="ruby-keyword kw">end</span>
195
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 66</span>
196
+ 66: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-identifier">route</span>)
197
+ 67: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">String</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>]
198
+ 68: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'/:controller/:action/:id'</span>
199
+ 69: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">' when /\A\/([^\/;.,?]+)(?:\/?\Z|\/([^\/;.,?]+)\/?)(?:\/?\Z|\/([^\/;.,?]+)\/?)\Z/
200
+ 70: @sections[:controller] = $1
201
+ 71: @sections[:action] = $2 || \'index\'
202
+ 72: @sections[:id] = $3 || nil
203
+ 73: return @sections'</span><span class="ruby-operator">&lt;&lt;</span><span class="ruby-value str">&quot;\n&quot;</span>
204
+ 74: <span class="ruby-keyword kw">end</span>
205
+ 75: <span class="ruby-identifier">code</span>, <span class="ruby-identifier">count</span> = <span class="ruby-value str">''</span>, <span class="ruby-value">0</span>
206
+ 76: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">=~</span> <span class="ruby-ivar">@@section_regexp</span>
207
+ 77: <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">dup</span>
208
+ 78: <span class="ruby-identifier">name</span> = <span class="ruby-identifier">$1</span>
209
+ 79: (<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(\*+)(\w+)/</span>) <span class="ruby-operator">?</span> (<span class="ruby-identifier">flag</span> = <span class="ruby-keyword kw">true</span>; <span class="ruby-identifier">name</span> = <span class="ruby-identifier">$2</span>) <span class="ruby-operator">:</span> (<span class="ruby-identifier">flag</span> = <span class="ruby-keyword kw">false</span>)
210
+ 80: <span class="ruby-identifier">count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
211
+ 81: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flag</span>
212
+ 82: <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sub!</span>(<span class="ruby-ivar">@@section_regexp</span>, <span class="ruby-value str">&quot;([^;.,?]+)&quot;</span>)
213
+ 83: <span class="ruby-keyword kw">else</span>
214
+ 84: <span class="ruby-identifier">route</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sub!</span>(<span class="ruby-ivar">@@section_regexp</span>, <span class="ruby-value str">&quot;([^\/;.,?]+)&quot;</span>)
215
+ 85: <span class="ruby-keyword kw">end</span>
216
+ 86: <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot; @sections[:#{name}] = $#{count}\n&quot;</span>
217
+ 87: <span class="ruby-keyword kw">end</span>
218
+ 88: <span class="ruby-identifier">condition</span> = <span class="ruby-node">&quot; when Regexp.new('#{route[0]}')&quot;</span>
219
+ 89: <span class="ruby-identifier">statement</span> = <span class="ruby-node">&quot;#{condition}\n#{code}&quot;</span>
220
+ 90: <span class="ruby-identifier">statement</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot; return #{route[1].inspect}.merge(@sections)\n&quot;</span>
221
+ 91: <span class="ruby-identifier">statement</span>
222
+ 92: <span class="ruby-keyword kw">end</span>
213
223
  </pre>
214
224
  </div>
215
225
  </div>
@@ -225,18 +235,24 @@ your controller methods. This route maps the default /controller/action and
225
235
  </div>
226
236
 
227
237
  <div class="method-description">
238
+ <p>
239
+ build up a string that defines a lambda that does a case statement on the
240
+ PATH_INFO against each of the compiled <a
241
+ href="RouteMatcher.html#M000030">routes</a> in turn. first route that
242
+ matches wins.
243
+ </p>
228
244
  <p><a class="source-toggle" href="#"
229
245
  onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
230
246
  <div class="method-source-code" id="M000033-source">
231
247
  <pre>
232
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 41</span>
233
- 41: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile_router</span>
234
- 42: <span class="ruby-identifier">router_lambda</span> = <span class="ruby-ivar">@@routes</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value str">&quot;lambda{|path| \n case path\n&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span>,<span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
235
- 43: <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">compile</span>(<span class="ruby-identifier">r</span>)
236
- 44: } <span class="ruby-operator">&lt;&lt;</span><span class="ruby-value str">&quot; else\n return {:controller=&gt;'Noroutefound', :action=&gt;'noroute'}\n end\n}&quot;</span>
237
- 45: <span class="ruby-ivar">@@compiled_statement</span> = <span class="ruby-identifier">router_lambda</span>
238
- 46: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">:route_request</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">eval</span>(<span class="ruby-identifier">router_lambda</span>))
239
- 47: <span class="ruby-keyword kw">end</span>
248
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 52</span>
249
+ 52: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile_router</span>
250
+ 53: <span class="ruby-identifier">router_lambda</span> = <span class="ruby-ivar">@@routes</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value str">&quot;lambda{|path| \n case path\n&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span>,<span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
251
+ 54: <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">compile</span>(<span class="ruby-identifier">r</span>)
252
+ 55: } <span class="ruby-operator">&lt;&lt;</span><span class="ruby-value str">&quot; else\n return {:controller=&gt;'Noroutefound', :action=&gt;'noroute'}\n end\n}&quot;</span>
253
+ 56: <span class="ruby-ivar">@@compiled_statement</span> = <span class="ruby-identifier">router_lambda</span>
254
+ 57: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">:route_request</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">eval</span>(<span class="ruby-identifier">router_lambda</span>))
255
+ 58: <span class="ruby-keyword kw">end</span>
240
256
  </pre>
241
257
  </div>
242
258
  </div>
@@ -252,14 +268,17 @@ your controller methods. This route maps the default /controller/action and
252
268
  </div>
253
269
 
254
270
  <div class="method-description">
271
+ <p>
272
+ init @sections for route segment recognition
273
+ </p>
255
274
  <p><a class="source-toggle" href="#"
256
275
  onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
257
276
  <div class="method-source-code" id="M000029-source">
258
277
  <pre>
259
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 25</span>
260
- 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
261
- 26: <span class="ruby-ivar">@sections</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
262
- 27: <span class="ruby-keyword kw">end</span>
278
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 28</span>
279
+ 28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
280
+ 29: <span class="ruby-ivar">@sections</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
281
+ 30: <span class="ruby-keyword kw">end</span>
263
282
  </pre>
264
283
  </div>
265
284
  </div>
@@ -275,17 +294,24 @@ your controller methods. This route maps the default /controller/action and
275
294
  </div>
276
295
 
277
296
  <div class="method-description">
297
+ <p>
298
+ setup the router and yield it out to <a
299
+ href="RouteMatcher.html#M000032">add</a> <a
300
+ href="RouteMatcher.html#M000030">routes</a> to it. Then <a
301
+ href="RouteMatcher.html#M000034">compile</a> all <a
302
+ href="RouteMatcher.html#M000030">routes</a>
303
+ </p>
278
304
  <p><a class="source-toggle" href="#"
279
305
  onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
280
306
  <div class="method-source-code" id="M000028-source">
281
307
  <pre>
282
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 18</span>
283
- 18: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">prepare</span>
284
- 19: <span class="ruby-ivar">@@routes</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
285
- 20: <span class="ruby-ivar">@@compiled_statement</span> = <span class="ruby-constant">String</span>.<span class="ruby-identifier">new</span>
286
- 21: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
287
- 22: <span class="ruby-identifier">compile_router</span>
288
- 23: <span class="ruby-keyword kw">end</span>
308
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 20</span>
309
+ 20: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">prepare</span>
310
+ 21: <span class="ruby-ivar">@@routes</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
311
+ 22: <span class="ruby-ivar">@@compiled_statement</span> = <span class="ruby-constant">String</span>.<span class="ruby-identifier">new</span>
312
+ 23: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
313
+ 24: <span class="ruby-identifier">compile_router</span>
314
+ 25: <span class="ruby-keyword kw">end</span>
289
315
  </pre>
290
316
  </div>
291
317
  </div>
@@ -303,14 +329,18 @@ your controller methods. This route maps the default /controller/action and
303
329
  </div>
304
330
 
305
331
  <div class="method-description">
332
+ <p>
333
+ the final compiled lambda that gets used as the body of the route_request
334
+ method.
335
+ </p>
306
336
  <p><a class="source-toggle" href="#"
307
337
  onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
308
338
  <div class="method-source-code" id="M000031-source">
309
339
  <pre>
310
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 33</span>
311
- 33: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compiled_statement</span>
312
- 34: <span class="ruby-ivar">@@compiled_statement</span>
313
- 35: <span class="ruby-keyword kw">end</span>
340
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 39</span>
341
+ 39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compiled_statement</span>
342
+ 40: <span class="ruby-ivar">@@compiled_statement</span>
343
+ 41: <span class="ruby-keyword kw">end</span>
314
344
  </pre>
315
345
  </div>
316
346
  </div>
@@ -326,14 +356,18 @@ your controller methods. This route maps the default /controller/action and
326
356
  </div>
327
357
 
328
358
  <div class="method-description">
359
+ <p>
360
+ all defined <a href="RouteMatcher.html#M000030">routes</a> in their raw
361
+ form.
362
+ </p>
329
363
  <p><a class="source-toggle" href="#"
330
364
  onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
331
365
  <div class="method-source-code" id="M000030-source">
332
366
  <pre>
333
- <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 29</span>
334
- 29: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">routes</span>
335
- 30: <span class="ruby-ivar">@@routes</span>
336
- 31: <span class="ruby-keyword kw">end</span>
367
+ <span class="ruby-comment cmt"># File lib/merb/merb_router.rb, line 33</span>
368
+ 33: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">routes</span>
369
+ 34: <span class="ruby-ivar">@@routes</span>
370
+ 35: <span class="ruby-keyword kw">end</span>
337
371
  </pre>
338
372
  </div>
339
373
  </div>
@@ -125,8 +125,7 @@
125
125
  <p>
126
126
  take the name of a directory and use that as the doc root or public
127
127
  directory of your site. This is set to the root of your merb app +
128
- &#8217;/public&#8217; by default. See merb_daemon.rb if you want to change
129
- this.
128
+ &#8217;/public&#8217; by default.
130
129
  </p>
131
130
  <p><a class="source-toggle" href="#"
132
131
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
@@ -162,11 +161,11 @@ display
162
161
  onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
163
162
  <div class="method-source-code" id="M000007-source">
164
163
  <pre>
165
- <span class="ruby-comment cmt"># File lib/merb/merb_handler.rb, line 143</span>
166
- 143: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exception</span>(<span class="ruby-identifier">e</span>)
167
- 144: <span class="ruby-node">&quot;&lt;html&gt;&lt;h2&gt;Merb Error!&lt;/h2&gt;&lt;p&gt;#{ e.message } - (#{ e.class })\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
168
- 145: <span class="ruby-node">&quot;#{(e.backtrace or []).join('&lt;br /&gt;')}&lt;/p&gt;&lt;/html&gt;&quot;</span>
169
- 146: <span class="ruby-keyword kw">end</span>
164
+ <span class="ruby-comment cmt"># File lib/merb/merb_handler.rb, line 154</span>
165
+ 154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exception</span>(<span class="ruby-identifier">e</span>)
166
+ 155: <span class="ruby-node">&quot;&lt;html&gt;&lt;h2&gt;Merb Error!&lt;/h2&gt;&lt;p&gt;#{ e.message } - (#{ e.class })\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
167
+ 156: <span class="ruby-node">&quot;#{(e.backtrace or []).join('&lt;br /&gt;')}&lt;/p&gt;&lt;/html&gt;&quot;</span>
168
+ 157: <span class="ruby-keyword kw">end</span>
170
169
  </pre>
171
170
  </div>
172
171
  </div>
@@ -185,26 +184,26 @@ display
185
184
  <p>
186
185
  This is where we grab the incoming request PATH_INFO and use that in the
187
186
  merb routematcher to determine which controller and method to run. returns
188
- a 2 element tuple of: [controller_object, method]
187
+ a 2 element tuple of: [controller, action]
189
188
  </p>
190
189
  <p><a class="source-toggle" href="#"
191
190
  onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
192
191
  <div class="method-source-code" id="M000005-source">
193
192
  <pre>
194
- <span class="ruby-comment cmt"># File lib/merb/merb_handler.rb, line 111</span>
195
- 111: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">handle</span>(<span class="ruby-identifier">request</span>)
196
- 112: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH_INFO</span>].<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/\/+/</span>, <span class="ruby-value str">'/'</span>)
197
- 113: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">path</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">path</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?/</span>)
198
- 114: <span class="ruby-identifier">route</span> = <span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteMatcher</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">route_request</span>(<span class="ruby-identifier">path</span>)
199
- 115: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$DEBUG</span>
200
- 116: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>
201
- 117: [ <span class="ruby-identifier">instantiate_controller</span>(<span class="ruby-identifier">route</span>[<span class="ruby-identifier">:controller</span>], <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>, <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>,
202
- 118: <span class="ruby-identifier">route</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">delete_if</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">:controller</span>, <span class="ruby-identifier">:action</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">k</span>}),
203
- 119: <span class="ruby-identifier">route</span>[<span class="ruby-identifier">:action</span>]]
204
- 120: <span class="ruby-keyword kw">else</span>
205
- 121: [<span class="ruby-value str">&quot;&lt;html&gt;&lt;body&gt;Error: no route matches!&lt;/body&gt;&lt;/html&gt;&quot;</span>, <span class="ruby-keyword kw">nil</span>]
206
- 122: <span class="ruby-keyword kw">end</span>
207
- 123: <span class="ruby-keyword kw">end</span>
193
+ <span class="ruby-comment cmt"># File lib/merb/merb_handler.rb, line 122</span>
194
+ 122: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">handle</span>(<span class="ruby-identifier">request</span>)
195
+ 123: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH_INFO</span>].<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/\/+/</span>, <span class="ruby-value str">'/'</span>)
196
+ 124: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">path</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">path</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?/</span>)
197
+ 125: <span class="ruby-identifier">route</span> = <span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteMatcher</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">route_request</span>(<span class="ruby-identifier">path</span>)
198
+ 126: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>
199
+ 127: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;No Matching Route!&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>[<span class="ruby-identifier">:controller</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'Noroutefound'</span>
200
+ 128: [ <span class="ruby-identifier">instantiate_controller</span>(<span class="ruby-identifier">route</span>[<span class="ruby-identifier">:controller</span>], <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>, <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>, <span class="ruby-identifier">route</span>),
201
+ 129: <span class="ruby-identifier">route</span>[<span class="ruby-identifier">:action</span>] ]
202
+ 130: <span class="ruby-keyword kw">else</span>
203
+ 131: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;No Matching Route!&quot;</span>)
204
+ 132: [<span class="ruby-value str">&quot;&lt;html&gt;&lt;body&gt;Error: no route matches!&lt;/body&gt;&lt;/html&gt;&quot;</span>, <span class="ruby-keyword kw">nil</span>]
205
+ 133: <span class="ruby-keyword kw">end</span>
206
+ 134: <span class="ruby-keyword kw">end</span>
208
207
  </pre>
209
208
  </div>
210
209
  </div>
@@ -231,19 +230,19 @@ href="Merb/Controller.html">Merb::Controller</a> is instantiated.
231
230
  onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
232
231
  <div class="method-source-code" id="M000006-source">
233
232
  <pre>
234
- <span class="ruby-comment cmt"># File lib/merb/merb_handler.rb, line 129</span>
235
- 129: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instantiate_controller</span>(<span class="ruby-identifier">controller_name</span>, <span class="ruby-identifier">req</span>, <span class="ruby-identifier">env</span>, <span class="ruby-identifier">params</span>)
236
- 130: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">Server</span>.<span class="ruby-identifier">config</span>[<span class="ruby-identifier">:dist_root</span>]<span class="ruby-operator">+</span><span class="ruby-node">&quot;/app/controllers/#{controller_name.snake_case}.rb&quot;</span>)
237
- 131: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">:Noroutefound</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">env</span>, <span class="ruby-identifier">params</span>)
238
- 132: <span class="ruby-keyword kw">end</span>
239
- 133: <span class="ruby-keyword kw">begin</span>
240
- 134: <span class="ruby-identifier">controller_name</span>.<span class="ruby-identifier">import</span>
241
- 135: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_get</span>( <span class="ruby-identifier">controller_name</span>.<span class="ruby-identifier">camel_case</span> ).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">env</span>, <span class="ruby-identifier">params</span>)
242
- 136: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
243
- 137: <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;Error getting instance of '#{controller_name.camel_case}': #{$!}&quot;</span>
244
- 138: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">$!</span>
245
- 139: <span class="ruby-keyword kw">end</span>
246
- 140: <span class="ruby-keyword kw">end</span>
233
+ <span class="ruby-comment cmt"># File lib/merb/merb_handler.rb, line 140</span>
234
+ 140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instantiate_controller</span>(<span class="ruby-identifier">controller_name</span>, <span class="ruby-identifier">req</span>, <span class="ruby-identifier">env</span>, <span class="ruby-identifier">params</span>)
235
+ 141: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">Server</span>.<span class="ruby-identifier">config</span>[<span class="ruby-identifier">:dist_root</span>]<span class="ruby-operator">+</span><span class="ruby-node">&quot;/app/controllers/#{controller_name.snake_case}.rb&quot;</span>)
236
+ 142: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">:Noroutefound</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">env</span>, <span class="ruby-identifier">params</span>)
237
+ 143: <span class="ruby-keyword kw">end</span>
238
+ 144: <span class="ruby-keyword kw">begin</span>
239
+ 145: <span class="ruby-identifier">controller_name</span>.<span class="ruby-identifier">import</span>
240
+ 146: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_get</span>( <span class="ruby-identifier">controller_name</span>.<span class="ruby-identifier">camel_case</span> ).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">env</span>, <span class="ruby-identifier">params</span>)
241
+ 147: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
242
+ 148: <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;Error getting instance of '#{controller_name.camel_case}': #{$!}&quot;</span>
243
+ 149: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">$!</span>
244
+ 150: <span class="ruby-keyword kw">end</span>
245
+ 151: <span class="ruby-keyword kw">end</span>
247
246
  </pre>
248
247
  </div>
249
248
  </div>
@@ -311,79 +310,90 @@ can go on processing other requests.
311
310
  29: <span class="ruby-keyword kw">return</span>
312
311
  30: <span class="ruby-keyword kw">end</span>
313
312
  31:
314
- 32: <span class="ruby-comment cmt"># Rails style page caching. Check the public dir first for</span>
315
- 33: <span class="ruby-comment cmt"># .html pages and serve directly. Otherwise fall back to Merb </span>
316
- 34: <span class="ruby-comment cmt"># routing and request dispatching. </span>
317
- 35: <span class="ruby-identifier">path_info</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH_INFO</span>]
318
- 36: <span class="ruby-identifier">page_cached</span> = <span class="ruby-identifier">path_info</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.html&quot;</span>
319
- 37: <span class="ruby-identifier">get_or_head</span> = <span class="ruby-ivar">@@file_only_methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUEST_METHOD</span>]
320
- 38:
321
- 39: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">get_or_head</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">can_serve</span>(<span class="ruby-identifier">path_info</span>)
322
- 40: <span class="ruby-comment cmt"># File exists as-is so serve it up</span>
323
- 41: <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>,<span class="ruby-identifier">response</span>)
324
- 42: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">get_or_head</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">can_serve</span>(<span class="ruby-identifier">page_cached</span>)
325
- 43: <span class="ruby-comment cmt"># Possible cached page, serve it up</span>
326
- 44: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH_INFO</span>] = <span class="ruby-identifier">page_cached</span>
313
+ 32: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Request: PATH_INFO: #{request.params[Mongrel::Const::PATH_INFO]}&quot;</span>)
314
+ 33:
315
+ 34: <span class="ruby-comment cmt"># Rails style page caching. Check the public dir first for</span>
316
+ 35: <span class="ruby-comment cmt"># .html pages and serve directly. Otherwise fall back to Merb </span>
317
+ 36: <span class="ruby-comment cmt"># routing and request dispatching. </span>
318
+ 37: <span class="ruby-identifier">path_info</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH_INFO</span>]
319
+ 38: <span class="ruby-identifier">page_cached</span> = <span class="ruby-identifier">path_info</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.html&quot;</span>
320
+ 39: <span class="ruby-identifier">get_or_head</span> = <span class="ruby-ivar">@@file_only_methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUEST_METHOD</span>]
321
+ 40:
322
+ 41: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">get_or_head</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">can_serve</span>(<span class="ruby-identifier">path_info</span>)
323
+ 42: <span class="ruby-comment cmt"># File exists as-is so serve it up</span>
324
+ 43: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Serving static file: #{path_info}&quot;</span>)
325
+ 44:
327
326
  45: <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>,<span class="ruby-identifier">response</span>)
328
- 46: <span class="ruby-keyword kw">else</span>
329
- 47: <span class="ruby-keyword kw">begin</span>
330
- 48: <span class="ruby-comment cmt"># This handles parsing the query string and post/file upload</span>
331
- 49: <span class="ruby-comment cmt"># params and is outside of the synchronize call so that</span>
332
- 50: <span class="ruby-comment cmt"># multiple file uploads can be done at once.</span>
333
- 51: <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">handle</span>(<span class="ruby-identifier">request</span>)
334
- 52: <span class="ruby-identifier">p</span> <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span>
335
- 53: <span class="ruby-identifier">output</span> = <span class="ruby-keyword kw">nil</span>
336
- 54: <span class="ruby-comment cmt"># synchronize here because this is where ActiveRecord or your db</span>
337
- 55: <span class="ruby-comment cmt"># calls will be run in your controller methods.</span>
338
- 56: <span class="ruby-ivar">@guard</span>.<span class="ruby-identifier">synchronize</span>(<span class="ruby-identifier">:EX</span>) {
339
- 57: <span class="ruby-identifier">output</span> = <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">controller</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">Controller</span>))
340
- 58: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">action</span>
341
- 59: <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action</span>)
342
- 60: <span class="ruby-keyword kw">else</span>
343
- 61: <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">to_s</span>
344
- 62: <span class="ruby-keyword kw">end</span>
345
- 63: <span class="ruby-keyword kw">else</span>
346
- 64: <span class="ruby-keyword kw">nil</span>
347
- 65: <span class="ruby-keyword kw">end</span>
348
- 66: }
349
- 67: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
350
- 68: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">start</span>(<span class="ruby-value">500</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">head</span>,<span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
351
- 69: <span class="ruby-identifier">head</span>[<span class="ruby-value str">&quot;Content-Type&quot;</span>] = <span class="ruby-value str">&quot;text/html&quot;</span>
352
- 70: <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">exception</span>(<span class="ruby-identifier">e</span>)
353
- 71: <span class="ruby-keyword kw">end</span>
354
- 72: <span class="ruby-keyword kw">return</span>
355
- 73: <span class="ruby-keyword kw">end</span>
356
- 74:
357
- 75: <span class="ruby-identifier">sendfile</span>, <span class="ruby-identifier">clength</span> = <span class="ruby-keyword kw">nil</span>
358
- 76: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">status</span>
359
- 77:
360
- 78: <span class="ruby-comment cmt"># check for the X-SENDFILE header from your Merb::Controller</span>
361
- 79: <span class="ruby-comment cmt"># and serve the file directly instead of buffering.</span>
362
- 80: <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
363
- 81: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^X-SENDFILE$/i</span>
364
- 82: <span class="ruby-identifier">sendfile</span> = <span class="ruby-identifier">v</span>
365
- 83: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^CONTENT-LENGTH$/i</span>
366
- 84: <span class="ruby-identifier">clength</span> = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_i</span>
367
- 85: <span class="ruby-keyword kw">else</span>
368
- 86: [<span class="ruby-operator">*</span><span class="ruby-identifier">v</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vi</span><span class="ruby-operator">|</span>
369
- 87: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">header</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">vi</span>
370
- 88: <span class="ruby-keyword kw">end</span>
371
- 89: <span class="ruby-keyword kw">end</span>
372
- 90: <span class="ruby-keyword kw">end</span>
373
- 91:
374
- 92: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sendfile</span>
375
- 93: <span class="ruby-comment cmt"># send X-SENDFILE header to mongrel</span>
376
- 94: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_status</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">size</span>(<span class="ruby-identifier">sendfile</span>))
377
- 95: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_header</span>
378
- 96: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_file</span>(<span class="ruby-identifier">sendfile</span>)
379
- 97: <span class="ruby-keyword kw">else</span>
380
- 98: <span class="ruby-comment cmt"># render response from successful controller</span>
381
- 99: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_status</span>(<span class="ruby-identifier">output</span>.<span class="ruby-identifier">length</span>)
382
- 100: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_header</span>
383
- 101: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">output</span>)
384
- 102: <span class="ruby-keyword kw">end</span>
385
- 103: <span class="ruby-keyword kw">end</span>
386
- 104: <span class="ruby-keyword kw">end</span>
327
+ 46: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">get_or_head</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">can_serve</span>(<span class="ruby-identifier">page_cached</span>)
328
+ 47: <span class="ruby-comment cmt"># Possible cached page, serve it up</span>
329
+ 48: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Serving static file: #{path_info}&quot;</span>)
330
+ 49: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH_INFO</span>] = <span class="ruby-identifier">page_cached</span>
331
+ 50: <span class="ruby-ivar">@files</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>,<span class="ruby-identifier">response</span>)
332
+ 51: <span class="ruby-keyword kw">else</span>
333
+ 52: <span class="ruby-keyword kw">begin</span>
334
+ 53: <span class="ruby-comment cmt"># This handles parsing the query string and post/file upload</span>
335
+ 54: <span class="ruby-comment cmt"># params and is outside of the synchronize call so that</span>
336
+ 55: <span class="ruby-comment cmt"># multiple file uploads can be done at once.</span>
337
+ 56: <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">handle</span>(<span class="ruby-identifier">request</span>)
338
+ 57: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Routing to controller: #{controller.class} action: #{action}&quot;</span>)
339
+ 58: <span class="ruby-identifier">output</span> = <span class="ruby-keyword kw">nil</span>
340
+ 59: <span class="ruby-comment cmt"># synchronize here because this is where ActiveRecord or your db</span>
341
+ 60: <span class="ruby-comment cmt"># calls will be run in your controller methods.</span>
342
+ 61: <span class="ruby-ivar">@guard</span>.<span class="ruby-identifier">synchronize</span>(<span class="ruby-identifier">:EX</span>) {
343
+ 62: <span class="ruby-identifier">output</span> =
344
+ 63: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">controller</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">Controller</span>))
345
+ 64: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">action</span>
346
+ 65: <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action</span>)
347
+ 66: <span class="ruby-keyword kw">else</span>
348
+ 67: <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">to_s</span>
349
+ 68: <span class="ruby-keyword kw">end</span>
350
+ 69: <span class="ruby-keyword kw">else</span>
351
+ 70: <span class="ruby-keyword kw">nil</span>
352
+ 71: <span class="ruby-keyword kw">end</span>
353
+ 72: }
354
+ 73: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
355
+ 74: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">start</span>(<span class="ruby-value">500</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">head</span>,<span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
356
+ 75: <span class="ruby-identifier">head</span>[<span class="ruby-value str">&quot;Content-Type&quot;</span>] = <span class="ruby-value str">&quot;text/html&quot;</span>
357
+ 76: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-identifier">ex</span> = <span class="ruby-identifier">exception</span>(<span class="ruby-identifier">e</span>))
358
+ 77: <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">ex</span>
359
+ 78: <span class="ruby-keyword kw">end</span>
360
+ 79: <span class="ruby-keyword kw">return</span>
361
+ 80: <span class="ruby-keyword kw">end</span>
362
+ 81:
363
+ 82: <span class="ruby-identifier">sendfile</span>, <span class="ruby-identifier">clength</span> = <span class="ruby-keyword kw">nil</span>
364
+ 83: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">status</span>
365
+ 84:
366
+ 85: <span class="ruby-comment cmt"># check for the X-SENDFILE header from your Merb::Controller</span>
367
+ 86: <span class="ruby-comment cmt"># and serve the file directly instead of buffering.</span>
368
+ 87: <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
369
+ 88: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^X-SENDFILE$/i</span>
370
+ 89: <span class="ruby-identifier">sendfile</span> = <span class="ruby-identifier">v</span>
371
+ 90: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^CONTENT-LENGTH$/i</span>
372
+ 91: <span class="ruby-identifier">clength</span> = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_i</span>
373
+ 92: <span class="ruby-keyword kw">else</span>
374
+ 93: [<span class="ruby-operator">*</span><span class="ruby-identifier">v</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vi</span><span class="ruby-operator">|</span>
375
+ 94: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">header</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">vi</span>
376
+ 95: <span class="ruby-keyword kw">end</span>
377
+ 96: <span class="ruby-keyword kw">end</span>
378
+ 97: <span class="ruby-keyword kw">end</span>
379
+ 98:
380
+ 99: <span class="ruby-identifier">controller</span> = <span class="ruby-keyword kw">nil</span>
381
+ 100:
382
+ 101: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sendfile</span>
383
+ 102: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;X-SENDFILE: #{sendfile}&quot;</span>)
384
+ 103: <span class="ruby-comment cmt"># send X-SENDFILE header to mongrel</span>
385
+ 104: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_status</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">size</span>(<span class="ruby-identifier">sendfile</span>))
386
+ 105: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_header</span>
387
+ 106: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_file</span>(<span class="ruby-identifier">sendfile</span>)
388
+ 107: <span class="ruby-keyword kw">else</span>
389
+ 108: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Response status: #{response.status}\n\n&quot;</span>)
390
+ 109: <span class="ruby-comment cmt"># render response from successful controller</span>
391
+ 110: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_status</span>(<span class="ruby-identifier">output</span>.<span class="ruby-identifier">length</span>)
392
+ 111: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_header</span>
393
+ 112: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">output</span>)
394
+ 113: <span class="ruby-keyword kw">end</span>
395
+ 114: <span class="ruby-keyword kw">end</span>
396
+ 115: <span class="ruby-keyword kw">end</span>
387
397
  </pre>
388
398
  </div>
389
399
  </div>