Capcode 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +58 -2
- data/doc/rdoc/classes/Capcode.html +224 -223
- data/doc/rdoc/classes/Capcode/HTTPError.html +2 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +55 -35
- data/doc/rdoc/classes/Capcode/{RouteError.html → Views.html} +7 -26
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/AUTHORS.html +1 -0
- data/doc/rdoc/files/COPYING.html +1 -0
- data/doc/rdoc/files/README.html +65 -3
- data/doc/rdoc/files/lib/capcode_rb.html +2 -1
- data/examples/sample.rb +11 -3
- data/lib/capcode.rb +12 -8
- data/lib/capcode/version.rb +1 -1
- metadata +3 -4
- data/doc/rdoc/classes/Capcode/ParameterError.html +0 -126
data/README
CHANGED
@@ -10,6 +10,10 @@ Capcode is a web microframework
|
|
10
10
|
|
11
11
|
== FEATURES/PROBLEMS:
|
12
12
|
|
13
|
+
=== 0.4.0
|
14
|
+
* Major bug correction !
|
15
|
+
* Add views...
|
16
|
+
|
13
17
|
=== 0.3.0
|
14
18
|
* Work with Rack 1.0.0
|
15
19
|
|
@@ -38,12 +42,12 @@ Capcode is a web microframework
|
|
38
42
|
|
39
43
|
Capcode.run( )
|
40
44
|
|
41
|
-
|
45
|
+
=== Running Capcode Apps
|
42
46
|
|
43
47
|
* Run: <tt>ruby sample.rb</tt>
|
44
48
|
* Visit http://localhost:3000/
|
45
49
|
|
46
|
-
|
50
|
+
=== Create model
|
47
51
|
|
48
52
|
require 'rubygems'
|
49
53
|
require 'capcode'
|
@@ -60,6 +64,58 @@ Capcode is a web microframework
|
|
60
64
|
|
61
65
|
See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for complete examples.
|
62
66
|
|
67
|
+
=== Create View
|
68
|
+
|
69
|
+
# file: sample.rb
|
70
|
+
require 'rubygems'
|
71
|
+
require 'capcode'
|
72
|
+
|
73
|
+
module Capcode
|
74
|
+
class Hello < Route '/hello'
|
75
|
+
def get
|
76
|
+
@t = Time.now
|
77
|
+
render :time
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module Capcode::Views
|
83
|
+
def time
|
84
|
+
"Hello world #{@t}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
Capcode.run( )
|
89
|
+
|
90
|
+
=== Create Helper
|
91
|
+
|
92
|
+
# file: sample.rb
|
93
|
+
require 'rubygems'
|
94
|
+
require 'capcode'
|
95
|
+
|
96
|
+
module Capcode
|
97
|
+
class Hello < Route '/hello'
|
98
|
+
def get
|
99
|
+
@t = Time.now
|
100
|
+
render :time
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
module Capcode::Helpers
|
106
|
+
def bold( &b )
|
107
|
+
"<b>"+yield+"</b>"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module Capcode::Views
|
112
|
+
def time
|
113
|
+
"Hello world " + bold { @t }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Capcode.run( )
|
118
|
+
|
63
119
|
== REQUIREMENTS:
|
64
120
|
|
65
121
|
* rack
|
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
@@ -92,6 +93,7 @@ end</strong>
|
|
92
93
|
<ul>
|
93
94
|
<li>Rack</li>
|
94
95
|
<li><a href="Capcode/Helpers.html">Capcode::Helpers</a></li>
|
96
|
+
<li><a href="Capcode/Views.html">Capcode::Views</a></li>
|
95
97
|
</ul>
|
96
98
|
|
97
99
|
<h2 class="ruled">Methods</h2>
|
@@ -127,120 +129,116 @@ If the regexp in the route does not match, all arguments will be
|
|
127
129
|
<p class="source-link">[ <a href="javascript:toggleSource('M000001_source')" id="l_M000001_source">show source</a> ]</p>
|
128
130
|
<div id="M000001_source" class="dyn-source">
|
129
131
|
<pre>
|
130
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
239:
|
241
|
-
240: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
242
|
-
241: }
|
243
|
-
242: <span class="ruby-keyword kw">end</span>
|
132
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 137</span>
|
133
|
+
137: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">u</span>
|
134
|
+
138: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
135
|
+
139: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>){
|
136
|
+
140: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'</span>
|
137
|
+
141: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, 2, <Capcode::Klass> ]</span>
|
138
|
+
142: <span class="ruby-identifier">h</span> = {}
|
139
|
+
143: <span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>
|
140
|
+
144: <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>
|
141
|
+
145: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">_u</span> )
|
142
|
+
146: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
143
|
+
147: <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>)
|
144
|
+
148: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-value str">''</span>
|
145
|
+
149: <span class="ruby-keyword kw">else</span>
|
146
|
+
150: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
147
|
+
151: <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>
|
148
|
+
152: <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>)
|
149
|
+
153: <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>]
|
150
|
+
154: <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>
|
151
|
+
155: <span class="ruby-keyword kw">end</span>
|
152
|
+
156: <span class="ruby-keyword kw">end</span>
|
153
|
+
157: [<span class="ruby-identifier">h</span>, <span class="ruby-identifier">max</span>, <span class="ruby-keyword kw">self</span>]
|
154
|
+
158: }
|
155
|
+
159:
|
156
|
+
160: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
157
|
+
161: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
158
|
+
162: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
159
|
+
163: <span class="ruby-keyword kw">end</span>
|
160
|
+
164:
|
161
|
+
165: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
162
|
+
166: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
163
|
+
167: <span class="ruby-ivar">@env</span>
|
164
|
+
168: <span class="ruby-keyword kw">end</span>
|
165
|
+
169:
|
166
|
+
170: <span class="ruby-comment cmt"># Hash session</span>
|
167
|
+
171: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
168
|
+
172: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
169
|
+
173: <span class="ruby-keyword kw">end</span>
|
170
|
+
174:
|
171
|
+
175: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
172
|
+
176: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
173
|
+
177: <span class="ruby-ivar">@request</span>
|
174
|
+
178: <span class="ruby-keyword kw">end</span>
|
175
|
+
179:
|
176
|
+
180: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
177
|
+
181: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
178
|
+
182: <span class="ruby-ivar">@response</span>
|
179
|
+
183: <span class="ruby-keyword kw">end</span>
|
180
|
+
184:
|
181
|
+
185: <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>
|
182
|
+
186: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
183
|
+
187: <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>
|
184
|
+
188: <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>)
|
185
|
+
189:
|
186
|
+
190: <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>]
|
187
|
+
191: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
188
|
+
192: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
189
|
+
193: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
190
|
+
194: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
191
|
+
195:
|
192
|
+
196: <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> )
|
193
|
+
197: <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>
|
194
|
+
198: <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> )
|
195
|
+
199: <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>
|
196
|
+
200: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
197
|
+
201: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
198
|
+
202: <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>
|
199
|
+
203: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
200
|
+
204: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
201
|
+
205: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
202
|
+
206: <span class="ruby-keyword kw">end</span>
|
203
|
+
207: <span class="ruby-keyword kw">end</span>
|
204
|
+
208:
|
205
|
+
209: <span class="ruby-keyword kw">end</span>
|
206
|
+
210:
|
207
|
+
211: <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>]
|
208
|
+
212: <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>] )
|
209
|
+
213:
|
210
|
+
214: <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> ) )
|
211
|
+
215: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
212
|
+
216: <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>
|
213
|
+
217: <span class="ruby-keyword kw">else</span>
|
214
|
+
218: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>
|
215
|
+
219: <span class="ruby-keyword kw">end</span>
|
216
|
+
220:
|
217
|
+
221: <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>
|
218
|
+
222: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
219
|
+
223: <span class="ruby-keyword kw">end</span>
|
220
|
+
224:
|
221
|
+
225: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
222
|
+
226: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
223
|
+
227: <span class="ruby-identifier">post</span>
|
224
|
+
228: <span class="ruby-keyword kw">end</span>
|
225
|
+
229: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
|
226
|
+
230: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
|
227
|
+
231: <span class="ruby-identifier">r</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
228
|
+
232: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
229
|
+
233: <span class="ruby-keyword kw">end</span>
|
230
|
+
234: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
|
231
|
+
235: <span class="ruby-keyword kw">else</span>
|
232
|
+
236: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
233
|
+
237: <span class="ruby-keyword kw">end</span>
|
234
|
+
238:
|
235
|
+
239: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
236
|
+
240: <span class="ruby-keyword kw">end</span>
|
237
|
+
241:
|
238
|
+
242: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
239
|
+
243: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
240
|
+
244: }
|
241
|
+
245: <span class="ruby-keyword kw">end</span>
|
244
242
|
</pre>
|
245
243
|
</div>
|
246
244
|
</div>
|
@@ -255,10 +253,10 @@ Hash containing all the environment variables
|
|
255
253
|
<p class="source-link">[ <a href="javascript:toggleSource('M000003_source')" id="l_M000003_source">show source</a> ]</p>
|
256
254
|
<div id="M000003_source" class="dyn-source">
|
257
255
|
<pre>
|
258
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
259
|
-
|
260
|
-
|
261
|
-
|
256
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 166</span>
|
257
|
+
166: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
258
|
+
167: <span class="ruby-ivar">@env</span>
|
259
|
+
168: <span class="ruby-keyword kw">end</span>
|
262
260
|
</pre>
|
263
261
|
</div>
|
264
262
|
</div>
|
@@ -279,10 +277,10 @@ Rack or What you want Helper
|
|
279
277
|
<p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
|
280
278
|
<div id="M000007_source" class="dyn-source">
|
281
279
|
<pre>
|
282
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
283
|
-
|
284
|
-
|
285
|
-
|
280
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 252</span>
|
281
|
+
252: <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> )
|
282
|
+
253: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
|
283
|
+
254: <span class="ruby-keyword kw">end</span>
|
286
284
|
</pre>
|
287
285
|
</div>
|
288
286
|
</div>
|
@@ -298,10 +296,10 @@ parameters (GET or POST)
|
|
298
296
|
<p class="source-link">[ <a href="javascript:toggleSource('M000002_source')" id="l_M000002_source">show source</a> ]</p>
|
299
297
|
<div id="M000002_source" class="dyn-source">
|
300
298
|
<pre>
|
301
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
302
|
-
|
303
|
-
|
304
|
-
|
299
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 161</span>
|
300
|
+
161: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
301
|
+
162: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
302
|
+
163: <span class="ruby-keyword kw">end</span>
|
305
303
|
</pre>
|
306
304
|
</div>
|
307
305
|
</div>
|
@@ -316,10 +314,10 @@ Return the Rack::Request object
|
|
316
314
|
<p class="source-link">[ <a href="javascript:toggleSource('M000005_source')" id="l_M000005_source">show source</a> ]</p>
|
317
315
|
<div id="M000005_source" class="dyn-source">
|
318
316
|
<pre>
|
319
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
320
|
-
|
321
|
-
|
322
|
-
|
317
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 176</span>
|
318
|
+
176: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
319
|
+
177: <span class="ruby-ivar">@request</span>
|
320
|
+
178: <span class="ruby-keyword kw">end</span>
|
323
321
|
</pre>
|
324
322
|
</div>
|
325
323
|
</div>
|
@@ -334,10 +332,10 @@ Return the Rack::Response object
|
|
334
332
|
<p class="source-link">[ <a href="javascript:toggleSource('M000006_source')" id="l_M000006_source">show source</a> ]</p>
|
335
333
|
<div id="M000006_source" class="dyn-source">
|
336
334
|
<pre>
|
337
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
338
|
-
|
339
|
-
|
340
|
-
|
335
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 181</span>
|
336
|
+
181: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
337
|
+
182: <span class="ruby-ivar">@response</span>
|
338
|
+
183: <span class="ruby-keyword kw">end</span>
|
341
339
|
</pre>
|
342
340
|
</div>
|
343
341
|
</div>
|
@@ -372,6 +370,9 @@ See Rack::Session for more informations
|
|
372
370
|
</li>
|
373
371
|
<li><tt>:daemonize</tt> = Daemonize application (default: false)
|
374
372
|
|
373
|
+
</li>
|
374
|
+
<li><tt>:db_config</tt> = database configuration file (default: database.yml)
|
375
|
+
|
375
376
|
</li>
|
376
377
|
</ul>
|
377
378
|
|
@@ -379,91 +380,91 @@ See Rack::Session for more informations
|
|
379
380
|
<p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
|
380
381
|
<div id="M000008_source" class="dyn-source">
|
381
382
|
<pre>
|
382
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
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
|
-
|
465
|
-
|
466
|
-
|
383
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 267</span>
|
384
|
+
267: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
385
|
+
268: <span class="ruby-identifier">conf</span> = {
|
386
|
+
269: <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>,
|
387
|
+
270: <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>,
|
388
|
+
271: <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>,
|
389
|
+
272: <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>,
|
390
|
+
273: <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>{},
|
391
|
+
274: <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>,
|
392
|
+
275: <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>,
|
393
|
+
276: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">></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>
|
394
|
+
277: }
|
395
|
+
278:
|
396
|
+
279: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
397
|
+
280: <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>
|
398
|
+
281: <span class="ruby-keyword kw">begin</span>
|
399
|
+
282: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
400
|
+
283: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
401
|
+
284: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
402
|
+
285: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
403
|
+
286: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
404
|
+
287: <span class="ruby-keyword kw">end</span>
|
405
|
+
288: <span class="ruby-keyword kw">end</span>
|
406
|
+
289:
|
407
|
+
290: <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>
|
408
|
+
291: <span class="ruby-keyword kw">begin</span>
|
409
|
+
292: <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>
|
410
|
+
293: <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>
|
411
|
+
294: <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>
|
412
|
+
295: <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>)
|
413
|
+
296: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
|
414
|
+
297: <span class="ruby-keyword kw">end</span>
|
415
|
+
298: <span class="ruby-keyword kw">end</span>
|
416
|
+
299: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
417
|
+
300: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
418
|
+
301: <span class="ruby-keyword kw">end</span>
|
419
|
+
302: <span class="ruby-keyword kw">end</span>
|
420
|
+
303:
|
421
|
+
304: <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>)
|
422
|
+
305: <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>] )
|
423
|
+
306: <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>)
|
424
|
+
307: <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>)
|
425
|
+
308: <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>)
|
426
|
+
309: <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>)
|
427
|
+
310: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
428
|
+
311: <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>]) )
|
429
|
+
312:
|
430
|
+
313: <span class="ruby-comment cmt"># From rackup !!!</span>
|
431
|
+
314: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
432
|
+
315: <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>
|
433
|
+
316: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
434
|
+
317: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
435
|
+
318: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
436
|
+
319: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
437
|
+
320: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
438
|
+
321: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
439
|
+
322: <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>
|
440
|
+
323: <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>
|
441
|
+
324: <span class="ruby-keyword kw">else</span>
|
442
|
+
325: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
443
|
+
326: <span class="ruby-keyword kw">end</span>
|
444
|
+
327:
|
445
|
+
328: <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>) }
|
446
|
+
329: <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>]) }
|
447
|
+
330: <span class="ruby-keyword kw">end</span>
|
448
|
+
331:
|
449
|
+
332: <span class="ruby-comment cmt"># Start database</span>
|
450
|
+
333: <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>
|
451
|
+
334: <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>] )
|
452
|
+
335: <span class="ruby-keyword kw">end</span>
|
453
|
+
336:
|
454
|
+
337: <span class="ruby-comment cmt"># Start server</span>
|
455
|
+
338: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
456
|
+
339: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
457
|
+
340: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
458
|
+
341: <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>
|
459
|
+
342: <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> }
|
460
|
+
343: }
|
461
|
+
344: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
462
|
+
345: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
463
|
+
346: <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>
|
464
|
+
347: <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> }
|
465
|
+
348: }
|
466
|
+
349: <span class="ruby-keyword kw">end</span>
|
467
|
+
350: <span class="ruby-keyword kw">end</span>
|
467
468
|
</pre>
|
468
469
|
</div>
|
469
470
|
</div>
|
@@ -478,10 +479,10 @@ Hash <a href="Capcode.html#M000004">session</a>
|
|
478
479
|
<p class="source-link">[ <a href="javascript:toggleSource('M000004_source')" id="l_M000004_source">show source</a> ]</p>
|
479
480
|
<div id="M000004_source" class="dyn-source">
|
480
481
|
<pre>
|
481
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
482
|
-
|
483
|
-
|
484
|
-
|
482
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 171</span>
|
483
|
+
171: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
484
|
+
172: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
485
|
+
173: <span class="ruby-keyword kw">end</span>
|
485
486
|
</pre>
|
486
487
|
</div>
|
487
488
|
</div>
|