Capcode 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -0
- data/doc/rdoc/classes/Capcode.html +322 -296
- data/doc/rdoc/classes/Capcode/Helpers.html +59 -59
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +28 -1
- data/doc/rdoc/files/lib/capcode_rb.html +2 -1
- data/examples/sample.rb +3 -3
- data/examples/{index.html → static/index.html} +0 -0
- data/lib/capcode.rb +60 -75
- data/lib/capcode/render/erb.rb +2 -2
- data/lib/capcode/render/haml.rb +3 -3
- data/lib/capcode/render/sass.rb +32 -0
- data/lib/capcode/render/static.rb +8 -0
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/version.rb +1 -1
- metadata +5 -3
@@ -131,21 +131,21 @@ then
|
|
131
131
|
<p class="source-link">[ <a href="javascript:toggleSource('M000012_source')" id="l_M000012_source">show source</a> ]</p>
|
132
132
|
<div id="M000012_source" class="dyn-source">
|
133
133
|
<pre>
|
134
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
134
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 126</span>
|
135
|
+
126: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">URL</span>( <span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span> )
|
136
|
+
127: <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
|
137
|
+
128: <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_if</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> }
|
138
|
+
129:
|
139
|
+
130: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Class</span>
|
140
|
+
131: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
141
|
+
132: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">p</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">klass</span>
|
142
|
+
133: <span class="ruby-keyword kw">end</span>
|
143
|
+
134: <span class="ruby-keyword kw">else</span>
|
144
|
+
135: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
|
145
|
+
136: <span class="ruby-keyword kw">end</span>
|
146
|
+
137:
|
147
|
+
138: <span class="ruby-identifier">path</span><span class="ruby-operator">+</span>((<span class="ruby-identifier">a</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-value str">"/"</span><span class="ruby-operator">+</span><span class="ruby-identifier">a</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"/"</span>))<span class="ruby-operator">:</span>(<span class="ruby-value str">""</span>))
|
148
|
+
139: <span class="ruby-keyword kw">end</span>
|
149
149
|
</pre>
|
150
150
|
</div>
|
151
151
|
</div>
|
@@ -161,12 +161,12 @@ markup in an identifier.
|
|
161
161
|
<p class="source-link">[ <a href="javascript:toggleSource('M000013_source')" id="l_M000013_source">show source</a> ]</p>
|
162
162
|
<div id="M000013_source" class="dyn-source">
|
163
163
|
<pre>
|
164
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
164
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 142</span>
|
165
|
+
142: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_for</span>( <span class="ruby-identifier">x</span> )
|
166
|
+
143: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ARGS__</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_</span>.<span class="ruby-identifier">to_s</span> }.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">x</span>.<span class="ruby-identifier">to_s</span>)
|
167
|
+
144: <span class="ruby-keyword kw">yield</span>
|
168
|
+
145: <span class="ruby-keyword kw">end</span>
|
169
|
+
146: <span class="ruby-keyword kw">end</span>
|
170
170
|
</pre>
|
171
171
|
</div>
|
172
172
|
</div>
|
@@ -190,12 +190,12 @@ Help you to return a JSON response
|
|
190
190
|
<p class="source-link">[ <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show source</a> ]</p>
|
191
191
|
<div id="M000010_source" class="dyn-source">
|
192
192
|
<pre>
|
193
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
193
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 90</span>
|
194
|
+
90: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">json</span>( <span class="ruby-identifier">d</span> ) <span class="ruby-comment cmt">## DELETE THIS IN 1.0.0</span>
|
195
|
+
91: <span class="ruby-identifier">warn</span>( <span class="ruby-value str">"json is deprecated, please use `render( :json => ... )'"</span> )
|
196
|
+
92: <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">'application/json'</span>
|
197
|
+
93: <span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_json</span>
|
198
|
+
94: <span class="ruby-keyword kw">end</span>
|
199
199
|
</pre>
|
200
200
|
</div>
|
201
201
|
</div>
|
@@ -223,10 +223,10 @@ Send a <a href="Helpers.html#M000011">redirect</a> response
|
|
223
223
|
<p class="source-link">[ <a href="javascript:toggleSource('M000011_source')" id="l_M000011_source">show source</a> ]</p>
|
224
224
|
<div id="M000011_source" class="dyn-source">
|
225
225
|
<pre>
|
226
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
227
|
-
|
228
|
-
|
229
|
-
|
226
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 109</span>
|
227
|
+
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">redirect</span>( <span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span> )
|
228
|
+
110: [<span class="ruby-value">302</span>, {<span class="ruby-value str">'Location'</span> =<span class="ruby-operator">></span> <span class="ruby-constant">URL</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)}, <span class="ruby-value str">''</span>]
|
229
|
+
111: <span class="ruby-keyword kw">end</span>
|
230
230
|
</pre>
|
231
231
|
</div>
|
232
232
|
</div>
|
@@ -278,35 +278,35 @@ If you want to use a specific layout, you can specify it with option
|
|
278
278
|
<p class="source-link">[ <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show source</a> ]</p>
|
279
279
|
<div id="M000009_source" class="dyn-source">
|
280
280
|
<pre>
|
281
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
281
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 52</span>
|
282
|
+
52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>( <span class="ruby-identifier">h</span> )
|
283
|
+
53: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Hash</span>
|
284
|
+
54: <span class="ruby-identifier">render_type</span> = <span class="ruby-keyword kw">nil</span>
|
285
|
+
55:
|
286
|
+
56: <span class="ruby-identifier">h</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">k</span><span class="ruby-operator">|</span>
|
287
|
+
57: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">"render_#{k.to_s}"</span>)
|
288
|
+
58: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span>
|
289
|
+
59: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-node">"Can't use multiple renderer (`#{render_type}' and `#{k}') !"</span>, <span class="ruby-identifier">caller</span>
|
290
|
+
60: <span class="ruby-keyword kw">end</span>
|
291
|
+
61: <span class="ruby-identifier">render_type</span> = <span class="ruby-identifier">k</span>
|
292
|
+
62: <span class="ruby-keyword kw">end</span>
|
293
|
+
63: <span class="ruby-keyword kw">end</span>
|
294
|
+
64:
|
295
|
+
65: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span>
|
296
|
+
66: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-value str">"Renderer type not specified!"</span>, <span class="ruby-identifier">caller</span>
|
297
|
+
67: <span class="ruby-keyword kw">end</span>
|
298
|
+
68:
|
299
|
+
69: <span class="ruby-identifier">render_name</span> = <span class="ruby-identifier">h</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">render_type</span>)
|
298
300
|
70:
|
299
|
-
71: <span class="ruby-
|
300
|
-
72:
|
301
|
-
73: <span class="ruby-keyword kw">
|
302
|
-
74: <span class="ruby-
|
303
|
-
75: <span class="ruby-keyword kw">
|
304
|
-
76:
|
305
|
-
77: <span class="ruby-
|
306
|
-
78: <span class="ruby-keyword kw">
|
307
|
-
79:
|
308
|
-
80: <span class="ruby-keyword kw">end</span>
|
309
|
-
81: <span class="ruby-keyword kw">end</span>
|
301
|
+
71: <span class="ruby-keyword kw">begin</span>
|
302
|
+
72: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>( <span class="ruby-node">"render_#{render_type.to_s}"</span>, <span class="ruby-identifier">render_name</span>, <span class="ruby-identifier">h</span> )
|
303
|
+
73: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
304
|
+
74: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RenderError</span>, <span class="ruby-node">"Error rendering `#{render_type.to_s}' : #{e.message}"</span>, <span class="ruby-identifier">caller</span>
|
305
|
+
75: <span class="ruby-keyword kw">end</span>
|
306
|
+
76: <span class="ruby-keyword kw">else</span>
|
307
|
+
77: <span class="ruby-identifier">render</span>( <span class="ruby-identifier">:text</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">h</span> )
|
308
|
+
78: <span class="ruby-keyword kw">end</span>
|
309
|
+
79: <span class="ruby-keyword kw">end</span>
|
310
310
|
</pre>
|
311
311
|
</div>
|
312
312
|
</div>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Wed, 08 Jul 2009 01:50:53 +0200
|
data/doc/rdoc/files/README.html
CHANGED
@@ -81,7 +81,7 @@ end</strong>
|
|
81
81
|
<div id="README" class="page_shade">
|
82
82
|
<div class="page">
|
83
83
|
<div class="header">
|
84
|
-
<div class="path">README /
|
84
|
+
<div class="path">README / Wed Jul 08 01:50:29 +0200 2009</div>
|
85
85
|
</div>
|
86
86
|
|
87
87
|
<h1><a href="../classes/Capcode.html">Capcode</a></h1>
|
@@ -98,6 +98,33 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
98
98
|
<a href="../classes/Capcode.html">Capcode</a> is a web microframework
|
99
99
|
</p>
|
100
100
|
<h2>FEATURES/PROBLEMS:</h2>
|
101
|
+
<h3>0.8.0</h3>
|
102
|
+
<ul>
|
103
|
+
<li>Bugs corrections in haml and text renderer
|
104
|
+
|
105
|
+
</li>
|
106
|
+
<li>Text renderer is now automaticaly included
|
107
|
+
|
108
|
+
</li>
|
109
|
+
<li>Add sass renderer
|
110
|
+
|
111
|
+
</li>
|
112
|
+
<li>:working_directory is no more available
|
113
|
+
|
114
|
+
</li>
|
115
|
+
<li>:root is now the real root directory
|
116
|
+
|
117
|
+
</li>
|
118
|
+
<li>Add :static option to set the directory for static files
|
119
|
+
|
120
|
+
</li>
|
121
|
+
<li>Add -r and -s (for root and static directories) options
|
122
|
+
|
123
|
+
</li>
|
124
|
+
<li>Add static renderer
|
125
|
+
|
126
|
+
</li>
|
127
|
+
</ul>
|
101
128
|
<h3>0.7.1</h3>
|
102
129
|
<ul>
|
103
130
|
<li>You need to include Capcode::Resource in your models !!!!
|
@@ -81,7 +81,7 @@ end</strong>
|
|
81
81
|
<div id="lib/capcode.rb" class="page_shade">
|
82
82
|
<div class="page">
|
83
83
|
<div class="header">
|
84
|
-
<div class="path">lib/capcode.rb /
|
84
|
+
<div class="path">lib/capcode.rb / Wed Jul 08 01:46:27 +0200 2009</div>
|
85
85
|
</div>
|
86
86
|
|
87
87
|
<pre>
|
@@ -524,6 +524,7 @@ License instead of this License.
|
|
524
524
|
<li>mime/types</li>
|
525
525
|
<li>capcode/version</li>
|
526
526
|
<li>capcode/core_ext</li>
|
527
|
+
<li>capcode/render/text</li>
|
527
528
|
<li>mongrel</li>
|
528
529
|
</ul>
|
529
530
|
|
data/examples/sample.rb
CHANGED
@@ -3,10 +3,10 @@ require 'rubygems'
|
|
3
3
|
require 'capcode'
|
4
4
|
require 'capcode/render/markaby'
|
5
5
|
require 'capcode/render/haml'
|
6
|
-
Capcode::Helpers.haml_path = "
|
6
|
+
Capcode::Helpers.haml_path = "haml"
|
7
7
|
require 'capcode/render/json'
|
8
8
|
require 'capcode/render/erb'
|
9
|
-
Capcode::Helpers.erb_path = "
|
9
|
+
Capcode::Helpers.erb_path = "erb"
|
10
10
|
|
11
11
|
module Capcode
|
12
12
|
module Helpers
|
@@ -110,4 +110,4 @@ module Capcode::Views
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
Capcode.run( :port => 3001, :host => "localhost", :
|
113
|
+
Capcode.run( :port => 3001, :host => "localhost", :static => "static" )
|
File without changes
|
data/lib/capcode.rb
CHANGED
@@ -7,9 +7,11 @@ require 'irb'
|
|
7
7
|
require 'mime/types'
|
8
8
|
require 'capcode/version'
|
9
9
|
require 'capcode/core_ext'
|
10
|
+
require 'capcode/render/text'
|
10
11
|
|
11
12
|
module Capcode
|
12
13
|
@@__ROUTES = {}
|
14
|
+
@@__STATIC_DIR = nil
|
13
15
|
|
14
16
|
# @@__FILTERS = []
|
15
17
|
# def self.before_filter( opts, &b )
|
@@ -30,11 +32,7 @@ module Capcode
|
|
30
32
|
|
31
33
|
# Helpers contains methods available in your controllers
|
32
34
|
module Helpers
|
33
|
-
@@__ROOT_DIRECTORY = ""
|
34
35
|
@@__ARGS__ = nil
|
35
|
-
def self.root=(p) #:nodoc:
|
36
|
-
@@__ROOT_DIRECTORY=p
|
37
|
-
end
|
38
36
|
|
39
37
|
# Render a view
|
40
38
|
#
|
@@ -165,66 +163,22 @@ module Capcode
|
|
165
163
|
#
|
166
164
|
# Do the same (r500, r501, r403) to customize 500, 501, 403 errors
|
167
165
|
class HTTPError
|
168
|
-
def initialize(app
|
166
|
+
def initialize(app)#:nodoc:
|
169
167
|
@app = app
|
170
|
-
@root = root
|
171
168
|
end
|
172
169
|
|
173
170
|
def call(env) #:nodoc:
|
174
|
-
|
175
|
-
@status, @headers, @body = @app.call(@env)
|
176
|
-
|
177
|
-
if @status == 404
|
178
|
-
if @env["PATH_INFO"].include? ".."
|
179
|
-
@status = 403
|
180
|
-
@headers = {}
|
181
|
-
@body = '403 - Invalid path'
|
182
|
-
error
|
183
|
-
end
|
184
|
-
|
185
|
-
@path = File.join(@root, @env["PATH_INFO"])
|
186
|
-
begin
|
187
|
-
if File.file?(@path) && File.readable?(@path)
|
188
|
-
serving
|
189
|
-
else
|
190
|
-
tmpPath = File.join(@root, @env["PATH_INFO"], "index.html")
|
191
|
-
if File.file?(tmpPath) && File.readable?(tmpPath) # @env["PATH_INFO"][-1].chr == "/" &&
|
192
|
-
@path = tmpPath
|
193
|
-
serving
|
194
|
-
else
|
195
|
-
raise Errno::EPERM
|
196
|
-
end
|
197
|
-
end
|
198
|
-
rescue SystemCallError
|
199
|
-
error
|
200
|
-
end
|
201
|
-
else
|
202
|
-
error
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def serving #:nodoc:
|
207
|
-
body = open(@path).read
|
208
|
-
size = body.size
|
171
|
+
status, headers, body = @app.call(env)
|
209
172
|
|
210
|
-
|
211
|
-
"
|
212
|
-
|
213
|
-
"Content-Length" => size.to_s
|
214
|
-
}, body]
|
215
|
-
end
|
216
|
-
|
217
|
-
def error #:nodoc:
|
218
|
-
if self.methods.include? "r#{@status}"
|
219
|
-
@body = self.send( "r#{@status}", @env['REQUEST_PATH'] )
|
220
|
-
@headers['Content-Length'] = @body.length.to_s
|
173
|
+
if self.methods.include? "r#{status}"
|
174
|
+
body = self.send( "r#{status}", env['REQUEST_PATH'] )
|
175
|
+
headers['Content-Length'] = body.length.to_s
|
221
176
|
end
|
222
177
|
|
223
|
-
[
|
178
|
+
[status, headers, body]
|
224
179
|
end
|
225
|
-
|
226
180
|
end
|
227
|
-
|
181
|
+
|
228
182
|
class << self
|
229
183
|
attr :__args__, true
|
230
184
|
|
@@ -389,9 +343,11 @@ module Capcode
|
|
389
343
|
# * <tt>:pid</tt> = PID file (default: $0.pid)
|
390
344
|
# * <tt>:daemonize</tt> = Daemonize application (default: false)
|
391
345
|
# * <tt>:db_config</tt> = database configuration file (default: database.yml)
|
392
|
-
# * <tt>:
|
393
|
-
# * <tt>:
|
346
|
+
# * <tt>:static</tt> = Static directory (default: none -- relative to the working directory)
|
347
|
+
# * <tt>:root</tt> = Root directory (default: directory of the main.rb) -- This is also the working directory !
|
394
348
|
def run( args = {} )
|
349
|
+
__VERBOSE = false
|
350
|
+
|
395
351
|
conf = {
|
396
352
|
:port => args[:port]||3000,
|
397
353
|
:host => args[:host]||"localhost",
|
@@ -401,8 +357,8 @@ module Capcode
|
|
401
357
|
:pid => args[:pid]||"#{$0}.pid",
|
402
358
|
:daemonize => args[:daemonize]||false,
|
403
359
|
:db_config => args[:db_config]||"database.yml",
|
404
|
-
:
|
405
|
-
:
|
360
|
+
:static => args[:static]||nil,
|
361
|
+
:root => args[:root]||File.expand_path(File.dirname($0)),
|
406
362
|
|
407
363
|
:console => false
|
408
364
|
}
|
@@ -425,18 +381,27 @@ module Capcode
|
|
425
381
|
opts.on( "-d", "--daemonize [true|false]", "Daemonize (default: #{conf[:daemonize]})" ) { |d|
|
426
382
|
conf[:daemonize] = d
|
427
383
|
}
|
384
|
+
opts.on( "-r", "--root PATH", "Working directory (default: #{conf[:root]})" ) { |w|
|
385
|
+
conf[:root] = w
|
386
|
+
}
|
387
|
+
opts.on( "-s", "--static PATH", "Static directory -- relative to the root directory (default: #{conf[:static]})" ) { |r|
|
388
|
+
conf[:static] = r
|
389
|
+
}
|
428
390
|
|
429
391
|
opts.separator ""
|
430
392
|
opts.separator "Common options:"
|
431
393
|
|
432
|
-
opts.
|
394
|
+
opts.on("-?", "--help", "Show this message") do
|
433
395
|
puts opts
|
434
396
|
exit
|
435
397
|
end
|
436
|
-
opts.
|
398
|
+
opts.on("-v", "--version", "Show versions") do
|
437
399
|
puts "Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"
|
438
400
|
exit
|
439
401
|
end
|
402
|
+
opts.on_tail( "-V", "--verbose", "Run in verbose mode" ) do
|
403
|
+
__VERBOSE = true
|
404
|
+
end
|
440
405
|
end
|
441
406
|
|
442
407
|
begin
|
@@ -448,9 +413,8 @@ module Capcode
|
|
448
413
|
end
|
449
414
|
|
450
415
|
# Run in the Working directory
|
451
|
-
|
452
|
-
|
453
|
-
Capcode::Helpers.root = File.expand_path( conf[:root] )
|
416
|
+
puts "** Go on root directory (#{File.expand_path(conf[:root])})" if __VERBOSE
|
417
|
+
Dir.chdir( conf[:root] ) do
|
454
418
|
|
455
419
|
# Check that mongrel exists
|
456
420
|
if conf[:server].nil? || conf[:server] == "mongrel"
|
@@ -477,9 +441,21 @@ module Capcode
|
|
477
441
|
end
|
478
442
|
end
|
479
443
|
|
444
|
+
# Set Static directory
|
445
|
+
@@__STATIC_DIR = File.expand_path(File.join("/", conf[:static]))
|
446
|
+
|
447
|
+
# Initialize Rack App
|
448
|
+
puts "** Map routes." if __VERBOSE
|
480
449
|
app = Rack::URLMap.new(@@__ROUTES)
|
450
|
+
puts "** Initialize static directory (#{conf[:static]})" if __VERBOSE
|
451
|
+
app = Rack::Static.new(
|
452
|
+
app,
|
453
|
+
:urls => [@@__STATIC_DIR],
|
454
|
+
:root => File.expand_path(conf[:root])
|
455
|
+
) unless conf[:static].nil?
|
456
|
+
puts "** Initialize session" if __VERBOSE
|
481
457
|
app = Rack::Session::Cookie.new( app, conf[:session] )
|
482
|
-
app = Capcode::HTTPError.new(app
|
458
|
+
app = Capcode::HTTPError.new(app)
|
483
459
|
app = Rack::ContentLength.new(app)
|
484
460
|
app = Rack::Lint.new(app)
|
485
461
|
app = Rack::ShowExceptions.new(app)
|
@@ -488,17 +464,21 @@ module Capcode
|
|
488
464
|
|
489
465
|
# From rackup !!!
|
490
466
|
if conf[:daemonize]
|
491
|
-
if
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
467
|
+
if /java/.match(RUBY_PLATFORM).nil?
|
468
|
+
if RUBY_VERSION < "1.9"
|
469
|
+
exit if fork
|
470
|
+
Process.setsid
|
471
|
+
exit if fork
|
472
|
+
# Dir.chdir "/"
|
473
|
+
File.umask 0000
|
474
|
+
STDIN.reopen "/dev/null"
|
475
|
+
STDOUT.reopen "/dev/null", "a"
|
476
|
+
STDERR.reopen "/dev/null", "a"
|
477
|
+
else
|
478
|
+
Process.daemon
|
479
|
+
end
|
500
480
|
else
|
501
|
-
|
481
|
+
puts "!! daemonize option unavailable on #{RUBY_PLATFORM} platform."
|
502
482
|
end
|
503
483
|
|
504
484
|
File.open(conf[:pid], 'w'){ |f| f.write("#{Process.pid}") }
|
@@ -539,5 +519,10 @@ module Capcode
|
|
539
519
|
def routes #:nodoc:
|
540
520
|
@@__ROUTES
|
541
521
|
end
|
522
|
+
|
523
|
+
def static #:nodoc:
|
524
|
+
puts "-------------------- #{@@__STATIC_DIR}"
|
525
|
+
@@__STATIC_DIR
|
526
|
+
end
|
542
527
|
end
|
543
528
|
end
|