Capcode 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +58 -2
- data/doc/rdoc/classes/Capcode.html +224 -223
- data/doc/rdoc/classes/Capcode/HTTPError.html +2 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +55 -35
- data/doc/rdoc/classes/Capcode/{RouteError.html → Views.html} +7 -26
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/AUTHORS.html +1 -0
- data/doc/rdoc/files/COPYING.html +1 -0
- data/doc/rdoc/files/README.html +65 -3
- data/doc/rdoc/files/lib/capcode_rb.html +2 -1
- data/examples/sample.rb +11 -3
- data/lib/capcode.rb +12 -8
- data/lib/capcode/version.rb +1 -1
- metadata +3 -4
- data/doc/rdoc/classes/Capcode/ParameterError.html +0 -126
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
@@ -113,6 +114,7 @@ Do the same (r500 and r501) to customize 500 and 501 errors
|
|
113
114
|
<ul>
|
114
115
|
<li>Rack</li>
|
115
116
|
<li><a href="Capcode/Helpers.html">Capcode::Helpers</a></li>
|
117
|
+
<li><a href="Capcode/Views.html">Capcode::Views</a></li>
|
116
118
|
</ul>
|
117
119
|
|
118
120
|
|
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
@@ -97,14 +98,15 @@ controllers
|
|
97
98
|
<ul>
|
98
99
|
<li>Rack</li>
|
99
100
|
<li><a href="Capcode/Helpers.html">Capcode::Helpers</a></li>
|
101
|
+
<li><a href="Capcode/Views.html">Capcode::Views</a></li>
|
100
102
|
</ul>
|
101
103
|
|
102
104
|
<h2 class="ruled">Methods</h2>
|
103
105
|
<h4 class="ruled">Public Instance method:
|
104
|
-
<strong><a name="
|
106
|
+
<strong><a name="M000012">URL( klass, *a )</a></strong> <a href="#M000012"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: URL" /></a></h4>
|
105
107
|
|
106
108
|
<p>
|
107
|
-
Builds an <a href="Helpers.html#
|
109
|
+
Builds an <a href="Helpers.html#M000012">URL</a> route to a controller or a
|
108
110
|
path
|
109
111
|
</p>
|
110
112
|
<p>
|
@@ -125,29 +127,29 @@ then
|
|
125
127
|
</pre>
|
126
128
|
|
127
129
|
<div class="sourcecode">
|
128
|
-
<p class="source-link">[ <a href="javascript:toggleSource('
|
129
|
-
<div id="
|
130
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000012_source')" id="l_M000012_source">show source</a> ]</p>
|
131
|
+
<div id="M000012_source" class="dyn-source">
|
130
132
|
<pre>
|
131
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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">></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>))
|
147
|
+
83: <span class="ruby-keyword kw">end</span>
|
146
148
|
</pre>
|
147
149
|
</div>
|
148
150
|
</div>
|
149
151
|
<h4 class="ruled">Public Instance method:
|
150
|
-
<strong><a name="
|
152
|
+
<strong><a name="M000010">json( d )</a></strong> <a href="#M000010"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: json" /></a></h4>
|
151
153
|
|
152
154
|
<p>
|
153
155
|
Help you to return a JSON response
|
@@ -163,22 +165,22 @@ Help you to return a JSON response
|
|
163
165
|
</pre>
|
164
166
|
|
165
167
|
<div class="sourcecode">
|
166
|
-
<p class="source-link">[ <a href="javascript:toggleSource('
|
167
|
-
<div id="
|
168
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show source</a> ]</p>
|
169
|
+
<div id="M000010_source" class="dyn-source">
|
168
170
|
<pre>
|
169
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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>
|
174
176
|
</pre>
|
175
177
|
</div>
|
176
178
|
</div>
|
177
179
|
<h4 class="ruled">Public Instance method:
|
178
|
-
<strong><a name="
|
180
|
+
<strong><a name="M000011">redirect( klass, *a )</a></strong> <a href="#M000011"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: redirect" /></a></h4>
|
179
181
|
|
180
182
|
<p>
|
181
|
-
Send a <a href="Helpers.html#
|
183
|
+
Send a <a href="Helpers.html#M000011">redirect</a> response
|
182
184
|
</p>
|
183
185
|
<pre>
|
184
186
|
module Capcode
|
@@ -195,13 +197,31 @@ Send a <a href="Helpers.html#M000010">redirect</a> response
|
|
195
197
|
</pre>
|
196
198
|
|
197
199
|
<div class="sourcecode">
|
198
|
-
<p class="source-link">[ <a href="javascript:toggleSource('
|
199
|
-
<div id="
|
200
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000011_source')" id="l_M000011_source">show source</a> ]</p>
|
201
|
+
<div id="M000011_source" class="dyn-source">
|
202
|
+
<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">></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>
|
207
|
+
</pre>
|
208
|
+
</div>
|
209
|
+
</div>
|
210
|
+
<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>
|
212
|
+
|
213
|
+
<p>
|
214
|
+
Render a view
|
215
|
+
</p>
|
216
|
+
|
217
|
+
<div class="sourcecode">
|
218
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show source</a> ]</p>
|
219
|
+
<div id="M000009_source" class="dyn-source">
|
200
220
|
<pre>
|
201
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
202
|
-
|
203
|
-
|
204
|
-
|
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>
|
205
225
|
</pre>
|
206
226
|
</div>
|
207
227
|
</div>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<html>
|
4
4
|
<head>
|
5
5
|
<title>
|
6
|
-
Capcode, the Documentation »
|
6
|
+
Capcode, the Documentation » Module: Capcode::Views
|
7
7
|
</title>
|
8
8
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
9
9
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
@@ -50,7 +50,7 @@
|
|
50
50
|
<body>
|
51
51
|
<!--
|
52
52
|
<div id="menu">
|
53
|
-
<h3 class="title">
|
53
|
+
<h3 class="title">Module: Capcode::Views</h3>
|
54
54
|
</div>
|
55
55
|
-->
|
56
56
|
<div id="fullpage">
|
@@ -58,7 +58,7 @@
|
|
58
58
|
<table>
|
59
59
|
<tr><td><img src="../../rubyfr.png" /></td>
|
60
60
|
<td id="pagertd">
|
61
|
-
<strong>#
|
61
|
+
<strong># Module: Capcode::Views<br />
|
62
62
|
[
|
63
63
|
"<a href="../../files/README.html" value="File: README">README</a>",
|
64
64
|
"<a href="../../files/AUTHORS.html" value="File: AUTHORS">AUTHORS</a>",
|
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
@@ -77,35 +78,14 @@ end</strong>
|
|
77
78
|
</div>
|
78
79
|
|
79
80
|
|
80
|
-
<div id="Capcode::
|
81
|
+
<div id="Capcode::Views" class="page_shade">
|
81
82
|
<div class="page">
|
82
|
-
<h3>
|
83
|
+
<h3>Module Capcode::Views</h3>
|
83
84
|
|
84
85
|
(in files
|
85
86
|
<a href="../../files/lib/capcode_rb.html">lib/capcode.rb</a>
|
86
87
|
)
|
87
88
|
|
88
|
-
<p>
|
89
|
-
<a href="HTTPError.html">HTTPError</a> help you to create your own 404, 500
|
90
|
-
and/or 501 response
|
91
|
-
</p>
|
92
|
-
<p>
|
93
|
-
To create a custom 404 reponse, create a fonction HTTPError.r404 in your
|
94
|
-
application :
|
95
|
-
</p>
|
96
|
-
<pre>
|
97
|
-
module Capcode
|
98
|
-
class HTTPError
|
99
|
-
def r404(f)
|
100
|
-
"#{f} not found :("
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
</pre>
|
105
|
-
<p>
|
106
|
-
Do the same (r500 and r501) to customize 500 and 501 errors
|
107
|
-
</p>
|
108
|
-
|
109
89
|
|
110
90
|
|
111
91
|
|
@@ -113,6 +93,7 @@ Do the same (r500 and r501) to customize 500 and 501 errors
|
|
113
93
|
<ul>
|
114
94
|
<li>Rack</li>
|
115
95
|
<li><a href="Capcode/Helpers.html">Capcode::Helpers</a></li>
|
96
|
+
<li><a href="Capcode/Views.html">Capcode::Views</a></li>
|
116
97
|
</ul>
|
117
98
|
|
118
99
|
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Thu, 30 Apr 2009 07:38:39 +0200
|
data/doc/rdoc/files/AUTHORS.html
CHANGED
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
data/doc/rdoc/files/COPYING.html
CHANGED
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
data/doc/rdoc/files/README.html
CHANGED
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
@@ -79,7 +80,7 @@ end</strong>
|
|
79
80
|
<div id="README" class="page_shade">
|
80
81
|
<div class="page">
|
81
82
|
<div class="header">
|
82
|
-
<div class="path">README /
|
83
|
+
<div class="path">README / Thu Apr 30 07:34:27 +0200 2009</div>
|
83
84
|
</div>
|
84
85
|
|
85
86
|
<h1><a href="../classes/Capcode.html">Capcode</a></h1>
|
@@ -96,6 +97,15 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
96
97
|
<a href="../classes/Capcode.html">Capcode</a> is a web microframework
|
97
98
|
</p>
|
98
99
|
<h2>FEATURES/PROBLEMS:</h2>
|
100
|
+
<h3>0.4.0</h3>
|
101
|
+
<ul>
|
102
|
+
<li>Major bug correction !
|
103
|
+
|
104
|
+
</li>
|
105
|
+
<li>Add views…
|
106
|
+
|
107
|
+
</li>
|
108
|
+
</ul>
|
99
109
|
<h3>0.3.0</h3>
|
100
110
|
<ul>
|
101
111
|
<li>Work with Rack 1.0.0
|
@@ -139,7 +149,7 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
139
149
|
|
140
150
|
Capcode.run( )
|
141
151
|
</pre>
|
142
|
-
<
|
152
|
+
<h3>Running <a href="../classes/Capcode.html">Capcode</a> Apps</h3>
|
143
153
|
<ul>
|
144
154
|
<li>Run: <tt>ruby sample.rb</tt>
|
145
155
|
|
@@ -148,7 +158,7 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
148
158
|
|
149
159
|
</li>
|
150
160
|
</ul>
|
151
|
-
<
|
161
|
+
<h3>Create model</h3>
|
152
162
|
<pre>
|
153
163
|
require 'rubygems'
|
154
164
|
require 'capcode'
|
@@ -167,6 +177,58 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
167
177
|
See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt>
|
168
178
|
for complete examples.
|
169
179
|
</p>
|
180
|
+
<h3>Create View</h3>
|
181
|
+
<pre>
|
182
|
+
# file: sample.rb
|
183
|
+
require 'rubygems'
|
184
|
+
require 'capcode'
|
185
|
+
|
186
|
+
module Capcode
|
187
|
+
class Hello < Route '/hello'
|
188
|
+
def get
|
189
|
+
@t = Time.now
|
190
|
+
render :time
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
module Capcode::Views
|
196
|
+
def time
|
197
|
+
"Hello world #{@t}"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
Capcode.run( )
|
202
|
+
</pre>
|
203
|
+
<h3>Create Helper</h3>
|
204
|
+
<pre>
|
205
|
+
# file: sample.rb
|
206
|
+
require 'rubygems'
|
207
|
+
require 'capcode'
|
208
|
+
|
209
|
+
module Capcode
|
210
|
+
class Hello < Route '/hello'
|
211
|
+
def get
|
212
|
+
@t = Time.now
|
213
|
+
render :time
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
module Capcode::Helpers
|
219
|
+
def bold( &b )
|
220
|
+
"<b>"+yield+"</b>"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
module Capcode::Views
|
225
|
+
def time
|
226
|
+
"Hello world " + bold { @t }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
Capcode.run( )
|
231
|
+
</pre>
|
170
232
|
<h2>REQUIREMENTS:</h2>
|
171
233
|
<ul>
|
172
234
|
<li>rack
|
@@ -66,6 +66,7 @@
|
|
66
66
|
"<a href="../../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>",
|
67
67
|
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
68
68
|
<a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
|
69
|
+
<a href="../../classes/Capcode/Views.html" title="Module: Capcode::Views">Capcode::Views</a>.view_html<br />
|
69
70
|
<a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
|
70
71
|
<a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
|
71
72
|
<a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
|
@@ -79,7 +80,7 @@ end</strong>
|
|
79
80
|
<div id="lib/capcode.rb" class="page_shade">
|
80
81
|
<div class="page">
|
81
82
|
<div class="header">
|
82
|
-
<div class="path">lib/capcode.rb /
|
83
|
+
<div class="path">lib/capcode.rb / Thu Apr 30 07:38:28 +0200 2009</div>
|
83
84
|
</div>
|
84
85
|
|
85
86
|
<pre>
|
data/examples/sample.rb
CHANGED
@@ -18,11 +18,13 @@ module Capcode
|
|
18
18
|
|
19
19
|
class Hello < Route '/hello/(.*)'
|
20
20
|
def get( you )
|
21
|
-
you =
|
21
|
+
@you = you
|
22
|
+
@you = "you" if you.nil?
|
22
23
|
|
23
|
-
session = { :user => you }
|
24
|
+
session = { :user => @you }
|
24
25
|
|
25
|
-
"Hello " + bold { you } + " it's '#{Time.now} !"
|
26
|
+
# "Hello " + bold { you } + " it's '#{Time.now} !"
|
27
|
+
render :hello
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -54,6 +56,12 @@ module Capcode
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
59
|
+
module Capcode::Views
|
60
|
+
def hello
|
61
|
+
"Hello " + bold { @you } + " it's '#{Time.now} !"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
57
65
|
Capcode.map( "/file" ) do
|
58
66
|
Rack::File.new( "." )
|
59
67
|
end
|
data/lib/capcode.rb
CHANGED
@@ -8,14 +8,21 @@ require 'capcode/core_ext'
|
|
8
8
|
module Capcode
|
9
9
|
@@__ROUTES = {}
|
10
10
|
|
11
|
-
class ParameterError < ArgumentError
|
11
|
+
class ParameterError < ArgumentError #:nodoc:
|
12
12
|
end
|
13
13
|
|
14
|
-
class RouteError < ArgumentError
|
14
|
+
class RouteError < ArgumentError #:nodoc:
|
15
15
|
end
|
16
16
|
|
17
|
+
module Views; end
|
18
|
+
|
17
19
|
# Helpers contains methods available in your controllers
|
18
20
|
module Helpers
|
21
|
+
# Render a view
|
22
|
+
def render( v )
|
23
|
+
self.send v.to_s
|
24
|
+
end
|
25
|
+
|
19
26
|
# Help you to return a JSON response
|
20
27
|
#
|
21
28
|
# module Capcode
|
@@ -201,15 +208,10 @@ module Capcode
|
|
201
208
|
|
202
209
|
end
|
203
210
|
|
204
|
-
# TODO : correct above to use this :
|
205
|
-
#puts "finalPath = #{finalPath}"
|
206
|
-
#puts "finalNArgs = #{finalNArgs}"
|
207
|
-
#print "finalArgs = "; p finalArgs
|
208
|
-
|
209
211
|
nargs = self.class.__urls__[1]
|
210
212
|
regexp = Regexp.new( self.class.__urls__[0][finalPath] )
|
211
213
|
|
212
|
-
args = regexp.match( Rack::Utils.unescape(@request.
|
214
|
+
args = regexp.match( Rack::Utils.unescape(@request.path).gsub( Regexp.new( "^#{finalPath}" ), "" ).gsub( /^\//, "" ) )
|
213
215
|
if args.nil?
|
214
216
|
raise Capcode::ParameterError, "Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"
|
215
217
|
else
|
@@ -238,6 +240,7 @@ module Capcode
|
|
238
240
|
end
|
239
241
|
|
240
242
|
include Capcode::Helpers
|
243
|
+
include Capcode::Views
|
241
244
|
}
|
242
245
|
end
|
243
246
|
|
@@ -260,6 +263,7 @@ module Capcode
|
|
260
263
|
# * <tt>:session</tt> = Session parameters. See Rack::Session for more informations
|
261
264
|
# * <tt>:pid</tt> = PID file (default: $0.pid)
|
262
265
|
# * <tt>:daemonize</tt> = Daemonize application (default: false)
|
266
|
+
# * <tt>:db_config</tt> = database configuration file (default: database.yml)
|
263
267
|
def run( args = {} )
|
264
268
|
conf = {
|
265
269
|
:port => args[:port]||3000,
|