Capcode 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -10,7 +10,13 @@ Capcode is a web microframework
10
10
 
11
11
  == FEATURES/PROBLEMS:
12
12
 
13
- === 0.5.1
13
+ === 0.6.1
14
+ * Major bugs corrections in haml and erb renderer ($%&! Windows)
15
+ * Major bugs corrections in Route.call
16
+ * Add Markaby layout support
17
+ * Rewrite blog-couchdb example
18
+
19
+ === 0.6.0
14
20
  * Add :root option to Capcode.run. This option allow you to specify the root directory for static files
15
21
  * Add :working_directory option to Capcode.run. This option allow you to specify the working directory
16
22
  * Of '/' route is not defined but /index.html exist, display index
@@ -207,39 +207,38 @@ If the regexp in the route does not match, all arguments will be
207
207
  275:
208
208
  276: <span class="ruby-identifier">nargs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">1</span>]
209
209
  277: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>][<span class="ruby-identifier">finalPath</span>] )
210
- 278:
211
- 279: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>( <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-node">&quot;^#{finalPath}&quot;</span> ), <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ) )
212
- 280: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
213
- 281: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-node">&quot;Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'&quot;</span>
214
- 282: <span class="ruby-keyword kw">else</span>
215
- 283: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>
216
- 284: <span class="ruby-keyword kw">end</span>
217
- 285:
218
- 286: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">nargs</span>
219
- 287: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
220
- 288: <span class="ruby-keyword kw">end</span>
221
- 289:
222
- 290: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
223
- 291: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
224
- 292: <span class="ruby-identifier">post</span>
225
- 293: <span class="ruby-keyword kw">end</span>
226
- 294: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
227
- 295: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
228
- 296: <span class="ruby-identifier">r</span>[<span class="ruby-value">1</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>
229
- 297: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
230
- 298: <span class="ruby-keyword kw">end</span>
231
- 299: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
232
- 300: <span class="ruby-keyword kw">else</span>
233
- 301: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
234
- 302: <span class="ruby-keyword kw">end</span>
235
- 303:
236
- 304: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
237
- 305: <span class="ruby-keyword kw">end</span>
238
- 306:
239
- 307: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
240
- 308: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
241
- 309: }
242
- 310: <span class="ruby-keyword kw">end</span>
210
+ 278: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>( <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-node">&quot;^#{finalPath}&quot;</span> ), <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ) )
211
+ 279: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
212
+ 280: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-node">&quot;Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'&quot;</span>
213
+ 281: <span class="ruby-keyword kw">else</span>
214
+ 282: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>.<span class="ruby-identifier">map</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">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)<span class="ruby-operator">?</span><span class="ruby-keyword kw">nil</span><span class="ruby-operator">:</span><span class="ruby-identifier">x</span> }
215
+ 283: <span class="ruby-keyword kw">end</span>
216
+ 284:
217
+ 285: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">nargs</span>
218
+ 286: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
219
+ 287: <span class="ruby-keyword kw">end</span>
220
+ 288:
221
+ 289: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
222
+ 290: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
223
+ 291: <span class="ruby-identifier">post</span>
224
+ 292: <span class="ruby-keyword kw">end</span>
225
+ 293: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
226
+ 294: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
227
+ 295: <span class="ruby-identifier">r</span>[<span class="ruby-value">1</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>
228
+ 296: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
229
+ 297: <span class="ruby-keyword kw">end</span>
230
+ 298: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
231
+ 299: <span class="ruby-keyword kw">else</span>
232
+ 300: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
233
+ 301: <span class="ruby-keyword kw">end</span>
234
+ 302:
235
+ 303: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
236
+ 304: <span class="ruby-keyword kw">end</span>
237
+ 305:
238
+ 306: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
239
+ 307: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
240
+ 308: }
241
+ 309: <span class="ruby-keyword kw">end</span>
243
242
  </pre>
244
243
  </div>
245
244
  </div>
@@ -278,10 +277,10 @@ Rack or What you want Helper
278
277
  <p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
279
278
  <div id="M000007_source" class="dyn-source">
280
279
  <pre>
281
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 317</span>
282
- 317: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
283
- 318: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
284
- 319: <span class="ruby-keyword kw">end</span>
280
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 316</span>
281
+ 316: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
282
+ 317: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
283
+ 318: <span class="ruby-keyword kw">end</span>
285
284
  </pre>
286
285
  </div>
287
286
  </div>
@@ -389,99 +388,99 @@ main.rb)
389
388
  <p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
390
389
  <div id="M000008_source" class="dyn-source">
391
390
  <pre>
392
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 334</span>
393
- 334: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
394
- 335: <span class="ruby-identifier">conf</span> = {
395
- 336: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
396
- 337: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;localhost&quot;</span>,
397
- 338: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:server</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
398
- 339: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
399
- 340: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{},
400
- 341: <span class="ruby-identifier">:pid</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:pid</span>]<span class="ruby-operator">||</span><span class="ruby-node">&quot;#{$0}.pid&quot;</span>,
401
- 342: <span class="ruby-identifier">:daemonize</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:daemonize</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">false</span>,
402
- 343: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:db_config</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;database.yml&quot;</span>,
403
- 344: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:root</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;.&quot;</span>,
404
- 345: <span class="ruby-identifier">:working_directory</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:working_directory</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">dirname</span>(<span class="ruby-identifier">$0</span>))
405
- 346: }
406
- 347:
407
- 348: <span class="ruby-comment cmt"># Run in the Working directory</span>
408
- 349: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:working_directory</span>] ) <span class="ruby-keyword kw">do</span>
409
- 350: <span class="ruby-comment cmt"># Set root directory for helpers</span>
410
- 351: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] )
411
- 352:
412
- 353: <span class="ruby-comment cmt"># Check that mongrel exists </span>
413
- 354: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
414
- 355: <span class="ruby-keyword kw">begin</span>
415
- 356: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
416
- 357: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;mongrel&quot;</span>
417
- 358: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
418
- 359: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
419
- 360: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;webrick&quot;</span>
420
- 361: <span class="ruby-keyword kw">end</span>
421
- 362: <span class="ruby-keyword kw">end</span>
422
- 363:
423
- 364: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</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-operator">|</span>
424
- 365: <span class="ruby-keyword kw">begin</span>
425
- 366: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.public_methods(true).include?( '__urls__' )&quot;</span>
426
- 367: <span class="ruby-identifier">u</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.__urls__&quot;</span>
427
- 368: <span class="ruby-identifier">u</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">_u</span><span class="ruby-operator">|</span>
428
- 369: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{_u}' already define !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ROUTES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
429
- 370: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
430
- 371: <span class="ruby-keyword kw">end</span>
431
- 372: <span class="ruby-keyword kw">end</span>
432
- 373: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
433
- 374: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
434
- 375: <span class="ruby-keyword kw">end</span>
435
- 376: <span class="ruby-keyword kw">end</span>
436
- 377:
437
- 378: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@@__ROUTES</span>)
438
- 379: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:session</span>] )
439
- 380: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
440
- 381: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
441
- 382: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
442
- 383: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
443
- 384: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
444
- 385: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>]) )
445
- 386:
446
- 387: <span class="ruby-comment cmt"># From rackup !!!</span>
447
- 388: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
448
- 389: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">&quot;1.9&quot;</span>
449
- 390: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
450
- 391: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
451
- 392: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
452
- 393: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
453
- 394: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
454
- 395: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
455
- 396: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
456
- 397: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
457
- 398: <span class="ruby-keyword kw">else</span>
458
- 399: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
459
- 400: <span class="ruby-keyword kw">end</span>
460
- 401:
461
- 402: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>], <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{Process.pid}&quot;</span>) }
462
- 403: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) }
463
- 404: <span class="ruby-keyword kw">end</span>
464
- 405:
465
- 406: <span class="ruby-comment cmt"># Start database</span>
466
- 407: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">&quot;db_connect&quot;</span>
467
- 408: <span class="ruby-identifier">db_connect</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:db_config</span>], <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>] )
468
- 409: <span class="ruby-keyword kw">end</span>
469
- 410:
470
- 411: <span class="ruby-comment cmt"># Start server</span>
471
- 412: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
472
- 413: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
473
- 414: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{conf[:host]}:#{conf[:port]}&quot;</span>
474
- 415: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
475
- 416: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
476
- 417: }
477
- 418: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
478
- 419: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{conf[:host]}:#{conf[:port]}&quot;</span>
479
- 420: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
480
- 421: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
481
- 422: }
482
- 423: <span class="ruby-keyword kw">end</span>
483
- 424: <span class="ruby-keyword kw">end</span>
484
- 425: <span class="ruby-keyword kw">end</span>
391
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 333</span>
392
+ 333: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
393
+ 334: <span class="ruby-identifier">conf</span> = {
394
+ 335: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
395
+ 336: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;localhost&quot;</span>,
396
+ 337: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:server</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
397
+ 338: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
398
+ 339: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{},
399
+ 340: <span class="ruby-identifier">:pid</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:pid</span>]<span class="ruby-operator">||</span><span class="ruby-node">&quot;#{$0}.pid&quot;</span>,
400
+ 341: <span class="ruby-identifier">:daemonize</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:daemonize</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">false</span>,
401
+ 342: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:db_config</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;database.yml&quot;</span>,
402
+ 343: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:root</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;.&quot;</span>,
403
+ 344: <span class="ruby-identifier">:working_directory</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:working_directory</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">dirname</span>(<span class="ruby-identifier">$0</span>))
404
+ 345: }
405
+ 346:
406
+ 347: <span class="ruby-comment cmt"># Run in the Working directory</span>
407
+ 348: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:working_directory</span>] ) <span class="ruby-keyword kw">do</span>
408
+ 349: <span class="ruby-comment cmt"># Set root directory for helpers</span>
409
+ 350: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] )
410
+ 351:
411
+ 352: <span class="ruby-comment cmt"># Check that mongrel exists </span>
412
+ 353: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
413
+ 354: <span class="ruby-keyword kw">begin</span>
414
+ 355: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
415
+ 356: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;mongrel&quot;</span>
416
+ 357: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
417
+ 358: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
418
+ 359: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;webrick&quot;</span>
419
+ 360: <span class="ruby-keyword kw">end</span>
420
+ 361: <span class="ruby-keyword kw">end</span>
421
+ 362:
422
+ 363: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</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-operator">|</span>
423
+ 364: <span class="ruby-keyword kw">begin</span>
424
+ 365: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.public_methods(true).include?( '__urls__' )&quot;</span>
425
+ 366: <span class="ruby-identifier">u</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.__urls__&quot;</span>
426
+ 367: <span class="ruby-identifier">u</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">_u</span><span class="ruby-operator">|</span>
427
+ 368: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{_u}' already define !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ROUTES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
428
+ 369: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
429
+ 370: <span class="ruby-keyword kw">end</span>
430
+ 371: <span class="ruby-keyword kw">end</span>
431
+ 372: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
432
+ 373: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
433
+ 374: <span class="ruby-keyword kw">end</span>
434
+ 375: <span class="ruby-keyword kw">end</span>
435
+ 376:
436
+ 377: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@@__ROUTES</span>)
437
+ 378: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:session</span>] )
438
+ 379: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
439
+ 380: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
440
+ 381: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
441
+ 382: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
442
+ 383: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
443
+ 384: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>]) )
444
+ 385:
445
+ 386: <span class="ruby-comment cmt"># From rackup !!!</span>
446
+ 387: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
447
+ 388: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">&quot;1.9&quot;</span>
448
+ 389: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
449
+ 390: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
450
+ 391: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
451
+ 392: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
452
+ 393: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
453
+ 394: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
454
+ 395: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
455
+ 396: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
456
+ 397: <span class="ruby-keyword kw">else</span>
457
+ 398: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
458
+ 399: <span class="ruby-keyword kw">end</span>
459
+ 400:
460
+ 401: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>], <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{Process.pid}&quot;</span>) }
461
+ 402: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) }
462
+ 403: <span class="ruby-keyword kw">end</span>
463
+ 404:
464
+ 405: <span class="ruby-comment cmt"># Start database</span>
465
+ 406: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">&quot;db_connect&quot;</span>
466
+ 407: <span class="ruby-identifier">db_connect</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:db_config</span>], <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>] )
467
+ 408: <span class="ruby-keyword kw">end</span>
468
+ 409:
469
+ 410: <span class="ruby-comment cmt"># Start server</span>
470
+ 411: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
471
+ 412: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
472
+ 413: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{conf[:host]}:#{conf[:port]}&quot;</span>
473
+ 414: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
474
+ 415: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
475
+ 416: }
476
+ 417: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
477
+ 418: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{conf[:host]}:#{conf[:port]}&quot;</span>
478
+ 419: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
479
+ 420: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
480
+ 421: }
481
+ 422: <span class="ruby-keyword kw">end</span>
482
+ 423: <span class="ruby-keyword kw">end</span>
483
+ 424: <span class="ruby-keyword kw">end</span>
485
484
  </pre>
486
485
  </div>
487
486
  </div>
@@ -1 +1 @@
1
- Mon, 08 Jun 2009 16:18:53 +0200
1
+ Mon, 15 Jun 2009 21:14:15 +0200
@@ -81,7 +81,7 @@ end</strong>
81
81
  <div id="README" class="page_shade">
82
82
  <div class="page">
83
83
  <div class="header">
84
- <div class="path">README / Mon Jun 08 16:06:13 +0200 2009</div>
84
+ <div class="path">README / Mon Jun 15 21:12:58 +0200 2009</div>
85
85
  </div>
86
86
 
87
87
  <h1><a href="../classes/Capcode.html">Capcode</a></h1>
@@ -98,7 +98,22 @@ Copyright (C) 2009 Gregoire Lejeune
98
98
  <a href="../classes/Capcode.html">Capcode</a> is a web microframework
99
99
  </p>
100
100
  <h2>FEATURES/PROBLEMS:</h2>
101
- <h3>0.5.1</h3>
101
+ <h3>0.6.1</h3>
102
+ <ul>
103
+ <li>Major bugs corrections in haml and erb renderer ($%&amp;! Windows)
104
+
105
+ </li>
106
+ <li>Major bugs corrections in Route.call
107
+
108
+ </li>
109
+ <li>Add Markaby layout support
110
+
111
+ </li>
112
+ <li>Rewrite blog-couchdb example
113
+
114
+ </li>
115
+ </ul>
116
+ <h3>0.6.0</h3>
102
117
  <ul>
103
118
  <li>Add :root option to <a
104
119
  href="../classes/Capcode.html#M000008">Capcode.run</a>. This option allow
@@ -81,7 +81,7 @@ end</strong>
81
81
  <div id="lib/capcode.rb" class="page_shade">
82
82
  <div class="page">
83
83
  <div class="header">
84
- <div class="path">lib/capcode.rb / Mon Jun 08 16:18:06 +0200 2009</div>
84
+ <div class="path">lib/capcode.rb / Mon Jun 15 19:58:55 +0200 2009</div>
85
85
  </div>
86
86
 
87
87
  <pre>
@@ -1,34 +1,39 @@
1
- $:.unshift( "../lib" )
2
1
  require 'rubygems'
3
2
  require 'capcode'
4
3
  require 'capcode/base/couchdb'
4
+ require 'capcode/render/markaby'
5
5
 
6
6
  class Story < Capcode::Base
7
7
  include Capcode::Resource
8
8
 
9
9
  property :title, String
10
10
  property :body, String
11
- property :date, String
11
+ property :create_at, String
12
+
13
+ default_sort :create_at
12
14
  end
13
15
 
14
16
  module Capcode
15
17
  class HTTPError
16
18
  def r404(f)
17
- "Pas glop !!! #{f} est inconnu !!!"
19
+ @file = f
18
20
  end
19
21
  end
20
22
 
21
- class Index < Route '/'
23
+ class Style < Route '/styles.css'
24
+ STYLE = File.read(__FILE__).gsub(/.*__END__/m, '')
25
+
22
26
  def get
23
- r = "<html><body>"
24
-
25
- story = Story.find( :all )
27
+ @response['Content-Type'] = 'text/css; charset=utf-8'
28
+ STYLE
29
+ end
30
+ end
26
31
 
27
- story.each do |s|
28
- r += "<h2>#{s.title}</h2><small>#{s.date} - <a href='#{URL( Remove, s.id, s.rev )}'>Delete this entry</a></small><p>#{s.body}</p>"
29
- end
32
+ class Index < Route '/'
33
+ def get
34
+ @story = Story.find( :all )
30
35
 
31
- r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
36
+ render( :markaby => :home )
32
37
  end
33
38
  end
34
39
 
@@ -41,22 +46,168 @@ module Capcode
41
46
 
42
47
  class Add < Route '/add'
43
48
  def get
44
- '
45
- <html><body>
46
- <h1>Add a new entry</h1>
47
- <form method="POST">
48
- Titre : <input type="text" name="title"><br />
49
- <textarea name="body"></textarea><br />
50
- <input type="submit">
51
- </form>
52
- </body></html>
53
- '
49
+ render( :markaby => :add )
54
50
  end
55
51
  def post
56
- Story.create( :title => params['title'], :body => params['body'], :date => Time.now.to_s )
52
+ Story.create( :title => params['title'], :body => params['body'], :create_at => Time.now )
57
53
  redirect( Index )
58
54
  end
59
55
  end
60
56
  end
61
57
 
62
- Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-couchdb.yml" )
58
+ module Capcode::Views
59
+ def r404
60
+ p "Pas glop !!! #{@file} est inconnu !!!"
61
+ end
62
+
63
+ def home
64
+ @story.each do |s|
65
+ h2 s.title
66
+ p.info do
67
+ _post_menu(s)
68
+ text s.create_at #.strftime('%B %M, %Y @ %H:%M ')
69
+ end
70
+ text s.body
71
+ end
72
+ end
73
+
74
+ def add
75
+ form :method => "POST" do
76
+ text "Titre :"
77
+ input :type => "text", :name => "title"; br
78
+ textarea :name => "body" do; end; br
79
+ input :type => "submit"
80
+ end
81
+ end
82
+
83
+ def layout
84
+ html do
85
+ head do
86
+ title 'My Blog'
87
+ link :rel => 'stylesheet', :type => 'text/css', :href => '/styles.css', :media => 'screen'
88
+ end
89
+ body do
90
+ h1 { a 'My Blog', :href => URL(Capcode::Index) }
91
+
92
+ div.wrapper! do
93
+ yield
94
+ end
95
+
96
+ p.footer! do
97
+ a 'New', :href => URL(Capcode::Add)
98
+ text ' &ndash; Powered by '
99
+ a 'Capcode', :href => 'http://capcode.rubyforge.org'
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def _post_menu(post)
106
+ text '('
107
+ a "Del", :href => URL( Capcode::Remove, post.id, post.rev )
108
+ text ')'
109
+ end
110
+
111
+ end
112
+
113
+ Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-couchdb.yml" )
114
+
115
+ __END__
116
+ * {
117
+ margin: 0;
118
+ padding: 0;
119
+ }
120
+
121
+ body {
122
+ font: normal 14px Arial, 'Bitstream Vera Sans', Helvetica, sans-serif;
123
+ line-height: 1.5;
124
+ }
125
+
126
+ h1, h2, h3, h4 {
127
+ font-family: Georgia, serif;
128
+ font-weight: normal;
129
+ }
130
+
131
+ h1 {
132
+ background-color: #EEE;
133
+ border-bottom: 5px solid #f06000;
134
+ outline: 5px solid #ab250c;
135
+ font-weight: normal;
136
+ font-size: 3em;
137
+ padding: 0.5em 0;
138
+ text-align: center;
139
+ }
140
+
141
+ h1 a { color: #143D55; text-decoration: none }
142
+ h1 a:hover { color: #143D55; text-decoration: underline }
143
+
144
+ h2 {
145
+ font-size: 2em;
146
+ color: #287AA9;
147
+ }
148
+
149
+ #wrapper {
150
+ margin: 3em auto;
151
+ width: 700px;
152
+ }
153
+
154
+ p {
155
+ margin-bottom: 1em;
156
+ }
157
+
158
+ p.info, p#footer {
159
+ color: #999;
160
+ margin-left: 1em;
161
+ }
162
+
163
+ p.info a, p#footer a {
164
+ color: #999;
165
+ }
166
+
167
+ p.info a:hover, p#footer a:hover {
168
+ text-decoration: none;
169
+ }
170
+
171
+ a {
172
+ color: #6F812D;
173
+ }
174
+
175
+ a:hover {
176
+ color: #9CB441;
177
+ }
178
+
179
+ hr {
180
+ border-width: 5px 0;
181
+ border-style: solid;
182
+ border-color: #9CB441;
183
+ border-bottom-color: #6F812D;
184
+ height: 0;
185
+ }
186
+
187
+ p#footer {
188
+ font-size: 0.9em;
189
+ margin: 0;
190
+ padding: 1em;
191
+ text-align: center;
192
+ }
193
+
194
+ label {
195
+ display: inline-block;
196
+ width: 100%;
197
+ }
198
+
199
+ input, textarea {
200
+ margin-bottom: 1em;
201
+ width: 200px;
202
+ }
203
+
204
+ input.submit {
205
+ float: left;
206
+ width: auto;
207
+ }
208
+
209
+ textarea {
210
+ font: normal 14px Arial, 'Bitstream Vera Sans', Helvetica, sans-serif;
211
+ height: 300px;
212
+ width: 400px;
213
+ }
@@ -30,7 +30,7 @@ module Capcode
30
30
  session = { :user => @you }
31
31
 
32
32
  # "Hello " + bold { you } + " it's '#{Time.now} !"
33
- render( :erb => :m_hello )
33
+ render( :markaby => :m_hello )
34
34
  end
35
35
  end
36
36
 
@@ -63,16 +63,23 @@ module Capcode
63
63
  end
64
64
 
65
65
  module Capcode::Views
66
- def m_hello
66
+ def layout
67
67
  html do
68
+ head do
69
+ title "Use a layout ;)"
70
+ end
68
71
  body do
72
+ yield
73
+ end
74
+ end
75
+ end
76
+
77
+ def m_hello
69
78
  p do
70
79
  text "Hello "
71
80
  b @you
72
81
  text " it's '#{Time.now} !"
73
82
  end
74
- end
75
- end
76
83
  end
77
84
  end
78
85
 
@@ -275,12 +275,11 @@ module Capcode
275
275
 
276
276
  nargs = self.class.__urls__[1]
277
277
  regexp = Regexp.new( self.class.__urls__[0][finalPath] )
278
-
279
278
  args = regexp.match( Rack::Utils.unescape(@request.path).gsub( Regexp.new( "^#{finalPath}" ), "" ).gsub( /^\//, "" ) )
280
279
  if args.nil?
281
280
  raise Capcode::ParameterError, "Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"
282
281
  else
283
- args = args.captures
282
+ args = args.captures.map { |x| (x.size == 0)?nil:x }
284
283
  end
285
284
 
286
285
  while args.size < nargs
@@ -7,14 +7,20 @@ module Capcode
7
7
  @@__ERB_PATH__ = p
8
8
  end
9
9
 
10
- def render_erb( f )
10
+ def render_erb( f ) #:nodoc:
11
11
  f = f.to_s
12
12
  if f.include? '..'
13
13
  return [403, {}, '403 - Invalid path']
14
14
  end
15
15
 
16
- unless( @@__ERB_PATH__[0].chr == "/" )
17
- @@__ERB_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__ERB_PATH__) )
16
+ if /Windows/.match( ENV['OS'] )
17
+ unless( /.:\\/.match( @@__ERB_PATH__[0] ) )
18
+ @@__ERB_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__ERB_PATH__) )
19
+ end
20
+ else
21
+ unless( @@__ERB_PATH__[0].chr == "/" )
22
+ @@__ERB_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__ERB_PATH__) )
23
+ end
18
24
  end
19
25
 
20
26
  f = f + ".rhtml" if File.extname( f ) != ".rhtml"
@@ -13,8 +13,14 @@ module Capcode
13
13
  return [403, {}, '403 - Invalid path']
14
14
  end
15
15
 
16
- unless( @@__HAML_PATH__[0].chr == "/" )
17
- @@__HAML_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__HAML_PATH__) )
16
+ if /Windows/.match( ENV['OS'] )
17
+ unless( /.:\\/.match( @@__ERB_PATH__[0] ) )
18
+ @@__HAML_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__HAML_PATH__) )
19
+ end
20
+ else
21
+ unless( @@__HAML_PATH__[0].chr == "/" )
22
+ @@__HAML_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__HAML_PATH__) )
23
+ end
18
24
  end
19
25
 
20
26
  f = f + ".haml" if File.extname( f ) != ".haml"
@@ -8,7 +8,13 @@ module Capcode
8
8
  module Helpers
9
9
  def render_markaby( f ) #:nodoc:
10
10
  f = f.to_s
11
- mab = Markaby::Builder.new({}, self) { self.send(f) }
11
+ mab = Markaby::Builder.new({}, self) {
12
+ if self.respond_to?(:layout)
13
+ layout { self.send(f) }
14
+ else
15
+ self.send(f)
16
+ end
17
+ }
12
18
  mab.to_s
13
19
  end
14
20
  end
@@ -1,3 +1,3 @@
1
1
  module Capcode
2
- CAPCOD_VERION="0.6.0"
2
+ CAPCOD_VERION="0.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Capcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Gr\xC3\xA9goire Lejeune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-09 00:00:00 +02:00
12
+ date: 2009-06-15 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency