Capcode 0.8.6 → 0.8.7
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 +72 -1
- data/doc/rdoc/classes/Capcode.html +549 -444
- data/doc/rdoc/classes/Capcode/Helpers.html +293 -133
- data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +60 -29
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +94 -8
- data/doc/rdoc/files/lib/capcode/configuration_rb.html +101 -0
- data/doc/rdoc/files/lib/capcode/helpers/auth_rb.html +1 -32
- data/doc/rdoc/files/lib/capcode/render/erb_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/haml_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/sass_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +8 -1
- data/doc/rdoc/fr_file_index.html +1 -0
- data/doc/rdoc/fr_method_index.html +19 -11
- data/examples/blog-couchdb.rb +4 -3
- data/examples/erb/cf.rhtml +1 -0
- data/examples/haml/cf.haml +4 -1
- data/examples/render-erb.rb +4 -1
- data/examples/render-haml_sass.rb +6 -2
- data/examples/render-image.rb +70 -0
- data/examples/render-static.rb +4 -1
- data/examples/render-static.ru +0 -2
- data/examples/render-use.rb +31 -0
- data/examples/static/coderay.css +131 -0
- data/examples/static/index.html +19 -0
- data/lib/capcode.rb +125 -76
- data/lib/capcode/configuration.rb +39 -0
- data/lib/capcode/helpers/auth.rb +22 -23
- data/lib/capcode/render/erb.rb +25 -18
- data/lib/capcode/render/haml.rb +28 -19
- data/lib/capcode/render/markaby.rb +2 -1
- data/lib/capcode/render/sass.rb +19 -13
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/version.rb +1 -1
- metadata +8 -2
data/README.rdoc
CHANGED
@@ -12,6 +12,12 @@ Capcode is a web microframework
|
|
12
12
|
|
13
13
|
== FEATURES/PROBLEMS:
|
14
14
|
|
15
|
+
=== 0.8.7
|
16
|
+
* Route's captures are now passed to all methods in a coontroller
|
17
|
+
* Add :content_type option to renderers (see render-image.rb)
|
18
|
+
* Add Capcode.set for configuration. So Capcode::Herpers#erb_path=, Capcode::Herpers#sass_path= and Capcode::Herpers#haml_path= are deprecated, you must now use `set :erb, ...', `set :sass, ...' and `set :haml, ...' (see render-erb.rb and render-haml_sass.rb)
|
19
|
+
* Add Capcode.use to allow usage of Rack middlewares (see render-use.rb)
|
20
|
+
|
15
21
|
=== 0.8.6
|
16
22
|
* HUGE bug correction
|
17
23
|
|
@@ -291,7 +297,72 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
|
|
291
297
|
|
292
298
|
end
|
293
299
|
|
294
|
-
Capcode.run( )
|
300
|
+
Capcode.run( )
|
301
|
+
|
302
|
+
=== HTTP Authentication
|
303
|
+
|
304
|
+
# file: sample.rb
|
305
|
+
require 'rubygems'
|
306
|
+
require 'capcode'
|
307
|
+
|
308
|
+
module Capcode
|
309
|
+
class Public < Route '/public'
|
310
|
+
def get
|
311
|
+
render "This page is not protected"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
class Private < Route '/private'
|
316
|
+
def get
|
317
|
+
http_authentication( :type => :digest, :realm => "Private part" ) {
|
318
|
+
{ "greg" => "p4ssw0rd" }
|
319
|
+
}
|
320
|
+
|
321
|
+
render "This page is private - Hello #{request.env['REMOTE_USER']}"
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
Capcode.run( )
|
327
|
+
|
328
|
+
Second example :
|
329
|
+
|
330
|
+
# file: sample.rb
|
331
|
+
require 'rubygems'
|
332
|
+
require 'capcode'
|
333
|
+
|
334
|
+
module Capcode
|
335
|
+
|
336
|
+
http_authentication( :type => :digest, :realm => "Private part", :routes => ['/admin', '/private'] ) {
|
337
|
+
{ "greg" => "p4ssw0rd" }
|
338
|
+
}
|
339
|
+
|
340
|
+
class Public < Route '/public'
|
341
|
+
def get
|
342
|
+
render "This page is not protected"
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
class Private < Route '/private'
|
347
|
+
def get
|
348
|
+
render "This page is private - Hello #{request.env['REMOTE_USER']}"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
class PrivateAgain < Route '/private/again'
|
353
|
+
def get
|
354
|
+
render "This page is also private - Hello #{request.env['REMOTE_USER']}"
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class Admin < Route '/admin'
|
359
|
+
def get
|
360
|
+
render "This page is private - Hello #{request.env['REMOTE_USER']}"
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
Capcode.run( )
|
295
366
|
|
296
367
|
== DEPLOYMENT
|
297
368
|
|
@@ -62,6 +62,10 @@
|
|
62
62
|
<a href="../files/lib/capcode/base/db_rb.html">
|
63
63
|
lib/capcode/base/db.rb
|
64
64
|
</a>
|
65
|
+
<br />
|
66
|
+
<a href="../files/lib/capcode/configuration_rb.html">
|
67
|
+
lib/capcode/configuration.rb
|
68
|
+
</a>
|
65
69
|
<br />
|
66
70
|
<a href="../files/lib/capcode/render/erb_rb.html">
|
67
71
|
lib/capcode/render/erb.rb
|
@@ -116,37 +120,6 @@
|
|
116
120
|
|
117
121
|
<div id="contextContent">
|
118
122
|
|
119
|
-
<div id="description">
|
120
|
-
<p>
|
121
|
-
Because this helper was trully inspired by this post : <a
|
122
|
-
href="http://www.gittr.com/index.php/archive/sinatra-basic-authentication-selectively-applied">www.gittr.com/index.php/archive/sinatra-basic-authentication-selectively-applied</a>/
|
123
|
-
and because the code in this post was extracted out of Wink, this file
|
124
|
-
follow the Wink license :
|
125
|
-
</p>
|
126
|
-
<p>
|
127
|
-
Permission is hereby granted, free of charge, to any person obtaining a
|
128
|
-
copy of this software and associated documentation files (the
|
129
|
-
"Software"), to deal in the Software without restriction,
|
130
|
-
including without limitation the rights to use, copy, modify, merge,
|
131
|
-
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
132
|
-
permit persons to whom the Software is furnished to do so, subject to the
|
133
|
-
following conditions:
|
134
|
-
</p>
|
135
|
-
<p>
|
136
|
-
The above copyright notice and this permission notice shall be included in
|
137
|
-
all copies or substantial portions of the Software.
|
138
|
-
</p>
|
139
|
-
<p>
|
140
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
141
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
142
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
143
|
-
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
144
|
-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
145
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
146
|
-
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
147
|
-
</p>
|
148
|
-
|
149
|
-
</div>
|
150
123
|
|
151
124
|
|
152
125
|
</div>
|
@@ -156,15 +129,18 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
156
129
|
|
157
130
|
<div class="name-list">
|
158
131
|
<a href="#M000001">Route</a>
|
159
|
-
<a href="#
|
132
|
+
<a href="#M000010">application</a>
|
133
|
+
<a href="#M000013">config</a>
|
160
134
|
<a href="#M000003">env</a>
|
161
|
-
<a href="#
|
135
|
+
<a href="#M000009">http_authentication</a>
|
162
136
|
<a href="#M000007">map</a>
|
163
137
|
<a href="#M000002">params</a>
|
164
138
|
<a href="#M000005">request</a>
|
165
139
|
<a href="#M000006">response</a>
|
166
|
-
<a href="#
|
140
|
+
<a href="#M000011">run</a>
|
167
141
|
<a href="#M000004">session</a>
|
142
|
+
<a href="#M000012">set</a>
|
143
|
+
<a href="#M000008">use</a>
|
168
144
|
</div>
|
169
145
|
</div>
|
170
146
|
|
@@ -244,10 +220,12 @@ Add routes to a controller class
|
|
244
220
|
<p>
|
245
221
|
In the <tt>get</tt> method, you will receive the maximum of parameters
|
246
222
|
declared by the routes. In this example, you will receive 2 parameters. So
|
247
|
-
if you go to <tt>/hello/world#friend</tt> then <tt>arg1</tt> will be
|
248
|
-
|
249
|
-
|
250
|
-
|
223
|
+
if you go to <tt>/hello/world#friend</tt> then <tt>arg1</tt> will be <a
|
224
|
+
href="Capcode.html#M000012">set</a> to <tt>world</tt> and <tt>arg2</tt>
|
225
|
+
will be <a href="Capcode.html#M000012">set</a> to <tt>friend</tt>. Now if
|
226
|
+
you go to <tt>/hello/you</tt>, then <tt>arg1</tt> will be <a
|
227
|
+
href="Capcode.html#M000012">set</a> to <tt>you</tt> and <tt>arg2</tt> will
|
228
|
+
be <a href="Capcode.html#M000012">set</a> to <tt>nil</tt>
|
251
229
|
</p>
|
252
230
|
<p>
|
253
231
|
If the regexp in the route does not match, all arguments will be
|
@@ -257,179 +235,179 @@ If the regexp in the route does not match, all arguments will be
|
|
257
235
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
258
236
|
<div class="method-source-code" id="M000001-source">
|
259
237
|
<pre>
|
260
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
399: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
377
|
-
400: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
378
|
-
401: <span class="ruby-keyword kw">end</span>
|
379
|
-
402: <span class="ruby-keyword kw">end</span>
|
380
|
-
403:
|
381
|
-
404: <span class="ruby-keyword kw">end</span>
|
382
|
-
405:
|
383
|
-
406: <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>]
|
384
|
-
407: <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>] )
|
385
|
-
408: <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">"^#{finalPath}"</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> ) )
|
386
|
-
409: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
387
|
-
410: <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">"Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"</span>
|
388
|
-
411: <span class="ruby-keyword kw">else</span>
|
389
|
-
412: <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> }
|
390
|
-
413: <span class="ruby-keyword kw">end</span>
|
391
|
-
414:
|
392
|
-
415: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">nargs</span>
|
393
|
-
416: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
238
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 302</span>
|
239
|
+
302: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">routes_paths</span>
|
240
|
+
303: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
241
|
+
304: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
|
242
|
+
305: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent => /Songbird (\d\.\d)[\d\/]*?/</span>
|
243
|
+
306: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, </span>
|
244
|
+
307: <span class="ruby-comment cmt"># 2, </span>
|
245
|
+
308: <span class="ruby-comment cmt"># <Capcode::Klass>, </span>
|
246
|
+
309: <span class="ruby-comment cmt"># {:agent => /Songbird (\d\.\d)[\d\/]*?/} ]</span>
|
247
|
+
310: <span class="ruby-identifier">hash_of_routes</span> = {}
|
248
|
+
311: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
|
249
|
+
312: <span class="ruby-identifier">routes_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
|
250
|
+
313: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current_route_path</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">String</span>
|
251
|
+
314: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">current_route_path</span> )
|
252
|
+
315: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
253
|
+
316: <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">"Route `#{current_route_path}' already defined with regexp `#{hash_of_routes[current_route_path]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
|
254
|
+
317: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
|
255
|
+
318: <span class="ruby-keyword kw">else</span>
|
256
|
+
319: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
257
|
+
320: <span class="ruby-identifier">_pre</span> = <span class="ruby-value str">"/"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_pre</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
258
|
+
321: <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">"Route `#{_pre}' already defined with regexp `#{hash_of_routes[_pre]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_pre</span>)
|
259
|
+
322: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">_pre</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
|
260
|
+
323: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max_captures_for_routes</span> <span class="ruby-operator"><</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span>
|
261
|
+
324: <span class="ruby-keyword kw">end</span>
|
262
|
+
325: <span class="ruby-keyword kw">else</span>
|
263
|
+
326: <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-value str">"Bad route declaration !"</span>, <span class="ruby-identifier">caller</span>
|
264
|
+
327: <span class="ruby-keyword kw">end</span>
|
265
|
+
328: <span class="ruby-keyword kw">end</span>
|
266
|
+
329: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
|
267
|
+
330: }
|
268
|
+
331:
|
269
|
+
332: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
270
|
+
333: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
271
|
+
334: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
272
|
+
335: <span class="ruby-keyword kw">end</span>
|
273
|
+
336:
|
274
|
+
337: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
275
|
+
338: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
276
|
+
339: <span class="ruby-ivar">@env</span>
|
277
|
+
340: <span class="ruby-keyword kw">end</span>
|
278
|
+
341:
|
279
|
+
342: <span class="ruby-comment cmt"># Session hash</span>
|
280
|
+
343: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
281
|
+
344: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
282
|
+
345: <span class="ruby-keyword kw">end</span>
|
283
|
+
346:
|
284
|
+
347: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
285
|
+
348: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
286
|
+
349: <span class="ruby-ivar">@request</span>
|
287
|
+
350: <span class="ruby-keyword kw">end</span>
|
288
|
+
351:
|
289
|
+
352: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
290
|
+
353: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
291
|
+
354: <span class="ruby-ivar">@response</span>
|
292
|
+
355: <span class="ruby-keyword kw">end</span>
|
293
|
+
356:
|
294
|
+
357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>( <span class="ruby-identifier">e</span> ) <span class="ruby-comment cmt">#:nodoc:</span>
|
295
|
+
358: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
296
|
+
359: <span class="ruby-ivar">@response</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
|
297
|
+
360: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@env</span>)
|
298
|
+
361:
|
299
|
+
362: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
|
300
|
+
363: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
|
301
|
+
364: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
|
302
|
+
365: <span class="ruby-comment cmt"># __run = true</span>
|
303
|
+
366: <span class="ruby-comment cmt"># if f[:only]</span>
|
304
|
+
367: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
|
305
|
+
368: <span class="ruby-comment cmt"># end</span>
|
306
|
+
369: <span class="ruby-comment cmt"># if f[:except]</span>
|
307
|
+
370: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
308
|
+
371: <span class="ruby-comment cmt"># end</span>
|
309
|
+
372: <span class="ruby-comment cmt"># </span>
|
310
|
+
373: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
|
311
|
+
374: <span class="ruby-comment cmt"># puts "call #{proc} for #{__k}"</span>
|
312
|
+
375: <span class="ruby-comment cmt"># end</span>
|
313
|
+
376:
|
314
|
+
377: <span class="ruby-comment cmt"># Check authz</span>
|
315
|
+
378: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
|
316
|
+
379: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
317
|
+
380: <span class="ruby-identifier">authz_options</span> = <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>[<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>
|
318
|
+
381: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
319
|
+
382: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
|
320
|
+
383:
|
321
|
+
384: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</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-identifier">o</span><span class="ruby-operator">|</span>
|
322
|
+
385: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">"^#{r.gsub(/\/$/, "")}([/]{1}.*)?$"</span>
|
323
|
+
386: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">match</span>( <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span> )
|
324
|
+
387: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">size</span>
|
325
|
+
388: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
|
326
|
+
389: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
|
327
|
+
390: <span class="ruby-keyword kw">end</span>
|
328
|
+
391: <span class="ruby-keyword kw">end</span>
|
329
|
+
392: <span class="ruby-keyword kw">end</span>
|
330
|
+
393: <span class="ruby-keyword kw">end</span>
|
331
|
+
394: <span class="ruby-keyword kw">end</span>
|
332
|
+
395:
|
333
|
+
396: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
|
334
|
+
397: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
335
|
+
398: <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:type</span>], <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:realm</span>], <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:realm</span>] ) {
|
336
|
+
399: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
|
337
|
+
400: }
|
338
|
+
401: <span class="ruby-keyword kw">end</span>
|
339
|
+
402:
|
340
|
+
403: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
341
|
+
404: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
342
|
+
405: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
343
|
+
406:
|
344
|
+
407: <span class="ruby-identifier">aPath</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</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-value str">"/"</span> )
|
345
|
+
408: <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">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
346
|
+
409: <span class="ruby-identifier">xPath</span> = <span class="ruby-identifier">p</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-value str">"/"</span> )
|
347
|
+
410: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
348
|
+
411: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
349
|
+
412: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
350
|
+
413: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">></span> <span class="ruby-identifier">diffNArgs</span>
|
351
|
+
414: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
352
|
+
415: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
353
|
+
416: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
394
354
|
417: <span class="ruby-keyword kw">end</span>
|
395
|
-
418:
|
396
|
-
419:
|
397
|
-
420:
|
398
|
-
421:
|
399
|
-
422:
|
400
|
-
423:
|
401
|
-
424:
|
402
|
-
425:
|
403
|
-
426:
|
404
|
-
427:
|
405
|
-
428:
|
406
|
-
429: <span class="ruby-
|
407
|
-
430:
|
408
|
-
431: <span class="ruby-
|
409
|
-
432: <span class="ruby-
|
355
|
+
418: <span class="ruby-keyword kw">end</span>
|
356
|
+
419:
|
357
|
+
420: <span class="ruby-keyword kw">end</span>
|
358
|
+
421:
|
359
|
+
422: <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>]
|
360
|
+
423: <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>] )
|
361
|
+
424: <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">"^#{finalPath}"</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> ) )
|
362
|
+
425: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
363
|
+
426: <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">"Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"</span>
|
364
|
+
427: <span class="ruby-keyword kw">else</span>
|
365
|
+
428: <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> }
|
366
|
+
429: <span class="ruby-keyword kw">end</span>
|
367
|
+
430:
|
368
|
+
431: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">nargs</span>
|
369
|
+
432: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
410
370
|
433: <span class="ruby-keyword kw">end</span>
|
411
|
-
434:
|
412
|
-
435:
|
413
|
-
436:
|
414
|
-
437:
|
415
|
-
438:
|
416
|
-
439:
|
417
|
-
440:
|
418
|
-
441:
|
419
|
-
442:
|
420
|
-
443:
|
421
|
-
444:
|
422
|
-
445:
|
371
|
+
434:
|
372
|
+
435: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
373
|
+
436: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
374
|
+
437: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
375
|
+
438: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
376
|
+
439: <span class="ruby-identifier">_method</span> = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">delete</span>( <span class="ruby-value str">"_method"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-value str">"post"</span> }
|
377
|
+
440: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
378
|
+
441: <span class="ruby-keyword kw">else</span>
|
379
|
+
442: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
380
|
+
443: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
381
|
+
444: <span class="ruby-keyword kw">end</span>
|
382
|
+
445: }
|
383
|
+
446: <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>)
|
384
|
+
447: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[0]</span>
|
385
|
+
448: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
|
386
|
+
449: <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</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>
|
387
|
+
450: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
388
|
+
451: <span class="ruby-keyword kw">end</span>
|
389
|
+
452: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
|
390
|
+
453: <span class="ruby-keyword kw">else</span>
|
391
|
+
454: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
392
|
+
455: <span class="ruby-keyword kw">end</span>
|
393
|
+
456:
|
394
|
+
457: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
395
|
+
458: <span class="ruby-keyword kw">end</span>
|
396
|
+
459:
|
397
|
+
460: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
398
|
+
461: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
399
|
+
462: }
|
400
|
+
463: <span class="ruby-keyword kw">end</span>
|
423
401
|
</pre>
|
424
402
|
</div>
|
425
403
|
</div>
|
426
404
|
</div>
|
427
405
|
|
428
|
-
<div id="method-
|
429
|
-
<a name="
|
406
|
+
<div id="method-M000010" class="method-detail">
|
407
|
+
<a name="M000010"></a>
|
430
408
|
|
431
409
|
<div class="method-heading">
|
432
|
-
<a href="#
|
410
|
+
<a href="#M000010" class="method-signature">
|
433
411
|
<span class="method-name">application</span><span class="method-args">( args = {} ) {|self| ...}</span>
|
434
412
|
</a>
|
435
413
|
</div>
|
@@ -439,62 +417,104 @@ If the regexp in the route does not match, all arguments will be
|
|
439
417
|
Return the Rack App.
|
440
418
|
</p>
|
441
419
|
<p>
|
442
|
-
Options :
|
420
|
+
Options : see <a href="Capcode.html#M000012">Capcode.set</a>
|
421
|
+
</p>
|
422
|
+
<p>
|
423
|
+
Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
|
424
|
+
href="Capcode.html#M000012">set</a> globally
|
443
425
|
</p>
|
444
426
|
<p><a class="source-toggle" href="#"
|
445
|
-
onclick="toggleCode('
|
446
|
-
<div class="method-source-code" id="
|
427
|
+
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
428
|
+
<div class="method-source-code" id="M000010-source">
|
447
429
|
<pre>
|
448
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
430
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 549</span>
|
431
|
+
549: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
|
432
|
+
550: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
433
|
+
551:
|
434
|
+
552: <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>
|
435
|
+
553: <span class="ruby-keyword kw">begin</span>
|
436
|
+
554: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.public_methods(true).include?( '__urls__' )"</span>
|
437
|
+
555: <span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.__urls__"</span>
|
438
|
+
556: <span class="ruby-identifier">hash_of_routes</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">current_route_path</span><span class="ruby-operator">|</span>
|
439
|
+
557: <span class="ruby-comment cmt">#raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if @@__ROUTES.keys.include?(current_route_path)</span>
|
440
|
+
558: <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">"Route `#{current_route_path}' already define !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
|
441
|
+
559: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
|
442
|
+
560: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
|
443
|
+
561: <span class="ruby-keyword kw">end</span>
|
444
|
+
562: <span class="ruby-keyword kw">end</span>
|
445
|
+
563: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
446
|
+
564: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
447
|
+
565: <span class="ruby-keyword kw">end</span>
|
448
|
+
566: <span class="ruby-keyword kw">end</span>
|
449
|
+
567:
|
450
|
+
568: <span class="ruby-comment cmt"># Set Static directory</span>
|
451
|
+
569: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == "/")?conf[:static]:"/"+conf[:static] unless conf[:static].nil?</span>
|
452
|
+
570: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> = (<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">chr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"/"</span>)<span class="ruby-operator">?</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">:</span><span class="ruby-value str">"/"</span><span class="ruby-operator">+</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
|
453
|
+
571:
|
454
|
+
572: <span class="ruby-comment cmt"># Initialize Rack App</span>
|
455
|
+
573: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"** Map routes."</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
456
|
+
574: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
|
457
|
+
575: <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-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
|
458
|
+
576: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Initialize static directory (#{conf[:static]})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
459
|
+
577: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
|
460
|
+
578: <span class="ruby-identifier">app</span>,
|
461
|
+
579: <span class="ruby-comment cmt">#:urls => [@@__STATIC_DIR], </span>
|
462
|
+
580: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">></span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
|
463
|
+
581: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">></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>])
|
464
|
+
582: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
|
465
|
+
583: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"** Initialize session"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
466
|
+
584: <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>] )
|
467
|
+
585: <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>)
|
468
|
+
586: <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>)
|
469
|
+
587: <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>)
|
470
|
+
588: <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>)
|
471
|
+
589: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
472
|
+
590: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
|
473
|
+
591:
|
474
|
+
592: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
|
475
|
+
593: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
|
476
|
+
594: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Load middleware #{middleware}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
477
|
+
595: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
|
478
|
+
596: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> )
|
479
|
+
597: <span class="ruby-keyword kw">else</span>
|
480
|
+
598: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
481
|
+
599: <span class="ruby-keyword kw">end</span>
|
482
|
+
600: <span class="ruby-keyword kw">end</span>
|
483
|
+
601:
|
484
|
+
602: <span class="ruby-comment cmt"># Start database</span>
|
485
|
+
603: <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">"db_connect"</span>
|
486
|
+
604: <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>] )
|
487
|
+
605: <span class="ruby-keyword kw">end</span>
|
488
|
+
606:
|
489
|
+
607: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
490
|
+
608: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
491
|
+
609: <span class="ruby-keyword kw">end</span>
|
492
|
+
610:
|
493
|
+
611: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
|
494
|
+
612: <span class="ruby-keyword kw">end</span>
|
495
|
+
</pre>
|
496
|
+
</div>
|
497
|
+
</div>
|
498
|
+
</div>
|
499
|
+
|
500
|
+
<div id="method-M000013" class="method-detail">
|
501
|
+
<a name="M000013"></a>
|
502
|
+
|
503
|
+
<div class="method-heading">
|
504
|
+
<a href="#M000013" class="method-signature">
|
505
|
+
<span class="method-name">config</span><span class="method-args">()</span>
|
506
|
+
</a>
|
507
|
+
</div>
|
508
|
+
|
509
|
+
<div class="method-description">
|
510
|
+
<p><a class="source-toggle" href="#"
|
511
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
512
|
+
<div class="method-source-code" id="M000013-source">
|
513
|
+
<pre>
|
514
|
+
<span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 35</span>
|
515
|
+
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
|
516
|
+
36: <span class="ruby-ivar">@configuration</span> <span class="ruby-operator">||=</span> {}
|
517
|
+
37: <span class="ruby-keyword kw">end</span>
|
498
518
|
</pre>
|
499
519
|
</div>
|
500
520
|
</div>
|
@@ -517,20 +537,20 @@ Hash containing all the environment variables
|
|
517
537
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
518
538
|
<div class="method-source-code" id="M000003-source">
|
519
539
|
<pre>
|
520
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
521
|
-
|
522
|
-
|
523
|
-
|
540
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 338</span>
|
541
|
+
338: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
542
|
+
339: <span class="ruby-ivar">@env</span>
|
543
|
+
340: <span class="ruby-keyword kw">end</span>
|
524
544
|
</pre>
|
525
545
|
</div>
|
526
546
|
</div>
|
527
547
|
</div>
|
528
548
|
|
529
|
-
<div id="method-
|
530
|
-
<a name="
|
549
|
+
<div id="method-M000009" class="method-detail">
|
550
|
+
<a name="M000009"></a>
|
531
551
|
|
532
552
|
<div class="method-heading">
|
533
|
-
<a href="#
|
553
|
+
<a href="#M000009" class="method-signature">
|
534
554
|
<span class="method-name">http_authentication</span><span class="method-args">( opts = {}, &b )</span>
|
535
555
|
</a>
|
536
556
|
</div>
|
@@ -551,8 +571,10 @@ Options :
|
|
551
571
|
<li><tt>:realm</tt> : realm ;) - default : "Capcode.app"
|
552
572
|
|
553
573
|
</li>
|
554
|
-
<li><tt>:opaque</tt> : Your secret passphrase. You MUST
|
555
|
-
|
574
|
+
<li><tt>:opaque</tt> : Your secret passphrase. You MUST <a
|
575
|
+
href="Capcode.html#M000012">set</a> it if you <a
|
576
|
+
href="Capcode.html#M000008">use</a> Digest Auth - default :
|
577
|
+
"opaque"
|
556
578
|
|
557
579
|
</li>
|
558
580
|
<li><tt>:routes</tt> : Routes - default : "/"
|
@@ -570,30 +592,30 @@ The block must return a Hash of username => password like that :
|
|
570
592
|
}
|
571
593
|
</pre>
|
572
594
|
<p><a class="source-toggle" href="#"
|
573
|
-
onclick="toggleCode('
|
574
|
-
<div class="method-source-code" id="
|
595
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
596
|
+
<div class="method-source-code" id="M000009-source">
|
575
597
|
<pre>
|
576
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
598
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 506</span>
|
599
|
+
506: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
600
|
+
507: <span class="ruby-identifier">options</span> = {
|
601
|
+
508: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:basic</span>,
|
602
|
+
509: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"Capcode.app"</span>,
|
603
|
+
510: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"opaque"</span>,
|
604
|
+
511: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"/"</span>
|
605
|
+
512: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
|
606
|
+
513:
|
607
|
+
514: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
|
608
|
+
515:
|
609
|
+
516: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
|
610
|
+
517:
|
611
|
+
518: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
|
612
|
+
519: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</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>
|
613
|
+
520: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
|
614
|
+
521: <span class="ruby-keyword kw">end</span>
|
615
|
+
522: <span class="ruby-keyword kw">else</span>
|
616
|
+
523: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
|
617
|
+
524: <span class="ruby-keyword kw">end</span>
|
618
|
+
525: <span class="ruby-keyword kw">end</span>
|
597
619
|
</pre>
|
598
620
|
</div>
|
599
621
|
</div>
|
@@ -622,10 +644,11 @@ Rack or What you want Helper
|
|
622
644
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
623
645
|
<div class="method-source-code" id="M000007-source">
|
624
646
|
<pre>
|
625
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
626
|
-
|
627
|
-
|
628
|
-
|
647
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 470</span>
|
648
|
+
470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">route</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
649
|
+
471: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
|
650
|
+
472: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
|
651
|
+
473: <span class="ruby-keyword kw">end</span>
|
629
652
|
</pre>
|
630
653
|
</div>
|
631
654
|
</div>
|
@@ -649,10 +672,10 @@ parameters (GET or POST)
|
|
649
672
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
650
673
|
<div class="method-source-code" id="M000002-source">
|
651
674
|
<pre>
|
652
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
653
|
-
|
654
|
-
|
655
|
-
|
675
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 333</span>
|
676
|
+
333: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
677
|
+
334: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
678
|
+
335: <span class="ruby-keyword kw">end</span>
|
656
679
|
</pre>
|
657
680
|
</div>
|
658
681
|
</div>
|
@@ -675,10 +698,10 @@ Return the Rack::Request object
|
|
675
698
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
676
699
|
<div class="method-source-code" id="M000005-source">
|
677
700
|
<pre>
|
678
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
679
|
-
|
680
|
-
|
681
|
-
|
701
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 348</span>
|
702
|
+
348: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
703
|
+
349: <span class="ruby-ivar">@request</span>
|
704
|
+
350: <span class="ruby-keyword kw">end</span>
|
682
705
|
</pre>
|
683
706
|
</div>
|
684
707
|
</div>
|
@@ -701,27 +724,202 @@ Return the Rack::Response object
|
|
701
724
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
702
725
|
<div class="method-source-code" id="M000006-source">
|
703
726
|
<pre>
|
704
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
705
|
-
|
706
|
-
|
707
|
-
|
727
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 353</span>
|
728
|
+
353: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
729
|
+
354: <span class="ruby-ivar">@response</span>
|
730
|
+
355: <span class="ruby-keyword kw">end</span>
|
708
731
|
</pre>
|
709
732
|
</div>
|
710
733
|
</div>
|
711
734
|
</div>
|
712
735
|
|
713
|
-
<div id="method-
|
714
|
-
<a name="
|
736
|
+
<div id="method-M000011" class="method-detail">
|
737
|
+
<a name="M000011"></a>
|
715
738
|
|
716
739
|
<div class="method-heading">
|
717
|
-
<a href="#
|
740
|
+
<a href="#M000011" class="method-signature">
|
718
741
|
<span class="method-name">run</span><span class="method-args">( args = {} ) {|self| ...}</span>
|
719
742
|
</a>
|
720
743
|
</div>
|
721
744
|
|
722
745
|
<div class="method-description">
|
723
746
|
<p>
|
724
|
-
Start your <a href="Capcode.html#
|
747
|
+
Start your <a href="Capcode.html#M000010">application</a>.
|
748
|
+
</p>
|
749
|
+
<p>
|
750
|
+
Options : see <a href="Capcode.html#M000012">Capcode.set</a>
|
751
|
+
</p>
|
752
|
+
<p>
|
753
|
+
Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
|
754
|
+
href="Capcode.html#M000012">set</a> globally
|
755
|
+
</p>
|
756
|
+
<p><a class="source-toggle" href="#"
|
757
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
758
|
+
<div class="method-source-code" id="M000011-source">
|
759
|
+
<pre>
|
760
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 619</span>
|
761
|
+
619: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
762
|
+
620: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
763
|
+
621:
|
764
|
+
622: <span class="ruby-comment cmt"># Parse options</span>
|
765
|
+
623: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
766
|
+
624: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
767
|
+
625: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
768
|
+
626: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
769
|
+
627:
|
770
|
+
628: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-C"</span>, <span class="ruby-value str">"--console"</span>, <span class="ruby-value str">"Run in console mode with IRB (default: false)"</span> ) {
|
771
|
+
629: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
|
772
|
+
630: }
|
773
|
+
631: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-h"</span>, <span class="ruby-value str">"--host HOSTNAME"</span>, <span class="ruby-node">"Host for web server to bind to (default: #{conf[:host]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
774
|
+
632: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
775
|
+
633: }
|
776
|
+
634: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-p"</span>, <span class="ruby-value str">"--port NUM"</span>, <span class="ruby-node">"Port for web server (default: #{conf[:port]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
777
|
+
635: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
|
778
|
+
636: }
|
779
|
+
637: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-d"</span>, <span class="ruby-value str">"--daemonize [true|false]"</span>, <span class="ruby-node">"Daemonize (default: #{conf[:daemonize]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
780
|
+
638: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
|
781
|
+
639: }
|
782
|
+
640: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-r"</span>, <span class="ruby-value str">"--root PATH"</span>, <span class="ruby-node">"Working directory (default: #{conf[:root]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
|
783
|
+
641: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
|
784
|
+
642: }
|
785
|
+
643: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-s"</span>, <span class="ruby-value str">"--static PATH"</span>, <span class="ruby-node">"Static directory -- relative to the root directory (default: #{conf[:static]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
786
|
+
644: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
|
787
|
+
645: }
|
788
|
+
646:
|
789
|
+
647: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
790
|
+
648: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
791
|
+
649:
|
792
|
+
650: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-?"</span>, <span class="ruby-value str">"--help"</span>, <span class="ruby-value str">"Show this message"</span>) <span class="ruby-keyword kw">do</span>
|
793
|
+
651: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
794
|
+
652: <span class="ruby-identifier">exit</span>
|
795
|
+
653: <span class="ruby-keyword kw">end</span>
|
796
|
+
654: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-v"</span>, <span class="ruby-value str">"--version"</span>, <span class="ruby-value str">"Show versions"</span>) <span class="ruby-keyword kw">do</span>
|
797
|
+
655: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
798
|
+
656: <span class="ruby-identifier">exit</span>
|
799
|
+
657: <span class="ruby-keyword kw">end</span>
|
800
|
+
658: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>( <span class="ruby-value str">"-V"</span>, <span class="ruby-value str">"--verbose"</span>, <span class="ruby-value str">"Run in verbose mode"</span> ) <span class="ruby-keyword kw">do</span>
|
801
|
+
659: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>] = <span class="ruby-keyword kw">true</span>
|
802
|
+
660: <span class="ruby-keyword kw">end</span>
|
803
|
+
661: <span class="ruby-keyword kw">end</span>
|
804
|
+
662:
|
805
|
+
663: <span class="ruby-keyword kw">begin</span>
|
806
|
+
664: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
807
|
+
665: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
|
808
|
+
666: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
809
|
+
667: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
810
|
+
668: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
811
|
+
669: <span class="ruby-keyword kw">end</span>
|
812
|
+
670:
|
813
|
+
671: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
814
|
+
672: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Go on root directory (#{File.expand_path(conf[:root])})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
815
|
+
673: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] ) <span class="ruby-keyword kw">do</span>
|
816
|
+
674:
|
817
|
+
675: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
818
|
+
676: <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">"mongrel"</span>
|
819
|
+
677: <span class="ruby-keyword kw">begin</span>
|
820
|
+
678: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
821
|
+
679: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
822
|
+
680: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
823
|
+
681: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
824
|
+
682: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
825
|
+
683: <span class="ruby-keyword kw">end</span>
|
826
|
+
684: <span class="ruby-keyword kw">end</span>
|
827
|
+
685:
|
828
|
+
686: <span class="ruby-comment cmt"># From rackup !!!</span>
|
829
|
+
687: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
830
|
+
688: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
|
831
|
+
689: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator"><</span> <span class="ruby-value str">"1.9"</span>
|
832
|
+
690: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
833
|
+
691: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
834
|
+
692: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
835
|
+
693: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
836
|
+
694: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
837
|
+
695: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
838
|
+
696: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
839
|
+
697: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
840
|
+
698: <span class="ruby-keyword kw">else</span>
|
841
|
+
699: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
842
|
+
700: <span class="ruby-keyword kw">end</span>
|
843
|
+
701: <span class="ruby-keyword kw">else</span>
|
844
|
+
702: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
845
|
+
703: <span class="ruby-keyword kw">end</span>
|
846
|
+
704:
|
847
|
+
705: <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">"#{Process.pid}"</span>) }
|
848
|
+
706: <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>]) }
|
849
|
+
707: <span class="ruby-keyword kw">end</span>
|
850
|
+
708:
|
851
|
+
709: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
|
852
|
+
710: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
853
|
+
711: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
|
854
|
+
712: <span class="ruby-keyword kw">else</span>
|
855
|
+
713: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>)
|
856
|
+
714: <span class="ruby-keyword kw">end</span>
|
857
|
+
715: <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>]) )
|
858
|
+
716:
|
859
|
+
717: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
|
860
|
+
718: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
861
|
+
719: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
862
|
+
720: <span class="ruby-identifier">exit</span>
|
863
|
+
721: <span class="ruby-keyword kw">end</span>
|
864
|
+
722:
|
865
|
+
723: <span class="ruby-comment cmt"># Start server</span>
|
866
|
+
724: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
867
|
+
725: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
868
|
+
726: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
869
|
+
727: <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">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">></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>
|
870
|
+
728: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
|
871
|
+
729: }
|
872
|
+
730: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
873
|
+
731: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
874
|
+
732: <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">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">></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>
|
875
|
+
733: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
|
876
|
+
734: }
|
877
|
+
735: <span class="ruby-keyword kw">end</span>
|
878
|
+
736: <span class="ruby-keyword kw">end</span>
|
879
|
+
737: <span class="ruby-keyword kw">end</span>
|
880
|
+
</pre>
|
881
|
+
</div>
|
882
|
+
</div>
|
883
|
+
</div>
|
884
|
+
|
885
|
+
<div id="method-M000004" class="method-detail">
|
886
|
+
<a name="M000004"></a>
|
887
|
+
|
888
|
+
<div class="method-heading">
|
889
|
+
<a href="#M000004" class="method-signature">
|
890
|
+
<span class="method-name">session</span><span class="method-args">()</span>
|
891
|
+
</a>
|
892
|
+
</div>
|
893
|
+
|
894
|
+
<div class="method-description">
|
895
|
+
<p>
|
896
|
+
Session hash
|
897
|
+
</p>
|
898
|
+
<p><a class="source-toggle" href="#"
|
899
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
900
|
+
<div class="method-source-code" id="M000004-source">
|
901
|
+
<pre>
|
902
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 343</span>
|
903
|
+
343: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
904
|
+
344: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
905
|
+
345: <span class="ruby-keyword kw">end</span>
|
906
|
+
</pre>
|
907
|
+
</div>
|
908
|
+
</div>
|
909
|
+
</div>
|
910
|
+
|
911
|
+
<div id="method-M000012" class="method-detail">
|
912
|
+
<a name="M000012"></a>
|
913
|
+
|
914
|
+
<div class="method-heading">
|
915
|
+
<a href="#M000012" class="method-signature">
|
916
|
+
<span class="method-name">set</span><span class="method-args">( key, value )</span>
|
917
|
+
</a>
|
918
|
+
</div>
|
919
|
+
|
920
|
+
<div class="method-description">
|
921
|
+
<p>
|
922
|
+
Set global configuration options
|
725
923
|
</p>
|
726
924
|
<p>
|
727
925
|
Options :
|
@@ -747,177 +945,84 @@ See Rack::Session for more informations
|
|
747
945
|
|
748
946
|
</li>
|
749
947
|
<li><tt>:daemonize</tt> = Daemonize <a
|
750
|
-
href="Capcode.html#
|
948
|
+
href="Capcode.html#M000010">application</a> (default: false)
|
751
949
|
|
752
950
|
</li>
|
753
951
|
<li><tt>:db_config</tt> = database configuration file (default: database.yml)
|
754
952
|
|
755
953
|
</li>
|
756
|
-
<li><tt>:static</tt> = Static directory (default:
|
757
|
-
working directory)
|
954
|
+
<li><tt>:static</tt> = Static directory (default: the working directory)
|
758
955
|
|
759
956
|
</li>
|
760
957
|
<li><tt>:root</tt> = Root directory (default: directory of the main.rb) —
|
761
958
|
This is also the working directory !
|
762
959
|
|
763
960
|
</li>
|
764
|
-
<li><tt>:verbose</tt> = <a href="Capcode.html#
|
961
|
+
<li><tt>:verbose</tt> = <a href="Capcode.html#M000011">run</a> in verbose mode
|
765
962
|
|
766
963
|
</li>
|
767
964
|
<li><tt>:auth</tt> = HTTP Basic Authentication options
|
768
965
|
|
769
966
|
</li>
|
770
967
|
</ul>
|
968
|
+
<p>
|
969
|
+
It can exist specifics options depending on a renderer, a helper, …
|
970
|
+
</p>
|
971
|
+
<p>
|
972
|
+
Example :
|
973
|
+
</p>
|
974
|
+
<pre>
|
975
|
+
module Capcode
|
976
|
+
set :erb, "/path/to/erb/files"
|
977
|
+
...
|
978
|
+
end
|
979
|
+
</pre>
|
771
980
|
<p><a class="source-toggle" href="#"
|
772
|
-
onclick="toggleCode('
|
773
|
-
<div class="method-source-code" id="
|
981
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
982
|
+
<div class="method-source-code" id="M000012-source">
|
774
983
|
<pre>
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
580: <span class="ruby-comment cmt"># Parse options</span>
|
780
|
-
581: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
781
|
-
582: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
782
|
-
583: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
783
|
-
584: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
784
|
-
585:
|
785
|
-
586: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-C"</span>, <span class="ruby-value str">"--console"</span>, <span class="ruby-value str">"Run in console mode with IRB (default: false)"</span> ) {
|
786
|
-
587: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
|
787
|
-
588: }
|
788
|
-
589: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-h"</span>, <span class="ruby-value str">"--host HOSTNAME"</span>, <span class="ruby-node">"Host for web server to bind to (default: #{conf[:host]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
789
|
-
590: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
790
|
-
591: }
|
791
|
-
592: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-p"</span>, <span class="ruby-value str">"--port NUM"</span>, <span class="ruby-node">"Port for web server (default: #{conf[:port]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
792
|
-
593: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
|
793
|
-
594: }
|
794
|
-
595: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-d"</span>, <span class="ruby-value str">"--daemonize [true|false]"</span>, <span class="ruby-node">"Daemonize (default: #{conf[:daemonize]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
795
|
-
596: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
|
796
|
-
597: }
|
797
|
-
598: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-r"</span>, <span class="ruby-value str">"--root PATH"</span>, <span class="ruby-node">"Working directory (default: #{conf[:root]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
|
798
|
-
599: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
|
799
|
-
600: }
|
800
|
-
601: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-s"</span>, <span class="ruby-value str">"--static PATH"</span>, <span class="ruby-node">"Static directory -- relative to the root directory (default: #{conf[:static]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
801
|
-
602: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
|
802
|
-
603: }
|
803
|
-
604:
|
804
|
-
605: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
805
|
-
606: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
806
|
-
607:
|
807
|
-
608: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-?"</span>, <span class="ruby-value str">"--help"</span>, <span class="ruby-value str">"Show this message"</span>) <span class="ruby-keyword kw">do</span>
|
808
|
-
609: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
809
|
-
610: <span class="ruby-identifier">exit</span>
|
810
|
-
611: <span class="ruby-keyword kw">end</span>
|
811
|
-
612: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-v"</span>, <span class="ruby-value str">"--version"</span>, <span class="ruby-value str">"Show versions"</span>) <span class="ruby-keyword kw">do</span>
|
812
|
-
613: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
813
|
-
614: <span class="ruby-identifier">exit</span>
|
814
|
-
615: <span class="ruby-keyword kw">end</span>
|
815
|
-
616: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>( <span class="ruby-value str">"-V"</span>, <span class="ruby-value str">"--verbose"</span>, <span class="ruby-value str">"Run in verbose mode"</span> ) <span class="ruby-keyword kw">do</span>
|
816
|
-
617: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>] = <span class="ruby-keyword kw">true</span>
|
817
|
-
618: <span class="ruby-keyword kw">end</span>
|
818
|
-
619: <span class="ruby-keyword kw">end</span>
|
819
|
-
620:
|
820
|
-
621: <span class="ruby-keyword kw">begin</span>
|
821
|
-
622: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
822
|
-
623: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
|
823
|
-
624: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
824
|
-
625: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
825
|
-
626: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
826
|
-
627: <span class="ruby-keyword kw">end</span>
|
827
|
-
628:
|
828
|
-
629: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
829
|
-
630: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Go on root directory (#{File.expand_path(conf[:root])})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
830
|
-
631: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] ) <span class="ruby-keyword kw">do</span>
|
831
|
-
632:
|
832
|
-
633: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
833
|
-
634: <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">"mongrel"</span>
|
834
|
-
635: <span class="ruby-keyword kw">begin</span>
|
835
|
-
636: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
836
|
-
637: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
837
|
-
638: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
838
|
-
639: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
839
|
-
640: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
840
|
-
641: <span class="ruby-keyword kw">end</span>
|
841
|
-
642: <span class="ruby-keyword kw">end</span>
|
842
|
-
643:
|
843
|
-
644: <span class="ruby-comment cmt"># From rackup !!!</span>
|
844
|
-
645: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
845
|
-
646: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
|
846
|
-
647: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator"><</span> <span class="ruby-value str">"1.9"</span>
|
847
|
-
648: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
848
|
-
649: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
849
|
-
650: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
850
|
-
651: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
851
|
-
652: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
852
|
-
653: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
853
|
-
654: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
854
|
-
655: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
855
|
-
656: <span class="ruby-keyword kw">else</span>
|
856
|
-
657: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
857
|
-
658: <span class="ruby-keyword kw">end</span>
|
858
|
-
659: <span class="ruby-keyword kw">else</span>
|
859
|
-
660: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
860
|
-
661: <span class="ruby-keyword kw">end</span>
|
861
|
-
662:
|
862
|
-
663: <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">"#{Process.pid}"</span>) }
|
863
|
-
664: <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>]) }
|
864
|
-
665: <span class="ruby-keyword kw">end</span>
|
865
|
-
666:
|
866
|
-
667: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
|
867
|
-
668: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
868
|
-
669: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
|
869
|
-
670: <span class="ruby-keyword kw">else</span>
|
870
|
-
671: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>)
|
871
|
-
672: <span class="ruby-keyword kw">end</span>
|
872
|
-
673: <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>]) )
|
873
|
-
674:
|
874
|
-
675: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
|
875
|
-
676: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
876
|
-
677: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
877
|
-
678: <span class="ruby-identifier">exit</span>
|
878
|
-
679: <span class="ruby-keyword kw">end</span>
|
879
|
-
680:
|
880
|
-
681: <span class="ruby-comment cmt"># Start server</span>
|
881
|
-
682: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
882
|
-
683: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
883
|
-
684: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
884
|
-
685: <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">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">></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>
|
885
|
-
686: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
|
886
|
-
687: }
|
887
|
-
688: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
888
|
-
689: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
889
|
-
690: <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">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">></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>
|
890
|
-
691: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
|
891
|
-
692: }
|
892
|
-
693: <span class="ruby-keyword kw">end</span>
|
893
|
-
694: <span class="ruby-keyword kw">end</span>
|
894
|
-
695: <span class="ruby-keyword kw">end</span>
|
984
|
+
<span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 27</span>
|
985
|
+
27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span> )
|
986
|
+
28: <span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
|
987
|
+
29: <span class="ruby-keyword kw">end</span>
|
895
988
|
</pre>
|
896
989
|
</div>
|
897
990
|
</div>
|
898
991
|
</div>
|
899
992
|
|
900
|
-
<div id="method-
|
901
|
-
<a name="
|
993
|
+
<div id="method-M000008" class="method-detail">
|
994
|
+
<a name="M000008"></a>
|
902
995
|
|
903
996
|
<div class="method-heading">
|
904
|
-
<a href="#
|
905
|
-
<span class="method-name">
|
997
|
+
<a href="#M000008" class="method-signature">
|
998
|
+
<span class="method-name">use</span><span class="method-args">(middleware, *args, &block)</span>
|
906
999
|
</a>
|
907
1000
|
</div>
|
908
1001
|
|
909
1002
|
<div class="method-description">
|
910
1003
|
<p>
|
911
|
-
|
1004
|
+
This method allow you to <a href="Capcode.html#M000008">use</a> a Rack
|
1005
|
+
middleware
|
1006
|
+
</p>
|
1007
|
+
<p>
|
1008
|
+
Example :
|
912
1009
|
</p>
|
1010
|
+
<pre>
|
1011
|
+
module Capcode
|
1012
|
+
...
|
1013
|
+
use Rack::Codehighlighter, :coderay, :element => "pre",
|
1014
|
+
:pattern => /\A:::(\w+)\s*\n/, :logging => false
|
1015
|
+
...
|
1016
|
+
end
|
1017
|
+
</pre>
|
913
1018
|
<p><a class="source-toggle" href="#"
|
914
|
-
onclick="toggleCode('
|
915
|
-
<div class="method-source-code" id="
|
1019
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
1020
|
+
<div class="method-source-code" id="M000008-source">
|
916
1021
|
<pre>
|
917
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
918
|
-
|
919
|
-
|
920
|
-
|
1022
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 485</span>
|
1023
|
+
485: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
1024
|
+
486: <span class="ruby-identifier">middlewares</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span>]
|
1025
|
+
487: <span class="ruby-keyword kw">end</span>
|
921
1026
|
</pre>
|
922
1027
|
</div>
|
923
1028
|
</div>
|