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