Capcode 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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>
@@ -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>
@@ -130,21 +131,21 @@ then
130
131
  <p class="source-link">[ <a href="javascript:toggleSource('M000012_source')" id="l_M000012_source">show source</a> ]</p>
131
132
  <div id="M000012_source" class="dyn-source">
132
133
  <pre>
133
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 70</span>
134
- 70: <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> )
135
- 71: <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
136
- 72: <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> }
137
- 73:
138
- 74: <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>
139
- 75: <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>
140
- 76: <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>
141
- 77: <span class="ruby-keyword kw">end</span>
142
- 78: <span class="ruby-keyword kw">else</span>
143
- 79: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
144
- 80: <span class="ruby-keyword kw">end</span>
145
- 81:
146
- 82: <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">&gt;</span><span class="ruby-value">0</span>)<span class="ruby-operator">?</span>(<span class="ruby-value str">&quot;/&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">a</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;/&quot;</span>))<span class="ruby-operator">:</span>(<span class="ruby-value str">&quot;&quot;</span>))
147
- 83: <span class="ruby-keyword kw">end</span>
134
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 85</span>
135
+ 85: <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
+ 86: <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
137
+ 87: <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
+ 88:
139
+ 89: <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
+ 90: <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
+ 91: <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
+ 92: <span class="ruby-keyword kw">end</span>
143
+ 93: <span class="ruby-keyword kw">else</span>
144
+ 94: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
145
+ 95: <span class="ruby-keyword kw">end</span>
146
+ 96:
147
+ 97: <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">&gt;</span><span class="ruby-value">0</span>)<span class="ruby-operator">?</span>(<span class="ruby-value str">&quot;/&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">a</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;/&quot;</span>))<span class="ruby-operator">:</span>(<span class="ruby-value str">&quot;&quot;</span>))
148
+ 98: <span class="ruby-keyword kw">end</span>
148
149
  </pre>
149
150
  </div>
150
151
  </div>
@@ -168,11 +169,12 @@ Help you to return a JSON response
168
169
  <p class="source-link">[ <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show source</a> ]</p>
169
170
  <div id="M000010_source" class="dyn-source">
170
171
  <pre>
171
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 35</span>
172
- 35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">json</span>( <span class="ruby-identifier">d</span> )
173
- 36: <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">'application/json'</span>
174
- 37: <span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_json</span>
175
- 38: <span class="ruby-keyword kw">end</span>
172
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 49</span>
173
+ 49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">json</span>( <span class="ruby-identifier">d</span> )
174
+ 50: <span class="ruby-identifier">warn</span>( <span class="ruby-value str">&quot;json is deprecated, please use `render( :json =&gt; ... )'&quot;</span> )
175
+ 51: <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">'application/json'</span>
176
+ 52: <span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_json</span>
177
+ 53: <span class="ruby-keyword kw">end</span>
176
178
  </pre>
177
179
  </div>
178
180
  </div>
@@ -200,15 +202,15 @@ Send a <a href="Helpers.html#M000011">redirect</a> response
200
202
  <p class="source-link">[ <a href="javascript:toggleSource('M000011_source')" id="l_M000011_source">show source</a> ]</p>
201
203
  <div id="M000011_source" class="dyn-source">
202
204
  <pre>
203
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 53</span>
204
- 53: <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> )
205
- 54: [<span class="ruby-value">302</span>, {<span class="ruby-value str">'Location'</span> =<span class="ruby-operator">&gt;</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>]
206
- 55: <span class="ruby-keyword kw">end</span>
205
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 68</span>
206
+ 68: <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> )
207
+ 69: [<span class="ruby-value">302</span>, {<span class="ruby-value str">'Location'</span> =<span class="ruby-operator">&gt;</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>]
208
+ 70: <span class="ruby-keyword kw">end</span>
207
209
  </pre>
208
210
  </div>
209
211
  </div>
210
212
  <h4 class="ruled">Public Instance method:
211
- <strong><a name="M000009">render( v )</a></strong> <a href="#M000009"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: render" /></a></h4>
213
+ <strong><a name="M000009">render( h )</a></strong> <a href="#M000009"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: render" /></a></h4>
212
214
 
213
215
  <p>
214
216
  Render a view
@@ -218,10 +220,20 @@ Render a view
218
220
  <p class="source-link">[ <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show source</a> ]</p>
219
221
  <div id="M000009_source" class="dyn-source">
220
222
  <pre>
221
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 22</span>
222
- 22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>( <span class="ruby-identifier">v</span> )
223
- 23: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_s</span>
224
- 24: <span class="ruby-keyword kw">end</span>
223
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 25</span>
224
+ 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>( <span class="ruby-identifier">h</span> )
225
+ 26: <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>
226
+ 27: <span class="ruby-identifier">t</span> = (<span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>)[<span class="ruby-value">0</span>]
227
+ 28: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">h</span>[<span class="ruby-identifier">t</span>]
228
+ 29: <span class="ruby-keyword kw">begin</span>
229
+ 30: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>( <span class="ruby-node">&quot;render_#{t.to_s}&quot;</span>, <span class="ruby-identifier">v</span> )
230
+ 31: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
231
+ 32: <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">&quot;Error rendering `#{t.to_s}' : #{e.message}&quot;</span>, <span class="ruby-identifier">caller</span>
232
+ 33: <span class="ruby-keyword kw">end</span>
233
+ 34: <span class="ruby-keyword kw">else</span>
234
+ 35: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">h</span>.<span class="ruby-identifier">to_s</span>)
235
+ 36: <span class="ruby-keyword kw">end</span>
236
+ 37: <span class="ruby-keyword kw">end</span>
225
237
  </pre>
226
238
  </div>
227
239
  </div>
@@ -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>
@@ -1 +1 @@
1
- Thu, 30 Apr 2009 07:38:39 +0200
1
+ Thu, 07 May 2009 17:10:30 +0200
@@ -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>
@@ -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>
@@ -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>
@@ -80,7 +81,7 @@ end</strong>
80
81
  <div id="README" class="page_shade">
81
82
  <div class="page">
82
83
  <div class="header">
83
- <div class="path">README / Thu Apr 30 07:34:27 +0200 2009</div>
84
+ <div class="path">README / Thu May 07 15:41:00 +0200 2009</div>
84
85
  </div>
85
86
 
86
87
  <h1><a href="../classes/Capcode.html">Capcode</a></h1>
@@ -97,6 +98,15 @@ Copyright (C) 2009 Gregoire Lejeune
97
98
  <a href="../classes/Capcode.html">Capcode</a> is a web microframework
98
99
  </p>
99
100
  <h2>FEATURES/PROBLEMS:</h2>
101
+ <h3>0.5.0</h3>
102
+ <ul>
103
+ <li>Add Haml and Markaby renderer
104
+
105
+ </li>
106
+ <li>json is deprecated and replaced by render( :json =&gt; &#8230; )
107
+
108
+ </li>
109
+ </ul>
100
110
  <h3>0.4.0</h3>
101
111
  <ul>
102
112
  <li>Major bug correction !
@@ -135,19 +145,19 @@ Copyright (C) 2009 Gregoire Lejeune
135
145
  </ul>
136
146
  <h2>SYNOPSIS:</h2>
137
147
  <pre>
138
- # file: sample.rb
139
- require 'rubygems'
140
- require 'capcode'
141
-
142
- module Capcode
143
- class Hello &lt; Route '/hello'
144
- def get
145
- &quot;Hello World #{Time.now} !&quot;
146
- end
147
- end
148
- end
149
-
150
- Capcode.run( )
148
+ # file: sample.rb
149
+ require 'rubygems'
150
+ require 'capcode'
151
+
152
+ module Capcode
153
+ class Hello &lt; Route '/hello'
154
+ def get
155
+ &quot;Hello World #{Time.now} !&quot;
156
+ end
157
+ end
158
+ end
159
+
160
+ Capcode.run( )
151
161
  </pre>
152
162
  <h3>Running <a href="../classes/Capcode.html">Capcode</a> Apps</h3>
153
163
  <ul>
@@ -160,73 +170,149 @@ Copyright (C) 2009 Gregoire Lejeune
160
170
  </ul>
161
171
  <h3>Create model</h3>
162
172
  <pre>
163
- require 'rubygems'
164
- require 'capcode'
165
- require 'capcode/base/dm' # or require 'capcode/base/couchdb'
166
-
167
- class Story &lt; Capcode::Base
168
- include Capcode::Resource
169
-
170
- property :id, Integer, :serial =&gt; true # only with DataMapper !
171
- property :title, String
172
- property :body, String
173
- property :date, String
174
- end
173
+ require 'rubygems'
174
+ require 'capcode'
175
+ require 'capcode/base/dm' # or require 'capcode/base/couchdb'
176
+
177
+ class Story &lt; Capcode::Base
178
+ include Capcode::Resource
179
+
180
+ property :id, Integer, :serial =&gt; true # only with DataMapper !
181
+ property :title, String
182
+ property :body, String
183
+ property :date, String
184
+ end
175
185
  </pre>
176
186
  <p>
177
187
  See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt>
178
188
  for complete examples.
179
189
  </p>
180
190
  <h3>Create View</h3>
191
+ <pre>
192
+ # file: sample.rb
193
+ require 'rubygems'
194
+ require 'capcode'
195
+
196
+ module Capcode
197
+ class Hello &lt; Route '/hello'
198
+ def get
199
+ @t = Time.now
200
+ render :time
201
+ end
202
+ end
203
+ end
204
+
205
+ module Capcode::Views
206
+ def time
207
+ &quot;Hello world #{@t}&quot;
208
+ end
209
+ end
210
+
211
+ Capcode.run( )
212
+ </pre>
213
+ <h3>Create Helper</h3>
214
+ <pre>
215
+ # file: sample.rb
216
+ require 'rubygems'
217
+ require 'capcode'
218
+
219
+ module Capcode
220
+ class Hello &lt; Route '/hello'
221
+ def get
222
+ @t = Time.now
223
+ render :time
224
+ end
225
+ end
226
+ end
227
+
228
+ module Capcode::Helpers
229
+ def bold( &amp;b )
230
+ &quot;&lt;b&gt;&quot;+yield+&quot;&lt;/b&gt;&quot;
231
+ end
232
+ end
233
+
234
+ module Capcode::Views
235
+ def time
236
+ &quot;Hello world &quot; + bold { @t }
237
+ end
238
+ end
239
+
240
+ Capcode.run( )
241
+ </pre>
242
+ <h3>Render with Markaby</h3>
243
+ <pre>
244
+ # file: sample.rb
245
+ require 'rubygems'
246
+ require 'capcode'
247
+ require 'capcode/render/markaby'
248
+
249
+ module Capcode
250
+ class Hello &lt; Route '/hello'
251
+ def get
252
+ @t = Time.now
253
+ render :markaby =&gt; :time
254
+ end
255
+ end
256
+ end
257
+
258
+ module Capcode::Views
259
+ def time
260
+ # We use Markaby in Capcode::Views.time
261
+ html do
262
+ body do
263
+ p {
264
+ text &quot;Hello World &quot;
265
+ b @t
266
+ }
267
+ end
268
+ end
269
+ end
270
+ end
271
+
272
+ Capcode.run( )
273
+ </pre>
274
+ <h3>Render with Haml</h3>
181
275
  <pre>
182
276
  # file: sample.rb
183
277
  require 'rubygems'
184
278
  require 'capcode'
279
+ require 'capcode/render/haml'
280
+ Capcode::Helpers.haml_path = &quot;./my_haml_views&quot;
185
281
 
186
282
  module Capcode
187
283
  class Hello &lt; Route '/hello'
188
284
  def get
189
285
  @t = Time.now
190
- render :time
286
+ render :haml =&gt; :time
191
287
  end
192
288
  end
193
289
  end
194
290
 
195
- module Capcode::Views
196
- def time
197
- &quot;Hello world #{@t}&quot;
198
- end
199
- end
200
-
201
291
  Capcode.run( )
292
+
293
+ # ./my_haml_views/time.haml
294
+ %html
295
+ %body
296
+ %p
297
+ Hello World
298
+ = @t
202
299
  </pre>
203
- <h3>Create Helper</h3>
300
+ <h3>Render with JSON</h3>
204
301
  <pre>
205
302
  # file: sample.rb
206
303
  require 'rubygems'
207
304
  require 'capcode'
305
+ require 'capcode/render/json'
208
306
 
209
307
  module Capcode
210
308
  class Hello &lt; Route '/hello'
211
309
  def get
212
310
  @t = Time.now
213
- render :time
311
+ render :json =&gt; { :time =&gt; @t }
214
312
  end
215
313
  end
216
314
  end
217
315
 
218
- module Capcode::Helpers
219
- def bold( &amp;b )
220
- &quot;&lt;b&gt;&quot;+yield+&quot;&lt;/b&gt;&quot;
221
- end
222
- end
223
-
224
- module Capcode::Views
225
- def time
226
- &quot;Hello world &quot; + bold { @t }
227
- end
228
- end
229
-
230
316
  Capcode.run( )
231
317
  </pre>
232
318
  <h2>REQUIREMENTS:</h2>
@@ -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>
@@ -80,7 +81,7 @@ end</strong>
80
81
  <div id="lib/capcode.rb" class="page_shade">
81
82
  <div class="page">
82
83
  <div class="header">
83
- <div class="path">lib/capcode.rb / Thu Apr 30 07:38:28 +0200 2009</div>
84
+ <div class="path">lib/capcode.rb / Thu May 07 15:33:01 +0200 2009</div>
84
85
  </div>
85
86
 
86
87
  <pre>
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ <p>Hello <%= @you %> it's <%= Time.now %></p>
4
+ </body>
5
+ </html>
@@ -0,0 +1,7 @@
1
+ %html
2
+ %body
3
+ %p
4
+ hello
5
+ %b= @you
6
+ it's
7
+ = Time.now
@@ -1,5 +1,11 @@
1
1
  $:.unshift( "../lib" )
2
2
  require 'capcode'
3
+ require 'capcode/render/markaby'
4
+ require 'capcode/render/haml'
5
+ Capcode::Helpers.haml_path = "./haml"
6
+ require 'capcode/render/json'
7
+ require 'capcode/render/erb'
8
+ Capcode::Helpers.erb_path = "./erb"
3
9
 
4
10
  module Capcode
5
11
  module Helpers
@@ -24,7 +30,7 @@ module Capcode
24
30
  session = { :user => @you }
25
31
 
26
32
  # "Hello " + bold { you } + " it's '#{Time.now} !"
27
- render :hello
33
+ render( :erb => :m_hello )
28
34
  end
29
35
  end
30
36
 
@@ -42,7 +48,7 @@ module Capcode
42
48
 
43
49
  class Js < Route '/toto'
44
50
  def get
45
- json( { :some => 'json', :stuff => ['here'] } )
51
+ render( :json => { :some => 'json', :stuff => ['here'] } )
46
52
  end
47
53
  end
48
54
 
@@ -57,8 +63,16 @@ module Capcode
57
63
  end
58
64
 
59
65
  module Capcode::Views
60
- def hello
61
- "Hello " + bold { @you } + " it's '#{Time.now} !"
66
+ def m_hello
67
+ html do
68
+ body do
69
+ p do
70
+ text "Hello "
71
+ b @you
72
+ text " it's '#{Time.now} !"
73
+ end
74
+ end
75
+ end
62
76
  end
63
77
  end
64
78