Capcode 0.9.3 → 0.9.4
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.
- data/README.rdoc +7 -0
- data/doc/rdoc/classes/Capcode.html +421 -406
- data/doc/rdoc/classes/Capcode/HTTPError.html +14 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +137 -119
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +23 -1
- data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +4 -2
- data/examples/route.rb +68 -0
- data/examples/upload.rb +1 -1
- data/lib/capcode.rb +105 -74
- data/lib/capcode/ext/rack/urlmap.rb +59 -0
- data/lib/capcode/render/text.rb +1 -0
- data/lib/capcode/version.rb +1 -1
- metadata +42 -8
@@ -97,6 +97,20 @@ application :
|
|
97
97
|
end
|
98
98
|
</pre>
|
99
99
|
<p>
|
100
|
+
the rXXX method can also receive a second optional parameter corresponding
|
101
|
+
of the header‘s Hash :
|
102
|
+
</p>
|
103
|
+
<pre>
|
104
|
+
module Capcode
|
105
|
+
class HTTPError
|
106
|
+
def r404(f, h)
|
107
|
+
h['Content-Type'] = 'text/plain'
|
108
|
+
"You are here ---> X (#{f} point)"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
</pre>
|
113
|
+
<p>
|
100
114
|
Do the same (r500, r501, r403) to customize 500, 501, 403 errors
|
101
115
|
</p>
|
102
116
|
|
@@ -147,17 +147,14 @@ controllers
|
|
147
147
|
</div>
|
148
148
|
|
149
149
|
<div class="method-description">
|
150
|
-
<p>
|
151
|
-
@@<em>ARGS</em> = nil
|
152
|
-
</p>
|
153
150
|
<p><a class="source-toggle" href="#"
|
154
151
|
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
155
152
|
<div class="method-source-code" id="M000014-source">
|
156
153
|
<pre>
|
157
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
158
|
-
|
159
|
-
|
160
|
-
|
154
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 37</span>
|
155
|
+
37: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">args</span>
|
156
|
+
38: <span class="ruby-ivar">@args</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">nil</span>
|
157
|
+
39: <span class="ruby-keyword kw">end</span>
|
161
158
|
</pre>
|
162
159
|
</div>
|
163
160
|
</div>
|
@@ -177,10 +174,10 @@ controllers
|
|
177
174
|
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
178
175
|
<div class="method-source-code" id="M000015-source">
|
179
176
|
<pre>
|
180
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
181
|
-
|
182
|
-
|
183
|
-
|
177
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 40</span>
|
178
|
+
40: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">args=</span>(<span class="ruby-identifier">x</span>)
|
179
|
+
41: <span class="ruby-ivar">@args</span> = <span class="ruby-identifier">x</span>
|
180
|
+
42: <span class="ruby-keyword kw">end</span>
|
184
181
|
</pre>
|
185
182
|
</div>
|
186
183
|
</div>
|
@@ -222,21 +219,43 @@ then
|
|
222
219
|
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
223
220
|
<div class="method-source-code" id="M000019-source">
|
224
221
|
<pre>
|
225
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
222
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 204</span>
|
223
|
+
204: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">URL</span>( <span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span> )
|
224
|
+
205: <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
|
225
|
+
206: <span class="ruby-identifier">result</span> = {}
|
226
|
+
207:
|
227
|
+
208: <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_if</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> }
|
228
|
+
209:
|
229
|
+
210: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Class</span>
|
230
|
+
211: <span class="ruby-identifier">last_size</span> = <span class="ruby-value">0</span>
|
231
|
+
212:
|
232
|
+
213: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cpath</span>, <span class="ruby-identifier">regexp</span><span class="ruby-operator">|</span>
|
233
|
+
214: <span class="ruby-identifier">data</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">clone</span>
|
234
|
+
215:
|
235
|
+
216: <span class="ruby-identifier">n</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">regexp</span> ).<span class="ruby-identifier">number_of_captures</span>
|
236
|
+
217: <span class="ruby-identifier">equart</span> = (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">n</span>).<span class="ruby-identifier">abs</span>
|
237
|
+
218:
|
238
|
+
219: <span class="ruby-identifier">rtable</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/\\\(/</span>, <span class="ruby-value str">""</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/\\\)/</span>, <span class="ruby-value str">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-regexp re">/\([^\)]*\)/</span> )
|
239
|
+
220:
|
240
|
+
221: <span class="ruby-identifier">rtable</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
241
|
+
222: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value str">""</span>
|
242
|
+
223: <span class="ruby-identifier">cpath</span> = <span class="ruby-identifier">cpath</span> <span class="ruby-operator">+</span> <span class="ruby-node">"/#{data.shift}"</span>
|
243
|
+
224: <span class="ruby-keyword kw">else</span>
|
244
|
+
225: <span class="ruby-identifier">cpath</span> = <span class="ruby-identifier">cpath</span> <span class="ruby-operator">+</span> <span class="ruby-node">"/#{r}"</span>
|
245
|
+
226: <span class="ruby-keyword kw">end</span>
|
246
|
+
227: <span class="ruby-keyword kw">end</span>
|
247
|
+
228:
|
248
|
+
229: <span class="ruby-identifier">cpath</span> = (<span class="ruby-identifier">cpath</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"/"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">join</span>( <span class="ruby-value str">"/"</span> )).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/\/\//</span>, <span class="ruby-value str">"/"</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/\/$/</span>, <span class="ruby-value str">""</span> )
|
249
|
+
230: <span class="ruby-identifier">result</span>[<span class="ruby-identifier">equart</span>] = <span class="ruby-identifier">cpath</span>
|
250
|
+
231: <span class="ruby-keyword kw">end</span>
|
251
|
+
232:
|
252
|
+
233: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">result</span>[<span class="ruby-identifier">result</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">min</span>]
|
253
|
+
234: <span class="ruby-keyword kw">else</span>
|
254
|
+
235: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
|
255
|
+
236: <span class="ruby-keyword kw">end</span>
|
256
|
+
237:
|
257
|
+
238: (<span class="ruby-constant">ENV</span>[<span class="ruby-value str">'RACK_BASE_URI'</span>]<span class="ruby-operator">||</span><span class="ruby-value str">''</span>)<span class="ruby-operator">+</span><span class="ruby-identifier">path</span>
|
258
|
+
239: <span class="ruby-keyword kw">end</span>
|
240
259
|
</pre>
|
241
260
|
</div>
|
242
261
|
</div>
|
@@ -292,13 +311,12 @@ markup in an identifier.
|
|
292
311
|
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
293
312
|
<div class="method-source-code" id="M000020-source">
|
294
313
|
<pre>
|
295
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
265: <span class="ruby-keyword kw">end</span>
|
314
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 273</span>
|
315
|
+
273: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_for</span>( <span class="ruby-identifier">x</span> )
|
316
|
+
274: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">args</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_</span>.<span class="ruby-identifier">to_s</span> }.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">x</span>.<span class="ruby-identifier">to_s</span>)
|
317
|
+
275: <span class="ruby-keyword kw">yield</span>
|
318
|
+
276: <span class="ruby-keyword kw">end</span>
|
319
|
+
277: <span class="ruby-keyword kw">end</span>
|
302
320
|
</pre>
|
303
321
|
</div>
|
304
322
|
</div>
|
@@ -335,11 +353,11 @@ href="Helpers.html#M000017">json</a> => o )</tt>
|
|
335
353
|
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
336
354
|
<div class="method-source-code" id="M000017-source">
|
337
355
|
<pre>
|
338
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
356
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 148</span>
|
357
|
+
148: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">json</span>( <span class="ruby-identifier">d</span> ) <span class="ruby-comment cmt">## DELETE THIS IN 1.0.0</span>
|
358
|
+
149: <span class="ruby-identifier">warn</span>( <span class="ruby-value str">"json is deprecated and will be removed in version 1.0, please use `render( :json => ... )'"</span> )
|
359
|
+
150: <span class="ruby-identifier">render</span> <span class="ruby-identifier">:json</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">d</span>
|
360
|
+
151: <span class="ruby-keyword kw">end</span>
|
343
361
|
</pre>
|
344
362
|
</div>
|
345
363
|
</div>
|
@@ -398,17 +416,17 @@ href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection">en
|
|
398
416
|
onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
|
399
417
|
<div class="method-source-code" id="M000018-source">
|
400
418
|
<pre>
|
401
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
419
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 180</span>
|
420
|
+
180: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">redirect</span>( <span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span> )
|
421
|
+
181: <span class="ruby-identifier">httpCode</span> = <span class="ruby-value">302</span>
|
422
|
+
182:
|
423
|
+
183: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Fixnum</span> )
|
424
|
+
184: <span class="ruby-identifier">httpCode</span> = <span class="ruby-identifier">klass</span>
|
425
|
+
185: <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">shift</span>
|
426
|
+
186: <span class="ruby-keyword kw">end</span>
|
427
|
+
187:
|
428
|
+
188: [<span class="ruby-identifier">httpCode</span>, {<span class="ruby-value str">'Location'</span> =<span class="ruby-operator">></span> <span class="ruby-constant">URL</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)}, <span class="ruby-value str">''</span>]
|
429
|
+
189: <span class="ruby-keyword kw">end</span>
|
412
430
|
</pre>
|
413
431
|
</div>
|
414
432
|
</div>
|
@@ -505,69 +523,69 @@ If you use the WebDav renderer, you can use the option
|
|
505
523
|
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
506
524
|
<div class="method-source-code" id="M000016-source">
|
507
525
|
<pre>
|
508
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
526
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 74</span>
|
527
|
+
74: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>( <span class="ruby-identifier">hash</span> )
|
528
|
+
75: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Hash</span>
|
529
|
+
76: <span class="ruby-identifier">render_type</span> = <span class="ruby-keyword kw">nil</span>
|
530
|
+
77: <span class="ruby-identifier">possible_code_renderer</span> = <span class="ruby-keyword kw">nil</span>
|
531
|
+
78:
|
532
|
+
79: <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
|
533
|
+
80: <span class="ruby-keyword kw">begin</span>
|
534
|
+
81: <span class="ruby-identifier">gem</span> <span class="ruby-node">"capcode-render-#{key.to_s}"</span>
|
535
|
+
82: <span class="ruby-identifier">require</span> <span class="ruby-node">"capcode/render/#{key.to_s}"</span>
|
536
|
+
83: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">LoadError</span>
|
537
|
+
84: <span class="ruby-keyword kw">nil</span>
|
538
|
+
85: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
539
|
+
86: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-node">"Hum... The #{key} renderer is malformated! Please try to install a new version or use an other renderer!"</span>, <span class="ruby-identifier">caller</span>
|
540
|
+
87: <span class="ruby-keyword kw">end</span>
|
541
|
+
88:
|
542
|
+
89: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">"render_#{key.to_s}"</span>)
|
543
|
+
90: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span>
|
544
|
+
91: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-node">"Can't use multiple renderer (`#{render_type}' and `#{key}') !"</span>, <span class="ruby-identifier">caller</span>
|
545
|
+
92: <span class="ruby-keyword kw">end</span>
|
546
|
+
93: <span class="ruby-identifier">render_type</span> = <span class="ruby-identifier">key</span>
|
547
|
+
94: <span class="ruby-keyword kw">end</span>
|
548
|
+
95:
|
549
|
+
96: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Fixnum</span>
|
550
|
+
97: <span class="ruby-identifier">possible_code_renderer</span> = <span class="ruby-identifier">key</span>
|
551
|
+
98: <span class="ruby-keyword kw">end</span>
|
552
|
+
99: <span class="ruby-keyword kw">end</span>
|
553
|
+
100:
|
554
|
+
101: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">possible_code_renderer</span>.<span class="ruby-identifier">nil?</span>
|
555
|
+
102: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-value str">"Renderer type not specified!"</span>, <span class="ruby-identifier">caller</span>
|
556
|
+
103: <span class="ruby-keyword kw">end</span>
|
557
|
+
104:
|
558
|
+
105: <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">"render_#{render_type.to_s}"</span>)
|
559
|
+
106: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">possible_code_renderer</span>.<span class="ruby-identifier">nil?</span>
|
560
|
+
107: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-node">"#{render_type} renderer not present ! please require 'capcode/render/#{render_type}'"</span>, <span class="ruby-identifier">caller</span>
|
561
|
+
108: <span class="ruby-keyword kw">else</span>
|
562
|
+
109: <span class="ruby-identifier">code</span> = <span class="ruby-identifier">possible_code_renderer</span>
|
563
|
+
110: <span class="ruby-identifier">body</span> = <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">possible_code_renderer</span>)
|
564
|
+
111: <span class="ruby-identifier">header</span> = {}
|
565
|
+
112: <span class="ruby-identifier">hash</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>
|
566
|
+
113: <span class="ruby-identifier">k</span> = <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/_/</span>).<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">capitalize</span>}.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"-"</span>)
|
567
|
+
114: <span class="ruby-identifier">header</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
568
|
+
115: <span class="ruby-keyword kw">end</span>
|
569
|
+
116:
|
570
|
+
117: [<span class="ruby-identifier">code</span>, <span class="ruby-identifier">header</span>, <span class="ruby-identifier">body</span>]
|
571
|
+
118: <span class="ruby-keyword kw">end</span>
|
572
|
+
119: <span class="ruby-keyword kw">else</span>
|
573
|
+
120: <span class="ruby-identifier">render_name</span> = <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">render_type</span>)
|
574
|
+
121: <span class="ruby-identifier">content_type</span> = <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:content_type</span>)
|
575
|
+
122: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">content_type</span>.<span class="ruby-identifier">nil?</span>
|
576
|
+
123: <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-identifier">content_type</span>
|
577
|
+
124: <span class="ruby-keyword kw">end</span>
|
578
|
+
125:
|
579
|
+
126: <span class="ruby-keyword kw">begin</span>
|
580
|
+
127: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>( <span class="ruby-node">"render_#{render_type.to_s}"</span>, <span class="ruby-identifier">render_name</span>, <span class="ruby-identifier">hash</span> )
|
581
|
+
128: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
582
|
+
129: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-node">"Error rendering `#{render_type.to_s}' : #{e.message}"</span>, <span class="ruby-identifier">caller</span>
|
583
|
+
130: <span class="ruby-keyword kw">end</span>
|
584
|
+
131: <span class="ruby-keyword kw">end</span>
|
585
|
+
132: <span class="ruby-keyword kw">else</span>
|
586
|
+
133: <span class="ruby-identifier">render</span>( <span class="ruby-identifier">:text</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">hash</span> )
|
587
|
+
134: <span class="ruby-keyword kw">end</span>
|
588
|
+
135: <span class="ruby-keyword kw">end</span>
|
571
589
|
</pre>
|
572
590
|
</div>
|
573
591
|
</div>
|
@@ -601,13 +619,13 @@ the <a href="Helpers.html#M000021">static</a> directory on the server
|
|
601
619
|
onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
|
602
620
|
<div class="method-source-code" id="M000021-source">
|
603
621
|
<pre>
|
604
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
622
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 283</span>
|
623
|
+
283: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">static</span>
|
624
|
+
284: {
|
625
|
+
285: <span class="ruby-identifier">:uri</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>,
|
626
|
+
286: <span class="ruby-identifier">:path</span> =<span class="ruby-operator">></span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>( <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>) ) )
|
627
|
+
287: }
|
628
|
+
288: <span class="ruby-keyword kw">end</span>
|
611
629
|
</pre>
|
612
630
|
</div>
|
613
631
|
</div>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Fri, 28 May 2010 00:38:59 +0200
|
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Fri Mar 05 13:50:01 +0100 2010</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -91,6 +91,28 @@ href="http://www.algorithmique.net/capcode">www.algorithmique.net/capcode</a>/
|
|
91
91
|
<a href="../classes/Capcode.html">Capcode</a> is a web microframework
|
92
92
|
</p>
|
93
93
|
<h2>FEATURES/PROBLEMS:</h2>
|
94
|
+
<h3>0.9.4</h3>
|
95
|
+
<ul>
|
96
|
+
<li>You can now create a controler without specifying the root name. If so the
|
97
|
+
name of the class will be used. <a
|
98
|
+
href="http://github.com/glejeune/Capcode/tree/master/examples/route.rb">see
|
99
|
+
example route.rb</a>.
|
100
|
+
|
101
|
+
</li>
|
102
|
+
<li>Major bug correction in Route
|
103
|
+
|
104
|
+
</li>
|
105
|
+
<li>render :text => … now really render text
|
106
|
+
|
107
|
+
</li>
|
108
|
+
<li>rXXX methods in HTTPError can now receive a second optional parameter
|
109
|
+
corresponding to headers
|
110
|
+
|
111
|
+
</li>
|
112
|
+
<li>Huge bug correction in Capcode::Helpers.URL
|
113
|
+
|
114
|
+
</li>
|
115
|
+
</ul>
|
94
116
|
<h3>0.9.3</h3>
|
95
117
|
<ul>
|
96
118
|
<li>Major bug correction
|
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Fri May 28 00:38:51 +0200 2010</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -84,13 +84,15 @@ Please read the README.rdoc file !
|
|
84
84
|
logger
|
85
85
|
optparse
|
86
86
|
irb
|
87
|
-
|
87
|
+
active_support
|
88
88
|
capcode/version
|
89
89
|
capcode/core_ext
|
90
90
|
capcode/helpers/auth
|
91
91
|
capcode/render/text
|
92
92
|
capcode/configuration
|
93
93
|
capcode/filters
|
94
|
+
capcode/ext/rack/urlmap
|
95
|
+
capcode/response
|
94
96
|
mongrel
|
95
97
|
</div>
|
96
98
|
</div>
|
data/examples/route.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
|
4
|
+
module Capcode
|
5
|
+
class HTTPError
|
6
|
+
def r404(f, h)
|
7
|
+
h['Content-Type'] = 'text/plain'
|
8
|
+
"You are here ---> X (#{f})"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Access via GET /index
|
13
|
+
class Index < Route
|
14
|
+
def get
|
15
|
+
render :markaby => :index
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Acces via GET /foo_bar
|
20
|
+
class FooBar < Route
|
21
|
+
def get
|
22
|
+
render "Hello FooBar!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Access via GET /bar
|
27
|
+
class Foo < Route '/bar'
|
28
|
+
def get
|
29
|
+
render "Hello Foo!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class RegexpOne < Route '/one/(.*)'
|
34
|
+
def get(x)
|
35
|
+
render "RegexpOne with '#{x}'"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class RegexpTwo < Route '/two/([^\/]*)/two'
|
40
|
+
def get(x)
|
41
|
+
render "RegexpTwo with '#{x}'"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class RegexpThree < Route '/three/with/([^\/]*)/and/(.*)', '/three/(.*)'
|
46
|
+
def get(x, y)
|
47
|
+
render "RegexpThree with '#{x}' and '#{y}'"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
module Capcode::Views
|
54
|
+
def index
|
55
|
+
html do
|
56
|
+
body do
|
57
|
+
a "FooBar", :href => URL(Capcode::FooBar); br;
|
58
|
+
a "Foo", :href => URL(Capcode::Foo); br;
|
59
|
+
a "RegexpOne", :href => URL(Capcode::RegexpOne, "Hello World"); br;
|
60
|
+
a "RegexpTwo", :href => URL(Capcode::RegexpTwo, "Hello World"); br;
|
61
|
+
a "RegexpThree", :href => URL(Capcode::RegexpThree, "Hello", "World"); br;
|
62
|
+
a "RegexpThree (again)", :href => URL(Capcode::RegexpThree, "Hello World"); br;
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Capcode.run()
|