Capcode 0.9.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.rdoc +3 -0
  2. data/examples/rest.log +15 -0
  3. data/examples/static.rb +12 -0
  4. data/examples/static/static-index.html +1 -0
  5. data/lib/capcode.rb +14 -344
  6. data/lib/capcode/filters.rb +1 -0
  7. data/lib/capcode/helpers.rb +246 -0
  8. data/lib/capcode/http_error.rb +49 -0
  9. data/lib/capcode/static_files.rb +68 -0
  10. data/lib/capcode/version.rb +1 -1
  11. metadata +46 -61
  12. data/doc/rdoc/classes/Capcode.html +0 -1076
  13. data/doc/rdoc/classes/Capcode/Base.html +0 -136
  14. data/doc/rdoc/classes/Capcode/Configuration.html +0 -290
  15. data/doc/rdoc/classes/Capcode/HTTPError.html +0 -148
  16. data/doc/rdoc/classes/Capcode/Helpers.html +0 -674
  17. data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +0 -219
  18. data/doc/rdoc/classes/Capcode/Resource.html +0 -111
  19. data/doc/rdoc/classes/Capcode/StaticFiles.html +0 -199
  20. data/doc/rdoc/classes/Capcode/Views.html +0 -112
  21. data/doc/rdoc/created.rid +0 -1
  22. data/doc/rdoc/files/AUTHORS.html +0 -107
  23. data/doc/rdoc/files/COPYING.html +0 -531
  24. data/doc/rdoc/files/README_rdoc.html +0 -887
  25. data/doc/rdoc/files/lib/capcode/base/db_rb.html +0 -101
  26. data/doc/rdoc/files/lib/capcode/configuration_rb.html +0 -101
  27. data/doc/rdoc/files/lib/capcode/filters_rb.html +0 -101
  28. data/doc/rdoc/files/lib/capcode/helpers/auth_rb.html +0 -101
  29. data/doc/rdoc/files/lib/capcode/render/text_rb.html +0 -101
  30. data/doc/rdoc/files/lib/capcode_rb.html +0 -144
  31. data/doc/rdoc/fr_class_index.html +0 -35
  32. data/doc/rdoc/fr_file_index.html +0 -35
  33. data/doc/rdoc/fr_method_index.html +0 -56
  34. data/doc/rdoc/index.html +0 -24
  35. data/doc/rdoc/rdoc-style.css +0 -208
  36. data/lib/capcode.rbSAVE +0 -881
@@ -1,674 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: Capcode::Helpers</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Module</strong></td>
53
- <td class="class-name-in-header">Capcode::Helpers</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../../files/lib/capcode_rb.html">
59
- lib/capcode.rb
60
- </a>
61
- <br />
62
- <a href="../../files/lib/capcode/render/text_rb.html">
63
- lib/capcode/render/text.rb
64
- </a>
65
- <br />
66
- <a href="../../files/lib/capcode/helpers/auth_rb.html">
67
- lib/capcode/helpers/auth.rb
68
- </a>
69
- <br />
70
- </td>
71
- </tr>
72
-
73
- </table>
74
- </div>
75
- <!-- banner header -->
76
-
77
- <div id="bodyContent">
78
-
79
-
80
-
81
- <div id="contextContent">
82
-
83
- <div id="description">
84
- <p>
85
- <a href="Helpers.html">Helpers</a> contains methods available in your
86
- controllers
87
- </p>
88
-
89
- </div>
90
-
91
-
92
- </div>
93
-
94
- <div id="method-list">
95
- <h3 class="section-bar">Methods</h3>
96
-
97
- <div class="name-list">
98
- <a href="#M000020">URL</a>&nbsp;&nbsp;
99
- <a href="#M000015">args</a>&nbsp;&nbsp;
100
- <a href="#M000016">args=</a>&nbsp;&nbsp;
101
- <a href="#M000021">content_for</a>&nbsp;&nbsp;
102
- <a href="#M000018">json</a>&nbsp;&nbsp;
103
- <a href="#M000023">log</a>&nbsp;&nbsp;
104
- <a href="#M000019">redirect</a>&nbsp;&nbsp;
105
- <a href="#M000017">render</a>&nbsp;&nbsp;
106
- <a href="#M000022">static</a>&nbsp;&nbsp;
107
- </div>
108
- </div>
109
-
110
- </div>
111
-
112
-
113
- <!-- if includes -->
114
- <div id="includes">
115
- <h3 class="section-bar">Included Modules</h3>
116
-
117
- <div id="includes-list">
118
- <span class="include-name"><a href="Helpers/Authorization.html">Authorization</a></span>
119
- </div>
120
- </div>
121
-
122
- <div id="section">
123
-
124
- <div id="class-list">
125
- <h3 class="section-bar">Classes and Modules</h3>
126
-
127
- Module <a href="Helpers/Authorization.html" class="link">Capcode::Helpers::Authorization</a><br />
128
-
129
- </div>
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
- <!-- if method_list -->
138
- <div id="methods">
139
- <h3 class="section-bar">Public Class methods</h3>
140
-
141
- <div id="method-M000015" class="method-detail">
142
- <a name="M000015"></a>
143
-
144
- <div class="method-heading">
145
- <a href="#M000015" class="method-signature">
146
- <span class="method-name">args</span><span class="method-args">()</span>
147
- </a>
148
- </div>
149
-
150
- <div class="method-description">
151
- <p><a class="source-toggle" href="#"
152
- onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
153
- <div class="method-source-code" id="M000015-source">
154
- <pre>
155
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 36</span>
156
- 36: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">args</span>
157
- 37: <span class="ruby-ivar">@args</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">nil</span>
158
- 38: <span class="ruby-keyword kw">end</span>
159
- </pre>
160
- </div>
161
- </div>
162
- </div>
163
-
164
- <div id="method-M000016" class="method-detail">
165
- <a name="M000016"></a>
166
-
167
- <div class="method-heading">
168
- <a href="#M000016" class="method-signature">
169
- <span class="method-name">args=</span><span class="method-args">(x)</span>
170
- </a>
171
- </div>
172
-
173
- <div class="method-description">
174
- <p><a class="source-toggle" href="#"
175
- onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
176
- <div class="method-source-code" id="M000016-source">
177
- <pre>
178
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 39</span>
179
- 39: <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>)
180
- 40: <span class="ruby-ivar">@args</span> = <span class="ruby-identifier">x</span>
181
- 41: <span class="ruby-keyword kw">end</span>
182
- </pre>
183
- </div>
184
- </div>
185
- </div>
186
-
187
- <h3 class="section-bar">Public Instance methods</h3>
188
-
189
- <div id="method-M000020" class="method-detail">
190
- <a name="M000020"></a>
191
-
192
- <div class="method-heading">
193
- <a href="#M000020" class="method-signature">
194
- <span class="method-name">URL</span><span class="method-args">( klass, *a )</span>
195
- </a>
196
- </div>
197
-
198
- <div class="method-description">
199
- <p>
200
- Builds an <a href="Helpers.html#M000020">URL</a> route to a controller or a
201
- path
202
- </p>
203
- <p>
204
- if you declare the controller Hello :
205
- </p>
206
- <pre>
207
- module Capcode
208
- class Hello &lt; Route '/hello/(.*)'
209
- ...
210
- end
211
- end
212
- </pre>
213
- <p>
214
- then
215
- </p>
216
- <pre>
217
- URL( Capcode::Hello, &quot;you&quot; ) # =&gt; /hello/you
218
- </pre>
219
- <p><a class="source-toggle" href="#"
220
- onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
221
- <div class="method-source-code" id="M000020-source">
222
- <pre>
223
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 203</span>
224
- 203: <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> )
225
- 204: <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
226
- 205: <span class="ruby-identifier">result</span> = {}
227
- 206:
228
- 207: <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> }
229
- 208:
230
- 209: <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>
231
- 210: <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">data</span><span class="ruby-operator">|</span>
232
- 211: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">clone</span>
233
- 212:
234
- 213: <span class="ruby-identifier">n</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:regexp</span>] ).<span class="ruby-identifier">number_of_captures</span>
235
- 214: <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>
236
- 215:
237
- 216: <span class="ruby-identifier">rtable</span> = <span class="ruby-identifier">data</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">&quot;&quot;</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/\\\)/</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-regexp re">/\([^\)]*\)/</span> )
238
- 217: <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>
239
- 218: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
240
- 219: <span class="ruby-identifier">cpath</span> = <span class="ruby-identifier">cpath</span> <span class="ruby-operator">+</span> <span class="ruby-node">&quot;/#{args.shift}&quot;</span>
241
- 220: <span class="ruby-keyword kw">else</span>
242
- 221: <span class="ruby-identifier">cpath</span> = <span class="ruby-identifier">cpath</span> <span class="ruby-operator">+</span> <span class="ruby-node">&quot;/#{r}&quot;</span>
243
- 222: <span class="ruby-keyword kw">end</span>
244
- 223: <span class="ruby-keyword kw">end</span>
245
- 224:
246
- 225: <span class="ruby-identifier">cpath</span> = (<span class="ruby-identifier">cpath</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">join</span>( <span class="ruby-value str">&quot;/&quot;</span> )) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
247
- 226: <span class="ruby-identifier">cpath</span> = <span class="ruby-identifier">cpath</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/(\/){2,}/</span>, <span class="ruby-value str">&quot;/&quot;</span> )
248
- 227: <span class="ruby-identifier">result</span>[<span class="ruby-identifier">equart</span>] = <span class="ruby-identifier">cpath</span>
249
- 228: <span class="ruby-keyword kw">end</span>
250
- 229:
251
- 230: <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>]
252
- 231: <span class="ruby-keyword kw">else</span>
253
- 232: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
254
- 233: <span class="ruby-keyword kw">end</span>
255
- 234:
256
- 235: (<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>
257
- 236: <span class="ruby-keyword kw">end</span>
258
- </pre>
259
- </div>
260
- </div>
261
- </div>
262
-
263
- <div id="method-M000021" class="method-detail">
264
- <a name="M000021"></a>
265
-
266
- <div class="method-heading">
267
- <a href="#M000021" class="method-signature">
268
- <span class="method-name">content_for</span><span class="method-args">( x ) {|| ...}</span>
269
- </a>
270
- </div>
271
-
272
- <div class="method-description">
273
- <p>
274
- Calling <a href="Helpers.html#M000021">content_for</a> stores a block of
275
- markup in an identifier.
276
- </p>
277
- <pre>
278
- module Capcode
279
- class ContentFor &lt; Route '/'
280
- def get
281
- render( :markaby =&gt; :page, :layout =&gt; :layout )
282
- end
283
- end
284
- end
285
-
286
- module Capcode::Views
287
- def layout
288
- html do
289
- head do
290
- yield :header
291
- end
292
- body do
293
- yield :content
294
- end
295
- end
296
- end
297
-
298
- def page
299
- content_for :header do
300
- title &quot;This is the title!&quot;
301
- end
302
-
303
- content_for :content do
304
- p &quot;this is the content!&quot;
305
- end
306
- end
307
- end
308
- </pre>
309
- <p><a class="source-toggle" href="#"
310
- onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
311
- <div class="method-source-code" id="M000021-source">
312
- <pre>
313
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 270</span>
314
- 270: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_for</span>( <span class="ruby-identifier">x</span> )
315
- 271: <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>)
316
- 272: <span class="ruby-keyword kw">yield</span>
317
- 273: <span class="ruby-keyword kw">end</span>
318
- 274: <span class="ruby-keyword kw">end</span>
319
- </pre>
320
- </div>
321
- </div>
322
- </div>
323
-
324
- <div id="method-M000018" class="method-detail">
325
- <a name="M000018"></a>
326
-
327
- <div class="method-heading">
328
- <a href="#M000018" class="method-signature">
329
- <span class="method-name">json</span><span class="method-args">( d )</span>
330
- </a>
331
- </div>
332
-
333
- <div class="method-description">
334
- <p>
335
- Help you to return a JSON response
336
- </p>
337
- <pre>
338
- module Capcode
339
- class JsonResponse &lt; Route '/json/([^\/]*)/(.*)'
340
- def get( arg1, arg2 )
341
- json( { :1 =&gt; arg1, :2 =&gt; arg2 })
342
- end
343
- end
344
- end
345
- </pre>
346
- <p>
347
- <b>DEPRECATED</b>, please use <tt><a
348
- href="Helpers.html#M000017">render</a>( :<a
349
- href="Helpers.html#M000018">json</a> =&gt; o )</tt>
350
- </p>
351
- <p><a class="source-toggle" href="#"
352
- onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
353
- <div class="method-source-code" id="M000018-source">
354
- <pre>
355
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 147</span>
356
- 147: <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>
357
- 148: <span class="ruby-identifier">warn</span>( <span class="ruby-value str">&quot;json is deprecated and will be removed in version 1.0, please use `render( :json =&gt; ... )'&quot;</span> )
358
- 149: <span class="ruby-identifier">render</span> <span class="ruby-identifier">:json</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">d</span>
359
- 150: <span class="ruby-keyword kw">end</span>
360
- </pre>
361
- </div>
362
- </div>
363
- </div>
364
-
365
- <div id="method-M000023" class="method-detail">
366
- <a name="M000023"></a>
367
-
368
- <div class="method-heading">
369
- <a href="#M000023" class="method-signature">
370
- <span class="method-name">log</span><span class="method-args">()</span>
371
- </a>
372
- </div>
373
-
374
- <div class="method-description">
375
- <p>
376
- Use the Rack logger
377
- </p>
378
- <pre>
379
- log.write( &quot;This is a log !&quot; )
380
- </pre>
381
- <p><a class="source-toggle" href="#"
382
- onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
383
- <div class="method-source-code" id="M000023-source">
384
- <pre>
385
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 290</span>
386
- 290: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">log</span>
387
- 291: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">logger</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">env</span>[<span class="ruby-value str">'rack.errors'</span>]
388
- 292: <span class="ruby-keyword kw">end</span>
389
- </pre>
390
- </div>
391
- </div>
392
- </div>
393
-
394
- <div id="method-M000019" class="method-detail">
395
- <a name="M000019"></a>
396
-
397
- <div class="method-heading">
398
- <a href="#M000019" class="method-signature">
399
- <span class="method-name">redirect</span><span class="method-args">( klass, *a )</span>
400
- </a>
401
- </div>
402
-
403
- <div class="method-description">
404
- <p>
405
- Send a <a href="Helpers.html#M000019">redirect</a> response
406
- </p>
407
- <pre>
408
- module Capcode
409
- class Hello &lt; Route '/hello/(.*)'
410
- def get( you )
411
- if you.nil?
412
- redirect( WhoAreYou )
413
- else
414
- ...
415
- end
416
- end
417
- end
418
- end
419
- </pre>
420
- <p>
421
- The first parameter can be a controller class name
422
- </p>
423
- <pre>
424
- redirect( MyController )
425
- </pre>
426
- <p>
427
- it can be a string path
428
- </p>
429
- <pre>
430
- redirect( &quot;/path/to/my/resource&quot; )
431
- </pre>
432
- <p>
433
- it can be an http status code (by default <tt><a
434
- href="Helpers.html#M000019">redirect</a></tt> use the http status code 302)
435
- </p>
436
- <pre>
437
- redirect( 304, MyController )
438
- </pre>
439
- <p>
440
- For more informations about HTTP status, see <a
441
- href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection">en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection</a>
442
- </p>
443
- <p><a class="source-toggle" href="#"
444
- onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
445
- <div class="method-source-code" id="M000019-source">
446
- <pre>
447
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 179</span>
448
- 179: <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> )
449
- 180: <span class="ruby-identifier">httpCode</span> = <span class="ruby-value">302</span>
450
- 181:
451
- 182: <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> )
452
- 183: <span class="ruby-identifier">httpCode</span> = <span class="ruby-identifier">klass</span>
453
- 184: <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">shift</span>
454
- 185: <span class="ruby-keyword kw">end</span>
455
- 186:
456
- 187: [<span class="ruby-identifier">httpCode</span>, {<span class="ruby-value str">'Location'</span> =<span class="ruby-operator">&gt;</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>]
457
- 188: <span class="ruby-keyword kw">end</span>
458
- </pre>
459
- </div>
460
- </div>
461
- </div>
462
-
463
- <div id="method-M000017" class="method-detail">
464
- <a name="M000017"></a>
465
-
466
- <div class="method-heading">
467
- <a href="#M000017" class="method-signature">
468
- <span class="method-name">render</span><span class="method-args">( hash )</span>
469
- </a>
470
- </div>
471
-
472
- <div class="method-description">
473
- <p>
474
- Render a view
475
- </p>
476
- <p>
477
- <a href="Helpers.html#M000017">render</a>&#8216;s parameter can be a Hash
478
- or a string. Passing a string is equivalent to do
479
- </p>
480
- <pre>
481
- render( :text =&gt; string )
482
- </pre>
483
- <p>
484
- If you want to use a specific renderer, use one of this options :
485
- </p>
486
- <ul>
487
- <li>:markaby =&gt; :my_func : :my_func must be defined in <a
488
- href="Views.html">Capcode::Views</a>
489
-
490
- </li>
491
- <li>:erb =&gt; :my_erb_file : this suppose that&#8216;s my_erb_file.rhtml exist
492
- in erb_path
493
-
494
- </li>
495
- <li>:haml =&gt; :my_haml_file : this suppose that&#8216;s my_haml_file.haml
496
- exist in haml_path
497
-
498
- </li>
499
- <li>:sass =&gt; :my_sass_file : this suppose that&#8216;s my_sass_file.sass
500
- exist in sass_path
501
-
502
- </li>
503
- <li>:text =&gt; &quot;my text&quot;
504
-
505
- </li>
506
- <li>:<a href="Helpers.html#M000018">json</a> =&gt; MyObject : this suppose
507
- that&#8216;s MyObject respond to .to_json
508
-
509
- </li>
510
- <li>:<a href="Helpers.html#M000022">static</a> =&gt; &quot;my_file.xxx&quot; :
511
- this suppose that&#8216;s my_file.xxx exist in the <a
512
- href="Helpers.html#M000022">static</a> directory
513
-
514
- </li>
515
- <li>:xml =&gt; :my_func : :my_func must be defined in <a
516
- href="Views.html">Capcode::Views</a>
517
-
518
- </li>
519
- <li>:webdav =&gt; /path/to/root
520
-
521
- </li>
522
- </ul>
523
- <p>
524
- Or you can use a &quot;HTTP code&quot; renderer :
525
- </p>
526
- <pre>
527
- render 200 =&gt; &quot;Ok&quot;, :server =&gt; &quot;Capcode #{Capcode::CAPCOD_VERION}&quot;, ...
528
- </pre>
529
- <p>
530
- If you want to use a specific layout, you can specify it with option
531
- </p>
532
- <pre>
533
- :layout
534
- </pre>
535
- <p>
536
- If you want to change the Content-Type, you can specify it with option
537
- </p>
538
- <pre>
539
- :content_type
540
- </pre>
541
- <p>
542
- Note that this will not work with the JSON renderer
543
- </p>
544
- <p>
545
- If you use the WebDav renderer, you can use the option
546
- </p>
547
- <pre>
548
- :resource_class (see http://github.com/georgi/rack_dav for more informations)
549
- </pre>
550
- <p><a class="source-toggle" href="#"
551
- onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
552
- <div class="method-source-code" id="M000017-source">
553
- <pre>
554
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 73</span>
555
- 73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>( <span class="ruby-identifier">hash</span> )
556
- 74: <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>
557
- 75: <span class="ruby-identifier">render_type</span> = <span class="ruby-keyword kw">nil</span>
558
- 76: <span class="ruby-identifier">possible_code_renderer</span> = <span class="ruby-keyword kw">nil</span>
559
- 77:
560
- 78: <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>
561
- 79: <span class="ruby-keyword kw">begin</span>
562
- 80: <span class="ruby-identifier">gem</span> <span class="ruby-node">&quot;capcode-render-#{key.to_s}&quot;</span>
563
- 81: <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;capcode/render/#{key.to_s}&quot;</span>
564
- 82: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">LoadError</span>
565
- 83: <span class="ruby-keyword kw">nil</span>
566
- 84: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
567
- 85: <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">&quot;Hum... The #{key} renderer is malformated! Please try to install a new version or use an other renderer!&quot;</span>, <span class="ruby-identifier">caller</span>
568
- 86: <span class="ruby-keyword kw">end</span>
569
- 87:
570
- 88: <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">&quot;render_#{key.to_s}&quot;</span>)
571
- 89: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span>
572
- 90: <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">&quot;Can't use multiple renderer (`#{render_type}' and `#{key}') !&quot;</span>, <span class="ruby-identifier">caller</span>
573
- 91: <span class="ruby-keyword kw">end</span>
574
- 92: <span class="ruby-identifier">render_type</span> = <span class="ruby-identifier">key</span>
575
- 93: <span class="ruby-keyword kw">end</span>
576
- 94:
577
- 95: <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>
578
- 96: <span class="ruby-identifier">possible_code_renderer</span> = <span class="ruby-identifier">key</span>
579
- 97: <span class="ruby-keyword kw">end</span>
580
- 98: <span class="ruby-keyword kw">end</span>
581
- 99:
582
- 100: <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>
583
- 101: <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">&quot;Renderer type not specified!&quot;</span>, <span class="ruby-identifier">caller</span>
584
- 102: <span class="ruby-keyword kw">end</span>
585
- 103:
586
- 104: <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">&quot;render_#{render_type.to_s}&quot;</span>)
587
- 105: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">possible_code_renderer</span>.<span class="ruby-identifier">nil?</span>
588
- 106: <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">&quot;#{render_type} renderer not present ! please require 'capcode/render/#{render_type}'&quot;</span>, <span class="ruby-identifier">caller</span>
589
- 107: <span class="ruby-keyword kw">else</span>
590
- 108: <span class="ruby-identifier">code</span> = <span class="ruby-identifier">possible_code_renderer</span>
591
- 109: <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>)
592
- 110: <span class="ruby-identifier">header</span> = {}
593
- 111: <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>
594
- 112: <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">&quot;-&quot;</span>)
595
- 113: <span class="ruby-identifier">header</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
596
- 114: <span class="ruby-keyword kw">end</span>
597
- 115:
598
- 116: [<span class="ruby-identifier">code</span>, <span class="ruby-identifier">header</span>, <span class="ruby-identifier">body</span>]
599
- 117: <span class="ruby-keyword kw">end</span>
600
- 118: <span class="ruby-keyword kw">else</span>
601
- 119: <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>)
602
- 120: <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>)
603
- 121: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">content_type</span>.<span class="ruby-identifier">nil?</span>
604
- 122: <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-identifier">content_type</span>
605
- 123: <span class="ruby-keyword kw">end</span>
606
- 124:
607
- 125: <span class="ruby-keyword kw">begin</span>
608
- 126: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>( <span class="ruby-node">&quot;render_#{render_type.to_s}&quot;</span>, <span class="ruby-identifier">render_name</span>, <span class="ruby-identifier">hash</span> )
609
- 127: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
610
- 128: <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">&quot;Error rendering `#{render_type.to_s}' : #{e.message}&quot;</span><span class="ruby-comment cmt">#, caller</span>
611
- 129: <span class="ruby-keyword kw">end</span>
612
- 130: <span class="ruby-keyword kw">end</span>
613
- 131: <span class="ruby-keyword kw">else</span>
614
- 132: <span class="ruby-identifier">render</span>( <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">hash</span> )
615
- 133: <span class="ruby-keyword kw">end</span>
616
- 134: <span class="ruby-keyword kw">end</span>
617
- </pre>
618
- </div>
619
- </div>
620
- </div>
621
-
622
- <div id="method-M000022" class="method-detail">
623
- <a name="M000022"></a>
624
-
625
- <div class="method-heading">
626
- <a href="#M000022" class="method-signature">
627
- <span class="method-name">static</span><span class="method-args">()</span>
628
- </a>
629
- </div>
630
-
631
- <div class="method-description">
632
- <p>
633
- Return information about the <a href="Helpers.html#M000022">static</a>
634
- directory
635
- </p>
636
- <ul>
637
- <li><tt><a href="Helpers.html#M000022">static</a>[:uri]</tt> give the <a
638
- href="Helpers.html#M000022">static</a> URI
639
-
640
- </li>
641
- <li><tt><a href="Helpers.html#M000022">static</a>[:path]</tt> give the path to
642
- the <a href="Helpers.html#M000022">static</a> directory on the server
643
-
644
- </li>
645
- </ul>
646
- <p><a class="source-toggle" href="#"
647
- onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
648
- <div class="method-source-code" id="M000022-source">
649
- <pre>
650
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 280</span>
651
- 280: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">static</span>
652
- 281: {
653
- 282: <span class="ruby-identifier">:uri</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>,
654
- 283: <span class="ruby-identifier">:path</span> =<span class="ruby-operator">&gt;</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>) ) )
655
- 284: }
656
- 285: <span class="ruby-keyword kw">end</span>
657
- </pre>
658
- </div>
659
- </div>
660
- </div>
661
-
662
-
663
- </div>
664
-
665
-
666
- </div>
667
-
668
-
669
- <div id="validator-badges">
670
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
671
- </div>
672
-
673
- </body>
674
- </html>