merb 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +41 -2
- data/Rakefile +4 -2
- data/TODO +3 -3
- data/bin/merb +157 -3
- data/doc/rdoc/classes/Hash.html +4 -4
- data/doc/rdoc/classes/Merb.html +2 -12
- data/doc/rdoc/classes/Merb/Controller.html +347 -156
- data/doc/rdoc/classes/Merb/RouteMatcher.html +93 -59
- data/doc/rdoc/classes/MerbHandler.html +117 -107
- data/doc/rdoc/classes/MerbHash.html +64 -58
- data/doc/rdoc/classes/Noroutefound.html +16 -10
- data/doc/rdoc/classes/Object.html +5 -5
- data/doc/rdoc/classes/String.html +28 -16
- data/doc/rdoc/classes/Symbol.html +15 -8
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +56 -4
- data/doc/rdoc/files/TODO.html +4 -4
- data/doc/rdoc/files/lib/merb/merb_controller_rb.html +1 -1
- data/doc/rdoc/files/lib/merb/merb_handler_rb.html +1 -1
- data/doc/rdoc/files/lib/merb/merb_router_rb.html +1 -1
- data/doc/rdoc/files/lib/merb/merb_utils_rb.html +1 -1
- data/doc/rdoc/files/lib/merb_rb.html +30 -2
- data/doc/rdoc/files/lib/{merb_config_rb.html → merb_tasks_rb.html} +4 -4
- data/doc/rdoc/fr_class_index.html +0 -2
- data/doc/rdoc/fr_file_index.html +1 -3
- data/doc/rdoc/fr_method_index.html +21 -21
- data/examples/app_skeleton/Rakefile +81 -0
- data/examples/app_skeleton/dist/conf/merb_init.rb +15 -0
- data/examples/{skeleton → app_skeleton}/dist/conf/router.rb +5 -7
- data/examples/app_skeleton/scripts/merb_stop +5 -0
- data/examples/app_skeleton/scripts/new_migration +21 -0
- data/examples/{skeleton → app_skeleton}/test/test_helper.rb +0 -0
- data/examples/sample_app/Rakefile +81 -0
- data/examples/sample_app/dist/app/controllers/posts.rb +26 -10
- data/examples/sample_app/dist/app/models/comment.rb +3 -0
- data/examples/sample_app/dist/app/models/post.rb +2 -11
- data/examples/sample_app/dist/app/views/layout/application.rhtml +59 -4
- data/examples/sample_app/dist/app/views/posts/_comments.rhtml +11 -0
- data/examples/sample_app/dist/app/views/posts/comment.merbjs +1 -0
- data/examples/sample_app/dist/app/views/posts/list.rhtml +2 -4
- data/examples/sample_app/dist/app/views/posts/new.rhtml +2 -2
- data/examples/sample_app/dist/app/views/posts/show.rhtml +35 -3
- data/examples/sample_app/dist/conf/merb_init.rb +2 -4
- data/examples/sample_app/dist/conf/router.rb +3 -4
- data/examples/sample_app/dist/public/images/bg.jpg +0 -0
- data/examples/sample_app/dist/public/images/book.gif +0 -0
- data/examples/sample_app/dist/public/images/booksmall.gif +0 -0
- data/examples/sample_app/dist/public/images/greenright.jpg +0 -0
- data/examples/sample_app/dist/public/images/louiecon.gif +0 -0
- data/examples/sample_app/dist/public/images/menu.gif +0 -0
- data/examples/sample_app/dist/public/images/menuleft.gif +0 -0
- data/examples/sample_app/dist/public/images/menuright.gif +0 -0
- data/examples/sample_app/dist/public/images/mountain.jpg +0 -0
- data/examples/sample_app/dist/public/images/n3.jpg +0 -0
- data/examples/sample_app/dist/public/images/nautica.jpg +0 -0
- data/examples/sample_app/dist/public/javascripts/application.js +0 -0
- data/examples/sample_app/dist/public/javascripts/effects.js +975 -0
- data/examples/sample_app/dist/public/javascripts/prototype.js +2264 -0
- data/examples/sample_app/dist/public/stylesheets/merb.css +277 -0
- data/examples/sample_app/dist/schema/migrations/001_add_comments_to_posts.rb +22 -0
- data/examples/sample_app/dist/schema/schema.rb +22 -0
- data/examples/sample_app/log/merb.log +164394 -0
- data/examples/sample_app/script/merb_stop +9 -0
- data/examples/sample_app/script/new_migration +21 -0
- data/lib/merb.rb +7 -4
- data/lib/merb/merb_controller.rb +83 -4
- data/lib/merb/merb_handler.rb +20 -9
- data/lib/merb/merb_router.rb +18 -1
- data/lib/merb/merb_utils.rb +11 -1
- data/lib/merb_tasks.rb +7 -0
- data/lib/tasks/db.rake +53 -0
- metadata +67 -34
- data/doc/rdoc/classes/Merb/Config.html +0 -161
- data/doc/rdoc/classes/Merb/Server.html +0 -288
- data/doc/rdoc/files/lib/merb/merb_daemon_rb.html +0 -113
- data/doc/rdoc/files/lib/merb/noroutefound_rb.html +0 -101
- data/examples/sample_app/dist/app/views/layout/posts.rhtml +0 -6
- data/examples/skeleton/dist/conf/merb_init.rb +0 -21
- data/lib/merb/merb_daemon.rb +0 -91
- data/lib/merb/noroutefound.rb +0 -11
- 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
|
163
|
-
|
164
|
-
|
165
|
-
|
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"><<</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 /…/ 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
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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"><<</span><span class="ruby-value str">"\n"</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">"([^;.,?]+)"</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">"([^\/;.,?]+)"</span>)
|
215
|
+
85: <span class="ruby-keyword kw">end</span>
|
216
|
+
86: <span class="ruby-identifier">code</span> <span class="ruby-operator"><<</span> <span class="ruby-node">" @sections[:#{name}] = $#{count}\n"</span>
|
217
|
+
87: <span class="ruby-keyword kw">end</span>
|
218
|
+
88: <span class="ruby-identifier">condition</span> = <span class="ruby-node">" when Regexp.new('#{route[0]}')"</span>
|
219
|
+
89: <span class="ruby-identifier">statement</span> = <span class="ruby-node">"#{condition}\n#{code}"</span>
|
220
|
+
90: <span class="ruby-identifier">statement</span> <span class="ruby-operator"><<</span> <span class="ruby-node">" return #{route[1].inspect}.merge(@sections)\n"</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
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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">"lambda{|path| \n case path\n"</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"><<</span> <span class="ruby-identifier">compile</span>(<span class="ruby-identifier">r</span>)
|
252
|
+
55: } <span class="ruby-operator"><<</span><span class="ruby-value str">" else\n return {:controller=>'Noroutefound', :action=>'noroute'}\n end\n}"</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">&</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
|
260
|
-
|
261
|
-
|
262
|
-
|
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
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
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
|
311
|
-
|
312
|
-
|
313
|
-
|
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
|
334
|
-
|
335
|
-
|
336
|
-
|
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
|
-
’/public’ by default.
|
129
|
-
this.
|
128
|
+
’/public’ 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
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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">"<html><h2>Merb Error!</h2><p>#{ e.message } - (#{ e.class })\n"</span> <span class="ruby-operator"><<</span>
|
167
|
+
156: <span class="ruby-node">"#{(e.backtrace or []).join('<br />')}</p></html>"</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: [
|
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
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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">"No Matching Route!"</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">"No Matching Route!"</span>)
|
204
|
+
132: [<span class="ruby-value str">"<html><body>Error: no route matches!</body></html>"</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
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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">"/app/controllers/#{controller_name.snake_case}.rb"</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">"Error getting instance of '#{controller_name.camel_case}': #{$!}"</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-
|
315
|
-
33:
|
316
|
-
34: <span class="ruby-comment cmt">#
|
317
|
-
35: <span class="ruby-
|
318
|
-
36: <span class="ruby-
|
319
|
-
37: <span class="ruby-identifier">
|
320
|
-
38:
|
321
|
-
39: <span class="ruby-
|
322
|
-
40:
|
323
|
-
41:
|
324
|
-
42:
|
325
|
-
43: <span class="ruby-
|
326
|
-
44:
|
313
|
+
32: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">"Request: PATH_INFO: #{request.params[Mongrel::Const::PATH_INFO]}"</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">".html"</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">"Serving static file: #{path_info}"</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">
|
329
|
-
47: <span class="ruby-
|
330
|
-
48:
|
331
|
-
49:
|
332
|
-
50:
|
333
|
-
51:
|
334
|
-
52:
|
335
|
-
53: <span class="ruby-
|
336
|
-
54: <span class="ruby-comment cmt">#
|
337
|
-
55: <span class="ruby-comment cmt">#
|
338
|
-
56: <span class="ruby-
|
339
|
-
57:
|
340
|
-
58:
|
341
|
-
59:
|
342
|
-
60:
|
343
|
-
61:
|
344
|
-
62:
|
345
|
-
63: <span class="ruby-keyword kw">
|
346
|
-
64: <span class="ruby-keyword kw">
|
347
|
-
65:
|
348
|
-
66:
|
349
|
-
67:
|
350
|
-
68:
|
351
|
-
69: <span class="ruby-
|
352
|
-
70:
|
353
|
-
71:
|
354
|
-
72:
|
355
|
-
73: <span class="ruby-keyword kw">
|
356
|
-
74:
|
357
|
-
75:
|
358
|
-
76:
|
359
|
-
77:
|
360
|
-
78:
|
361
|
-
79:
|
362
|
-
80: <span class="ruby-
|
363
|
-
81:
|
364
|
-
82:
|
365
|
-
83:
|
366
|
-
84:
|
367
|
-
85:
|
368
|
-
86:
|
369
|
-
87:
|
370
|
-
88:
|
371
|
-
89:
|
372
|
-
90:
|
373
|
-
91:
|
374
|
-
92:
|
375
|
-
93:
|
376
|
-
94:
|
377
|
-
95:
|
378
|
-
96: <span class="ruby-
|
379
|
-
97: <span class="ruby-keyword kw">
|
380
|
-
98:
|
381
|
-
99:
|
382
|
-
100:
|
383
|
-
101:
|
384
|
-
102:
|
385
|
-
103:
|
386
|
-
104:
|
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">"Serving static file: #{path_info}"</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">"Routing to controller: #{controller.class} action: #{action}"</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">&&</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">></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">"Content-Type"</span>] = <span class="ruby-value str">"text/html"</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"><<</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">"X-SENDFILE: #{sendfile}"</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">"Response status: #{response.status}\n\n"</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>
|