Capcode 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +8 -1
- data/doc/rdoc/classes/Capcode.html +317 -317
- data/doc/rdoc/classes/Capcode/Helpers.html +22 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +21 -2
- data/doc/rdoc/files/lib/capcode_rb.html +1 -1
- data/examples/rss.rb +48 -0
- data/examples/upload.rb +39 -0
- data/lib/capcode.rb +10 -2
- data/lib/capcode/render/erb.rb +4 -0
- data/lib/capcode/render/haml.rb +5 -1
- data/lib/capcode/render/sass.rb +4 -0
- data/lib/capcode/render/static.rb +2 -2
- data/lib/capcode/render/xml.rb +121 -0
- data/lib/capcode/version.rb +1 -1
- metadata +11 -3
data/README
CHANGED
@@ -10,6 +10,13 @@ Capcode is a web microframework
|
|
10
10
|
|
11
11
|
== FEATURES/PROBLEMS:
|
12
12
|
|
13
|
+
=== 0.8.2
|
14
|
+
* Add XML renderer (see rss example)
|
15
|
+
* Major bug corrections
|
16
|
+
* Add Helpers.static
|
17
|
+
* New example : upload.rb
|
18
|
+
* The database' configuration file is no more relative to the root directory but to the main file
|
19
|
+
|
13
20
|
=== 0.8.1
|
14
21
|
* Sorry for 0.8.0 !!
|
15
22
|
|
@@ -46,7 +53,7 @@ Capcode is a web microframework
|
|
46
53
|
=== 0.6.0
|
47
54
|
* Add :root option to Capcode.run. This option allow you to specify the root directory for static files
|
48
55
|
* Add :working_directory option to Capcode.run. This option allow you to specify the working directory
|
49
|
-
*
|
56
|
+
* If '/' route is not defined but /index.html exist, display index
|
50
57
|
* add mime-types dependency
|
51
58
|
* Bug correction in erb and haml renderer
|
52
59
|
|
@@ -130,130 +130,130 @@ If the regexp in the route does not match, all arguments will be
|
|
130
130
|
<p class="source-link">[ <a href="javascript:toggleSource('M000001_source')" id="l_M000001_source">show source</a> ]</p>
|
131
131
|
<div id="M000001_source" class="dyn-source">
|
132
132
|
<pre>
|
133
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
133
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 210</span>
|
134
|
+
210: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">u</span>
|
135
|
+
211: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
136
|
+
212: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>){
|
137
|
+
213: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'</span>
|
138
|
+
214: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, 2, <Capcode::Klass> ]</span>
|
139
|
+
215: <span class="ruby-identifier">h</span> = {}
|
140
|
+
216: <span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>
|
141
|
+
217: <span class="ruby-identifier">u</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">_u</span><span class="ruby-operator">|</span>
|
142
|
+
218: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">_u</span> )
|
143
|
+
219: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
144
|
+
220: <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 `#{_u}' already defined with regexp `#{h[_u]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
|
145
|
+
221: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-value str">''</span>
|
146
|
+
222: <span class="ruby-keyword kw">else</span>
|
147
|
+
223: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
148
|
+
224: <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>
|
149
|
+
225: <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 `#{h[_pre]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_pre</span>)
|
150
|
+
226: <span class="ruby-identifier">h</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>]
|
151
|
+
227: <span class="ruby-identifier">max</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</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>
|
152
|
+
228: <span class="ruby-keyword kw">end</span>
|
153
|
+
229: <span class="ruby-keyword kw">end</span>
|
154
|
+
230: [<span class="ruby-identifier">h</span>, <span class="ruby-identifier">max</span>, <span class="ruby-keyword kw">self</span>]
|
155
|
+
231: }
|
156
|
+
232:
|
157
|
+
233: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
158
|
+
234: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
159
|
+
235: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
160
|
+
236: <span class="ruby-keyword kw">end</span>
|
161
|
+
237:
|
162
|
+
238: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
163
|
+
239: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
164
|
+
240: <span class="ruby-ivar">@env</span>
|
165
|
+
241: <span class="ruby-keyword kw">end</span>
|
166
|
+
242:
|
167
|
+
243: <span class="ruby-comment cmt"># Hash session</span>
|
168
|
+
244: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
169
|
+
245: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
170
|
+
246: <span class="ruby-keyword kw">end</span>
|
171
|
+
247:
|
172
|
+
248: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
173
|
+
249: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
174
|
+
250: <span class="ruby-ivar">@request</span>
|
175
|
+
251: <span class="ruby-keyword kw">end</span>
|
176
|
+
252:
|
177
|
+
253: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
178
|
+
254: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
179
|
+
255: <span class="ruby-ivar">@response</span>
|
180
|
+
256: <span class="ruby-keyword kw">end</span>
|
181
|
+
257:
|
182
|
+
258: <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>
|
183
|
+
259: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
184
|
+
260: <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>
|
185
|
+
261: <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>)
|
186
|
+
262:
|
187
|
+
263: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
|
188
|
+
264: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
|
189
|
+
265: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
|
190
|
+
266: <span class="ruby-comment cmt"># __run = true</span>
|
191
|
+
267: <span class="ruby-comment cmt"># if f[:only]</span>
|
192
|
+
268: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
|
193
|
+
269: <span class="ruby-comment cmt"># end</span>
|
194
|
+
270: <span class="ruby-comment cmt"># if f[:except]</span>
|
195
|
+
271: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
196
|
+
272: <span class="ruby-comment cmt"># end</span>
|
197
|
+
273: <span class="ruby-comment cmt"># </span>
|
198
|
+
274: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
|
199
|
+
275: <span class="ruby-comment cmt"># puts "call #{proc} for #{__k}"</span>
|
200
|
+
276: <span class="ruby-comment cmt"># end</span>
|
201
|
+
277:
|
202
|
+
278: <span class="ruby-identifier">r</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
203
|
+
279: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
204
|
+
280: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
205
|
+
281: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
206
|
+
282: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
207
|
+
283:
|
208
|
+
284: <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> )
|
209
|
+
285: <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>
|
210
|
+
286: <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> )
|
211
|
+
287: <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>
|
212
|
+
288: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
213
|
+
289: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
214
|
+
290: <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>
|
215
|
+
291: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
216
|
+
292: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
217
|
+
293: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
218
|
+
294: <span class="ruby-keyword kw">end</span>
|
219
|
+
295: <span class="ruby-keyword kw">end</span>
|
220
|
+
296:
|
221
|
+
297: <span class="ruby-keyword kw">end</span>
|
222
|
+
298:
|
223
|
+
299: <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>]
|
224
|
+
300: <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>] )
|
225
|
+
301: <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> ) )
|
226
|
+
302: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
227
|
+
303: <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>
|
228
|
+
304: <span class="ruby-keyword kw">else</span>
|
229
|
+
305: <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> }
|
230
|
+
306: <span class="ruby-keyword kw">end</span>
|
231
|
+
307:
|
232
|
+
308: <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>
|
233
|
+
309: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
234
|
+
310: <span class="ruby-keyword kw">end</span>
|
235
|
+
311:
|
236
|
+
312: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
237
|
+
313: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
238
|
+
314: <span class="ruby-identifier">post</span>
|
239
|
+
315: <span class="ruby-keyword kw">end</span>
|
240
|
+
316: <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>)
|
241
|
+
317: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
|
242
|
+
318: <span class="ruby-identifier">r</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
243
|
+
319: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
244
|
+
320: <span class="ruby-keyword kw">end</span>
|
245
|
+
321: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
|
246
|
+
322: <span class="ruby-keyword kw">else</span>
|
247
|
+
323: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
248
|
+
324: <span class="ruby-keyword kw">end</span>
|
249
|
+
325:
|
250
|
+
326: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
251
|
+
327: <span class="ruby-keyword kw">end</span>
|
252
|
+
328:
|
253
|
+
329: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
254
|
+
330: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
255
|
+
331: }
|
256
|
+
332: <span class="ruby-keyword kw">end</span>
|
257
257
|
</pre>
|
258
258
|
</div>
|
259
259
|
</div>
|
@@ -268,10 +268,10 @@ Hash containing all the environment variables
|
|
268
268
|
<p class="source-link">[ <a href="javascript:toggleSource('M000003_source')" id="l_M000003_source">show source</a> ]</p>
|
269
269
|
<div id="M000003_source" class="dyn-source">
|
270
270
|
<pre>
|
271
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
272
|
-
|
273
|
-
|
274
|
-
|
271
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 239</span>
|
272
|
+
239: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
273
|
+
240: <span class="ruby-ivar">@env</span>
|
274
|
+
241: <span class="ruby-keyword kw">end</span>
|
275
275
|
</pre>
|
276
276
|
</div>
|
277
277
|
</div>
|
@@ -292,10 +292,10 @@ Rack or What you want Helper
|
|
292
292
|
<p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
|
293
293
|
<div id="M000007_source" class="dyn-source">
|
294
294
|
<pre>
|
295
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
296
|
-
|
297
|
-
|
298
|
-
|
295
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 339</span>
|
296
|
+
339: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
297
|
+
340: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
|
298
|
+
341: <span class="ruby-keyword kw">end</span>
|
299
299
|
</pre>
|
300
300
|
</div>
|
301
301
|
</div>
|
@@ -311,10 +311,10 @@ parameters (GET or POST)
|
|
311
311
|
<p class="source-link">[ <a href="javascript:toggleSource('M000002_source')" id="l_M000002_source">show source</a> ]</p>
|
312
312
|
<div id="M000002_source" class="dyn-source">
|
313
313
|
<pre>
|
314
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
315
|
-
|
316
|
-
|
317
|
-
|
314
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 234</span>
|
315
|
+
234: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
316
|
+
235: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
317
|
+
236: <span class="ruby-keyword kw">end</span>
|
318
318
|
</pre>
|
319
319
|
</div>
|
320
320
|
</div>
|
@@ -329,10 +329,10 @@ Return the Rack::Request object
|
|
329
329
|
<p class="source-link">[ <a href="javascript:toggleSource('M000005_source')" id="l_M000005_source">show source</a> ]</p>
|
330
330
|
<div id="M000005_source" class="dyn-source">
|
331
331
|
<pre>
|
332
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
333
|
-
|
334
|
-
|
335
|
-
|
332
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 249</span>
|
333
|
+
249: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
334
|
+
250: <span class="ruby-ivar">@request</span>
|
335
|
+
251: <span class="ruby-keyword kw">end</span>
|
336
336
|
</pre>
|
337
337
|
</div>
|
338
338
|
</div>
|
@@ -347,10 +347,10 @@ Return the Rack::Response object
|
|
347
347
|
<p class="source-link">[ <a href="javascript:toggleSource('M000006_source')" id="l_M000006_source">show source</a> ]</p>
|
348
348
|
<div id="M000006_source" class="dyn-source">
|
349
349
|
<pre>
|
350
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
351
|
-
|
352
|
-
|
353
|
-
|
350
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 254</span>
|
351
|
+
254: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
352
|
+
255: <span class="ruby-ivar">@response</span>
|
353
|
+
256: <span class="ruby-keyword kw">end</span>
|
354
354
|
</pre>
|
355
355
|
</div>
|
356
356
|
</div>
|
@@ -403,177 +403,177 @@ This is also the working directory !
|
|
403
403
|
<p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
|
404
404
|
<div id="M000008_source" class="dyn-source">
|
405
405
|
<pre>
|
406
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
405: <span class="ruby-keyword kw">end</span>
|
465
|
-
406:
|
466
|
-
407: <span class="ruby-keyword kw">begin</span>
|
467
|
-
408: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
468
|
-
409: <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>
|
469
|
-
410: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
470
|
-
411: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
471
|
-
412: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
406
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 356</span>
|
407
|
+
356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
408
|
+
357: <span class="ruby-identifier">__VERBOSE</span> = <span class="ruby-keyword kw">false</span>
|
409
|
+
358:
|
410
|
+
359: <span class="ruby-identifier">conf</span> = {
|
411
|
+
360: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
|
412
|
+
361: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"localhost"</span>,
|
413
|
+
362: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:server</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
|
414
|
+
363: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
|
415
|
+
364: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{},
|
416
|
+
365: <span class="ruby-identifier">:pid</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:pid</span>]<span class="ruby-operator">||</span><span class="ruby-node">"#{$0}.pid"</span>,
|
417
|
+
366: <span class="ruby-identifier">:daemonize</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:daemonize</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">false</span>,
|
418
|
+
367: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">></span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">args</span>[<span class="ruby-identifier">:db_config</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"database.yml"</span>),
|
419
|
+
368: <span class="ruby-identifier">:static</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
|
420
|
+
369: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<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-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">$0</span>)),
|
421
|
+
370:
|
422
|
+
371: <span class="ruby-identifier">:console</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>
|
423
|
+
372: }
|
424
|
+
373:
|
425
|
+
374: <span class="ruby-comment cmt"># Parse options</span>
|
426
|
+
375: <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>
|
427
|
+
376: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
428
|
+
377: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
429
|
+
378: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
430
|
+
379:
|
431
|
+
380: <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> ) {
|
432
|
+
381: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
|
433
|
+
382: }
|
434
|
+
383: <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>
|
435
|
+
384: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
436
|
+
385: }
|
437
|
+
386: <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>
|
438
|
+
387: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
|
439
|
+
388: }
|
440
|
+
389: <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>
|
441
|
+
390: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
|
442
|
+
391: }
|
443
|
+
392: <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>
|
444
|
+
393: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
|
445
|
+
394: }
|
446
|
+
395: <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>
|
447
|
+
396: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
|
448
|
+
397: }
|
449
|
+
398:
|
450
|
+
399: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
451
|
+
400: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
452
|
+
401:
|
453
|
+
402: <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>
|
454
|
+
403: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
455
|
+
404: <span class="ruby-identifier">exit</span>
|
456
|
+
405: <span class="ruby-keyword kw">end</span>
|
457
|
+
406: <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>
|
458
|
+
407: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
459
|
+
408: <span class="ruby-identifier">exit</span>
|
460
|
+
409: <span class="ruby-keyword kw">end</span>
|
461
|
+
410: <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>
|
462
|
+
411: <span class="ruby-identifier">__VERBOSE</span> = <span class="ruby-keyword kw">true</span>
|
463
|
+
412: <span class="ruby-keyword kw">end</span>
|
472
464
|
413: <span class="ruby-keyword kw">end</span>
|
473
465
|
414:
|
474
|
-
415: <span class="ruby-
|
475
|
-
416:
|
476
|
-
417: <span class="ruby-
|
477
|
-
418:
|
478
|
-
419: <span class="ruby-
|
479
|
-
420: <span class="ruby-
|
480
|
-
421:
|
481
|
-
422:
|
482
|
-
423:
|
483
|
-
424:
|
484
|
-
425:
|
485
|
-
426:
|
486
|
-
427:
|
487
|
-
428: <span class="ruby-keyword kw">
|
488
|
-
429:
|
489
|
-
430:
|
490
|
-
431:
|
491
|
-
432:
|
492
|
-
433:
|
493
|
-
434:
|
494
|
-
435:
|
495
|
-
436:
|
496
|
-
437:
|
497
|
-
438:
|
498
|
-
439: <span class="ruby-keyword kw">
|
499
|
-
440: <span class="ruby-
|
500
|
-
441:
|
501
|
-
442:
|
502
|
-
443:
|
503
|
-
444:
|
504
|
-
445:
|
505
|
-
446:
|
506
|
-
447:
|
507
|
-
448:
|
508
|
-
449:
|
509
|
-
450: <span class="ruby-
|
510
|
-
451:
|
511
|
-
452:
|
512
|
-
453:
|
513
|
-
454:
|
514
|
-
455:
|
515
|
-
456: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"**
|
516
|
-
457: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">
|
517
|
-
458: <span class="ruby-identifier">
|
518
|
-
459: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">
|
519
|
-
460:
|
520
|
-
461:
|
521
|
-
462:
|
522
|
-
463:
|
523
|
-
464:
|
524
|
-
465: <span class="ruby-
|
525
|
-
466: <span class="ruby-
|
526
|
-
467:
|
527
|
-
468:
|
528
|
-
469:
|
529
|
-
470:
|
530
|
-
471:
|
531
|
-
472:
|
532
|
-
473:
|
533
|
-
474:
|
534
|
-
475:
|
535
|
-
476:
|
536
|
-
477:
|
537
|
-
478: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">
|
538
|
-
479:
|
539
|
-
480:
|
540
|
-
481:
|
541
|
-
482:
|
542
|
-
483:
|
543
|
-
484:
|
544
|
-
485:
|
545
|
-
486:
|
546
|
-
487:
|
547
|
-
488:
|
548
|
-
489:
|
549
|
-
490: <span class="ruby-
|
550
|
-
491:
|
551
|
-
492:
|
552
|
-
493:
|
553
|
-
494:
|
554
|
-
495:
|
555
|
-
496:
|
556
|
-
497: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">
|
557
|
-
498: <span class="ruby-identifier">
|
558
|
-
499:
|
559
|
-
500:
|
560
|
-
501: <span class="ruby-keyword kw">
|
561
|
-
502:
|
562
|
-
503: <span class="ruby-
|
563
|
-
504:
|
564
|
-
505: <span class="ruby-keyword kw">
|
565
|
-
506: <span class="ruby-identifier">puts</span> <span class="ruby-
|
566
|
-
507: <span class="ruby-constant">
|
567
|
-
508:
|
568
|
-
509:
|
569
|
-
510:
|
570
|
-
511:
|
571
|
-
512:
|
572
|
-
513:
|
573
|
-
514: }
|
574
|
-
515:
|
575
|
-
516:
|
576
|
-
517:
|
466
|
+
415: <span class="ruby-keyword kw">begin</span>
|
467
|
+
416: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
468
|
+
417: <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>
|
469
|
+
418: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
470
|
+
419: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
471
|
+
420: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
472
|
+
421: <span class="ruby-keyword kw">end</span>
|
473
|
+
422:
|
474
|
+
423: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
475
|
+
424: <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">__VERBOSE</span>
|
476
|
+
425: <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>
|
477
|
+
426:
|
478
|
+
427: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
479
|
+
428: <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>
|
480
|
+
429: <span class="ruby-keyword kw">begin</span>
|
481
|
+
430: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
482
|
+
431: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
483
|
+
432: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
484
|
+
433: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
485
|
+
434: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
486
|
+
435: <span class="ruby-keyword kw">end</span>
|
487
|
+
436: <span class="ruby-keyword kw">end</span>
|
488
|
+
437:
|
489
|
+
438: <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>
|
490
|
+
439: <span class="ruby-keyword kw">begin</span>
|
491
|
+
440: <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>
|
492
|
+
441: <span class="ruby-identifier">u</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.__urls__"</span>
|
493
|
+
442: <span class="ruby-identifier">u</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">_u</span><span class="ruby-operator">|</span>
|
494
|
+
443: <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 `#{_u}' already define !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ROUTES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
|
495
|
+
444: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
|
496
|
+
445: <span class="ruby-keyword kw">end</span>
|
497
|
+
446: <span class="ruby-keyword kw">end</span>
|
498
|
+
447: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
499
|
+
448: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
500
|
+
449: <span class="ruby-keyword kw">end</span>
|
501
|
+
450: <span class="ruby-keyword kw">end</span>
|
502
|
+
451:
|
503
|
+
452: <span class="ruby-comment cmt"># Set Static directory</span>
|
504
|
+
453: <span class="ruby-ivar">@@__STATIC_DIR</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>
|
505
|
+
454:
|
506
|
+
455: <span class="ruby-comment cmt"># Initialize Rack App</span>
|
507
|
+
456: <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">__VERBOSE</span>
|
508
|
+
457: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@@__ROUTES</span>)
|
509
|
+
458: <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">__VERBOSE</span>
|
510
|
+
459: <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>(
|
511
|
+
460: <span class="ruby-identifier">app</span>,
|
512
|
+
461: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">></span> [<span class="ruby-ivar">@@__STATIC_DIR</span>],
|
513
|
+
462: <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>])
|
514
|
+
463: ) <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>
|
515
|
+
464: <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">__VERBOSE</span>
|
516
|
+
465: <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>] )
|
517
|
+
466: <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>)
|
518
|
+
467: <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>)
|
519
|
+
468: <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>)
|
520
|
+
469: <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>)
|
521
|
+
470: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
522
|
+
471: <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>]) )
|
523
|
+
472:
|
524
|
+
473: <span class="ruby-comment cmt"># From rackup !!!</span>
|
525
|
+
474: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
526
|
+
475: <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>
|
527
|
+
476: <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>
|
528
|
+
477: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
529
|
+
478: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
530
|
+
479: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
531
|
+
480: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
532
|
+
481: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
533
|
+
482: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
534
|
+
483: <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>
|
535
|
+
484: <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>
|
536
|
+
485: <span class="ruby-keyword kw">else</span>
|
537
|
+
486: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
538
|
+
487: <span class="ruby-keyword kw">end</span>
|
539
|
+
488: <span class="ruby-keyword kw">else</span>
|
540
|
+
489: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
541
|
+
490: <span class="ruby-keyword kw">end</span>
|
542
|
+
491:
|
543
|
+
492: <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>) }
|
544
|
+
493: <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>]) }
|
545
|
+
494: <span class="ruby-keyword kw">end</span>
|
546
|
+
495:
|
547
|
+
496: <span class="ruby-comment cmt"># Start database</span>
|
548
|
+
497: <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>
|
549
|
+
498: <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>] )
|
550
|
+
499: <span class="ruby-keyword kw">end</span>
|
551
|
+
500:
|
552
|
+
501: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
553
|
+
502: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
554
|
+
503: <span class="ruby-keyword kw">end</span>
|
555
|
+
504:
|
556
|
+
505: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
|
557
|
+
506: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
558
|
+
507: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
559
|
+
508: <span class="ruby-identifier">exit</span>
|
560
|
+
509: <span class="ruby-keyword kw">end</span>
|
561
|
+
510:
|
562
|
+
511: <span class="ruby-comment cmt"># Start server</span>
|
563
|
+
512: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
564
|
+
513: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
565
|
+
514: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
566
|
+
515: <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>
|
567
|
+
516: <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> }
|
568
|
+
517: }
|
569
|
+
518: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
570
|
+
519: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
571
|
+
520: <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>
|
572
|
+
521: <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> }
|
573
|
+
522: }
|
574
|
+
523: <span class="ruby-keyword kw">end</span>
|
575
|
+
524: <span class="ruby-keyword kw">end</span>
|
576
|
+
525: <span class="ruby-keyword kw">end</span>
|
577
577
|
</pre>
|
578
578
|
</div>
|
579
579
|
</div>
|
@@ -588,10 +588,10 @@ Hash <a href="Capcode.html#M000004">session</a>
|
|
588
588
|
<p class="source-link">[ <a href="javascript:toggleSource('M000004_source')" id="l_M000004_source">show source</a> ]</p>
|
589
589
|
<div id="M000004_source" class="dyn-source">
|
590
590
|
<pre>
|
591
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
592
|
-
|
593
|
-
|
594
|
-
|
591
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 244</span>
|
592
|
+
244: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
593
|
+
245: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
594
|
+
246: <span class="ruby-keyword kw">end</span>
|
595
595
|
</pre>
|
596
596
|
</div>
|
597
597
|
</div>
|