Capcode 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -1
- data/doc/rdoc/classes/Capcode.html +226 -226
- data/doc/rdoc/classes/Capcode/Helpers.html +116 -43
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +17 -2
- data/doc/rdoc/files/lib/capcode_rb.html +1 -1
- data/examples/blog-couchdb.rb +4 -3
- data/examples/erb/cf.rhtml +7 -0
- data/examples/erb/cf_layout.rhtml +8 -0
- data/examples/erb/layout.rhtml +8 -0
- data/examples/erb/m_hello.rhtml +1 -5
- data/examples/haml/cf.haml +4 -0
- data/examples/haml/cf_layout.haml +5 -0
- data/examples/haml/layout.haml +5 -0
- data/examples/haml/m_hello.haml +5 -7
- data/examples/sample.rb +36 -13
- data/lib/capcode.rb +45 -7
- data/lib/capcode/render/erb.rb +18 -3
- data/lib/capcode/render/haml.rb +13 -2
- data/lib/capcode/render/json.rb +1 -1
- data/lib/capcode/render/markaby.rb +10 -3
- data/lib/capcode/render/text.rb +7 -0
- data/lib/capcode/version.rb +1 -1
- metadata +9 -2
@@ -111,10 +111,10 @@ controllers
|
|
111
111
|
<p class="source-link">[ <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show source</a> ]</p>
|
112
112
|
<div id="M000009_source" class="dyn-source">
|
113
113
|
<pre>
|
114
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 27</span>
|
115
|
+
27: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">root=</span>(<span class="ruby-identifier">p</span>)
|
116
|
+
28: <span class="ruby-ivar">@@__ROOT_DIRECTORY</span>=<span class="ruby-identifier">p</span>
|
117
|
+
29: <span class="ruby-keyword kw">end</span>
|
118
118
|
</pre>
|
119
119
|
</div>
|
120
120
|
</div>
|
@@ -146,21 +146,42 @@ then
|
|
146
146
|
<p class="source-link">[ <a href="javascript:toggleSource('M000013_source')" id="l_M000013_source">show source</a> ]</p>
|
147
147
|
<div id="M000013_source" class="dyn-source">
|
148
148
|
<pre>
|
149
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
149
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 120</span>
|
150
|
+
120: <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> )
|
151
|
+
121: <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
|
152
|
+
122: <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> }
|
153
|
+
123:
|
154
|
+
124: <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>
|
155
|
+
125: <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>
|
156
|
+
126: <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>
|
157
|
+
127: <span class="ruby-keyword kw">end</span>
|
158
|
+
128: <span class="ruby-keyword kw">else</span>
|
159
|
+
129: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
|
160
|
+
130: <span class="ruby-keyword kw">end</span>
|
161
|
+
131:
|
162
|
+
132: <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>))
|
163
|
+
133: <span class="ruby-keyword kw">end</span>
|
164
|
+
</pre>
|
165
|
+
</div>
|
166
|
+
</div>
|
167
|
+
<h4 class="ruled">Public Instance method:
|
168
|
+
<strong><a name="M000014">content_for( x ) {|| ...}</a></strong> <a href="#M000014"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: content_for" /></a></h4>
|
169
|
+
|
170
|
+
<p>
|
171
|
+
Calling <a href="Helpers.html#M000014">content_for</a> stores a block of
|
172
|
+
markup in an identifier.
|
173
|
+
</p>
|
174
|
+
|
175
|
+
<div class="sourcecode">
|
176
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000014_source')" id="l_M000014_source">show source</a> ]</p>
|
177
|
+
<div id="M000014_source" class="dyn-source">
|
178
|
+
<pre>
|
179
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 136</span>
|
180
|
+
136: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_for</span>( <span class="ruby-identifier">x</span> )
|
181
|
+
137: <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>)
|
182
|
+
138: <span class="ruby-keyword kw">yield</span>
|
183
|
+
139: <span class="ruby-keyword kw">end</span>
|
184
|
+
140: <span class="ruby-keyword kw">end</span>
|
164
185
|
</pre>
|
165
186
|
</div>
|
166
187
|
</div>
|
@@ -184,12 +205,12 @@ Help you to return a JSON response
|
|
184
205
|
<p class="source-link">[ <a href="javascript:toggleSource('M000011_source')" id="l_M000011_source">show source</a> ]</p>
|
185
206
|
<div id="M000011_source" class="dyn-source">
|
186
207
|
<pre>
|
187
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
208
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 84</span>
|
209
|
+
84: <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>
|
210
|
+
85: <span class="ruby-identifier">warn</span>( <span class="ruby-value str">"json is deprecated, please use `render( :json => ... )'"</span> )
|
211
|
+
86: <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">'application/json'</span>
|
212
|
+
87: <span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_json</span>
|
213
|
+
88: <span class="ruby-keyword kw">end</span>
|
193
214
|
</pre>
|
194
215
|
</div>
|
195
216
|
</div>
|
@@ -217,10 +238,10 @@ Send a <a href="Helpers.html#M000012">redirect</a> response
|
|
217
238
|
<p class="source-link">[ <a href="javascript:toggleSource('M000012_source')" id="l_M000012_source">show source</a> ]</p>
|
218
239
|
<div id="M000012_source" class="dyn-source">
|
219
240
|
<pre>
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
241
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 103</span>
|
242
|
+
103: <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> )
|
243
|
+
104: [<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>]
|
244
|
+
105: <span class="ruby-keyword kw">end</span>
|
224
245
|
</pre>
|
225
246
|
</div>
|
226
247
|
</div>
|
@@ -230,25 +251,77 @@ Send a <a href="Helpers.html#M000012">redirect</a> response
|
|
230
251
|
<p>
|
231
252
|
Render a view
|
232
253
|
</p>
|
254
|
+
<p>
|
255
|
+
<a href="Helpers.html#M000010">render</a>‘s parameter can be a Hash
|
256
|
+
or a string. Passing a string is equivalent to do
|
257
|
+
</p>
|
258
|
+
<pre>
|
259
|
+
render( :text => string )
|
260
|
+
</pre>
|
261
|
+
<p>
|
262
|
+
If you want to use a specific renderer, use one of this options :
|
263
|
+
</p>
|
264
|
+
<ul>
|
265
|
+
<li>:markaby => :my_func : :my_func must be defined in <a
|
266
|
+
href="Views.html">Capcode::Views</a>
|
267
|
+
|
268
|
+
</li>
|
269
|
+
<li>:erb => :my_erb_file : this suppose that‘s my_erb_file.rhtml exist
|
270
|
+
in erb_path
|
271
|
+
|
272
|
+
</li>
|
273
|
+
<li>:haml => :my_haml_file : this suppose that‘s my_haml_file.rhtml
|
274
|
+
exist in haml_path
|
275
|
+
|
276
|
+
</li>
|
277
|
+
<li>:text => "my text"
|
278
|
+
|
279
|
+
</li>
|
280
|
+
<li>:<a href="Helpers.html#M000011">json</a> => MyObject : this suppose
|
281
|
+
that‘s MyObject respond to .to_json
|
282
|
+
|
283
|
+
</li>
|
284
|
+
</ul>
|
285
|
+
<p>
|
286
|
+
If you want to use a specific layout, you can specify it with option
|
287
|
+
</p>
|
288
|
+
<pre>
|
289
|
+
:layout
|
290
|
+
</pre>
|
233
291
|
|
234
292
|
<div class="sourcecode">
|
235
293
|
<p class="source-link">[ <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show source</a> ]</p>
|
236
294
|
<div id="M000010_source" class="dyn-source">
|
237
295
|
<pre>
|
238
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
296
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 46</span>
|
297
|
+
46: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>( <span class="ruby-identifier">h</span> )
|
298
|
+
47: <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>
|
299
|
+
48: <span class="ruby-identifier">render_type</span> = <span class="ruby-keyword kw">nil</span>
|
300
|
+
49:
|
301
|
+
50: <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>
|
302
|
+
51: <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>)
|
303
|
+
52: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span>
|
304
|
+
53: <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>
|
305
|
+
54: <span class="ruby-keyword kw">end</span>
|
306
|
+
55: <span class="ruby-identifier">render_type</span> = <span class="ruby-identifier">k</span>
|
307
|
+
56: <span class="ruby-keyword kw">end</span>
|
308
|
+
57: <span class="ruby-keyword kw">end</span>
|
309
|
+
58:
|
310
|
+
59: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">render_type</span>.<span class="ruby-identifier">nil?</span>
|
311
|
+
60: <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>
|
312
|
+
61: <span class="ruby-keyword kw">end</span>
|
313
|
+
62:
|
314
|
+
63: <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>)
|
315
|
+
64:
|
316
|
+
65: <span class="ruby-keyword kw">begin</span>
|
317
|
+
66: <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> )
|
318
|
+
67: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
319
|
+
68: <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>
|
320
|
+
69: <span class="ruby-keyword kw">end</span>
|
321
|
+
70: <span class="ruby-keyword kw">else</span>
|
322
|
+
71: <span class="ruby-identifier">render</span>( <span class="ruby-identifier">:text</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">h</span> )
|
323
|
+
72: <span class="ruby-keyword kw">end</span>
|
324
|
+
73: <span class="ruby-keyword kw">end</span>
|
252
325
|
</pre>
|
253
326
|
</div>
|
254
327
|
</div>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Mon,
|
1
|
+
Mon, 29 Jun 2009 17:37:38 +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 / Mon Jun
|
84
|
+
<div class="path">README / Mon Jun 29 17:32:18 +0200 2009</div>
|
85
85
|
</div>
|
86
86
|
|
87
87
|
<h1><a href="../classes/Capcode.html">Capcode</a></h1>
|
@@ -98,6 +98,19 @@ 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.6.2</h3>
|
102
|
+
<ul>
|
103
|
+
<li>Add Markaby, Erb and Haml layout see Capcode::Helpers.render for more
|
104
|
+
informations
|
105
|
+
|
106
|
+
</li>
|
107
|
+
<li>Add content_for…
|
108
|
+
|
109
|
+
</li>
|
110
|
+
<li>Major bugs corrections
|
111
|
+
|
112
|
+
</li>
|
113
|
+
</ul>
|
101
114
|
<h3>0.6.1</h3>
|
102
115
|
<ul>
|
103
116
|
<li>Major bugs corrections in haml and erb renderer ($%&! Windows)
|
@@ -109,7 +122,9 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
109
122
|
<li>Add Markaby layout support
|
110
123
|
|
111
124
|
</li>
|
112
|
-
<li>Rewrite blog-couchdb example
|
125
|
+
<li>Rewrite blog-couchdb example (based on the very sympatic camping example :
|
126
|
+
<a
|
127
|
+
href="http://github.com/judofyr/camping/blob/master/examples/blog.rb">github.com/judofyr/camping/blob/master/examples/blog.rb</a>)
|
113
128
|
|
114
129
|
</li>
|
115
130
|
</ul>
|
@@ -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 / Mon Jun
|
84
|
+
<div class="path">lib/capcode.rb / Mon Jun 29 17:30:35 +0200 2009</div>
|
85
85
|
</div>
|
86
86
|
|
87
87
|
<pre>
|
data/examples/blog-couchdb.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
1
2
|
require 'rubygems'
|
2
3
|
require 'capcode'
|
3
4
|
require 'capcode/base/couchdb'
|
@@ -33,7 +34,7 @@ module Capcode
|
|
33
34
|
def get
|
34
35
|
@story = Story.find( :all )
|
35
36
|
|
36
|
-
render( :markaby => :home )
|
37
|
+
render( :markaby => :home, :layout => :my_layout )
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -46,7 +47,7 @@ module Capcode
|
|
46
47
|
|
47
48
|
class Add < Route '/add'
|
48
49
|
def get
|
49
|
-
render( :markaby => :add )
|
50
|
+
render( :markaby => :add, :layout => :my_layout )
|
50
51
|
end
|
51
52
|
def post
|
52
53
|
Story.create( :title => params['title'], :body => params['body'], :create_at => Time.now )
|
@@ -80,7 +81,7 @@ module Capcode::Views
|
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
|
-
def
|
84
|
+
def my_layout
|
84
85
|
html do
|
85
86
|
head do
|
86
87
|
title 'My Blog'
|
data/examples/erb/m_hello.rhtml
CHANGED
data/examples/haml/m_hello.haml
CHANGED
data/examples/sample.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
$:.unshift( "../lib" )
|
2
|
+
require 'rubygems'
|
2
3
|
require 'capcode'
|
3
4
|
require 'capcode/render/markaby'
|
4
5
|
require 'capcode/render/haml'
|
@@ -29,8 +30,7 @@ module Capcode
|
|
29
30
|
|
30
31
|
session = { :user => @you }
|
31
32
|
|
32
|
-
|
33
|
-
render( :markaby => :m_hello )
|
33
|
+
render( :haml => :m_hello )
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,7 +42,7 @@ module Capcode
|
|
42
42
|
|
43
43
|
class Glop < Route '/glop/(.*)', '/glop/code/([^\/]*)/(.*)'
|
44
44
|
def get( r, v )
|
45
|
-
"Glop receive #{r}, type #{r.class} and #{v}, type #{v.class} from #{URL(Glop)}"
|
45
|
+
render( :text => "Glop receive #{r}, type #{r.class} and #{v}, type #{v.class} from #{URL(Glop)}" )
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -57,12 +57,39 @@ module Capcode
|
|
57
57
|
x = env.map do |k,v|
|
58
58
|
"#{k} => #{v}"
|
59
59
|
end.join( "<br />\n" )
|
60
|
-
x
|
60
|
+
render( :text => x )
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class ContentFor < Route '/cf'
|
65
|
+
def get
|
66
|
+
render( :erb => :cf, :layout => :cf_layout )
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
71
|
module Capcode::Views
|
72
|
+
def cf_layout
|
73
|
+
html do
|
74
|
+
head do
|
75
|
+
yield :header
|
76
|
+
end
|
77
|
+
body do
|
78
|
+
yield :content
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def cf
|
84
|
+
content_for :header do
|
85
|
+
title "This is the title!"
|
86
|
+
end
|
87
|
+
|
88
|
+
content_for :content do
|
89
|
+
p "this is the content!"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
66
93
|
def layout
|
67
94
|
html do
|
68
95
|
head do
|
@@ -75,16 +102,12 @@ module Capcode::Views
|
|
75
102
|
end
|
76
103
|
|
77
104
|
def m_hello
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
105
|
+
p do
|
106
|
+
text "Hello "
|
107
|
+
b @you
|
108
|
+
text " it's '#{Time.now} !"
|
109
|
+
end
|
83
110
|
end
|
84
111
|
end
|
85
112
|
|
86
|
-
#Capcode.map( "/file" ) do
|
87
|
-
# Rack::File.new( "." )
|
88
|
-
#end
|
89
|
-
|
90
113
|
Capcode.run( :port => 3001, :host => "localhost", :root => "." )
|
data/lib/capcode.rb
CHANGED
@@ -23,26 +23,55 @@ module Capcode
|
|
23
23
|
# Helpers contains methods available in your controllers
|
24
24
|
module Helpers
|
25
25
|
@@__ROOT_DIRECTORY = ""
|
26
|
+
@@__ARGS__ = nil
|
26
27
|
def self.root=(p)
|
27
28
|
@@__ROOT_DIRECTORY=p
|
28
29
|
end
|
29
30
|
|
30
31
|
# Render a view
|
32
|
+
#
|
33
|
+
# render's parameter can be a Hash or a string. Passing a string is equivalent to do
|
34
|
+
# render( :text => string )
|
35
|
+
#
|
36
|
+
# If you want to use a specific renderer, use one of this options :
|
37
|
+
#
|
38
|
+
# * :markaby => :my_func : :my_func must be defined in Capcode::Views
|
39
|
+
# * :erb => :my_erb_file : this suppose that's my_erb_file.rhtml exist in erb_path
|
40
|
+
# * :haml => :my_haml_file : this suppose that's my_haml_file.rhtml exist in haml_path
|
41
|
+
# * :text => "my text"
|
42
|
+
# * :json => MyObject : this suppose that's MyObject respond to .to_json
|
43
|
+
#
|
44
|
+
# If you want to use a specific layout, you can specify it with option
|
45
|
+
# :layout
|
31
46
|
def render( h )
|
32
47
|
if h.class == Hash
|
33
|
-
|
34
|
-
|
48
|
+
render_type = nil
|
49
|
+
|
50
|
+
h.keys.each do |k|
|
51
|
+
if self.respond_to?("render_#{k.to_s}")
|
52
|
+
unless render_type.nil?
|
53
|
+
raise Capcode::RenderError, "Can't use multiple renderer (`#{render_type}' and `#{k}') !", caller
|
54
|
+
end
|
55
|
+
render_type = k
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if render_type.nil?
|
60
|
+
raise Capcode::RenderError, "Renderer type not specified!", caller
|
61
|
+
end
|
62
|
+
|
63
|
+
render_name = h.delete(render_type)
|
64
|
+
|
35
65
|
begin
|
36
|
-
self.send( "render_#{
|
66
|
+
self.send( "render_#{render_type.to_s}", render_name, h )
|
37
67
|
rescue => e
|
38
|
-
raise Capcode::RenderError, "Error rendering `#{
|
68
|
+
raise Capcode::RenderError, "Error rendering `#{render_type.to_s}' : #{e.message}", caller
|
39
69
|
end
|
40
70
|
else
|
41
|
-
|
71
|
+
render( :text => h )
|
42
72
|
end
|
43
73
|
end
|
44
74
|
|
45
|
-
|
46
75
|
# Help you to return a JSON response
|
47
76
|
#
|
48
77
|
# module Capcode
|
@@ -102,6 +131,13 @@ module Capcode
|
|
102
131
|
|
103
132
|
path+((a.size>0)?("/"+a.join("/")):(""))
|
104
133
|
end
|
134
|
+
|
135
|
+
# Calling content_for stores a block of markup in an identifier.
|
136
|
+
def content_for( x )
|
137
|
+
if @@__ARGS__.map{|_| _.to_s }.include?(x.to_s)
|
138
|
+
yield
|
139
|
+
end
|
140
|
+
end
|
105
141
|
end
|
106
142
|
|
107
143
|
include Rack
|
@@ -165,7 +201,7 @@ module Capcode
|
|
165
201
|
|
166
202
|
[200, {
|
167
203
|
"Last-Modified" => File.mtime(@path).httpdate,
|
168
|
-
"Content-Type" => (MIME::Types.type_for(@path)[0] || '
|
204
|
+
"Content-Type" => (MIME::Types.type_for(@path)[0] || 'text/plain').to_s,
|
169
205
|
"Content-Length" => size.to_s
|
170
206
|
}, body]
|
171
207
|
end
|
@@ -182,6 +218,8 @@ module Capcode
|
|
182
218
|
end
|
183
219
|
|
184
220
|
class << self
|
221
|
+
attr :__args__, true
|
222
|
+
|
185
223
|
# Add routes to a controller class
|
186
224
|
#
|
187
225
|
# module Capcode
|