Capcode 0.8.2 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/{README → README.rdoc} +12 -1
- data/examples/haml/cf_layout.haml +1 -0
- data/examples/haml/style.sass +2 -0
- data/examples/render-erb.rb +14 -0
- data/examples/render-haml_sass.rb +22 -0
- data/examples/render-json.rb +13 -0
- data/examples/render-markaby.rb +27 -0
- data/examples/render-static.rb +18 -0
- data/examples/render-text.rb +12 -0
- data/examples/render-xml.rb +24 -0
- data/examples/rest.rb +77 -0
- data/examples/upload.rb +4 -4
- data/lib/capcode.rb +118 -44
- data/lib/capcode/base/db.rb +23 -0
- data/lib/capcode/base/dm.rb +11 -11
- data/lib/capcode/render/erb.rb +5 -3
- data/lib/capcode/render/haml.rb +3 -2
- data/lib/capcode/render/json.rb +1 -1
- data/lib/capcode/render/markaby.rb +5 -5
- data/lib/capcode/render/sass.rb +4 -2
- data/lib/capcode/render/static.rb +6 -2
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/render/xml.rb +3 -5
- data/lib/capcode/version.rb +1 -1
- metadata +25 -55
- data/doc/rdoc/classes/Capcode.html +0 -605
- data/doc/rdoc/classes/Capcode/HTTPError.html +0 -129
- data/doc/rdoc/classes/Capcode/Helpers.html +0 -342
- data/doc/rdoc/classes/Capcode/RenderError.html +0 -129
- data/doc/rdoc/classes/Capcode/Views.html +0 -108
- data/doc/rdoc/created.rid +0 -1
- data/doc/rdoc/files/AUTHORS.html +0 -103
- data/doc/rdoc/files/COPYING.html +0 -527
- data/doc/rdoc/files/README.html +0 -478
- data/doc/rdoc/files/lib/capcode_rb.html +0 -541
- data/doc/rdoc/index.html +0 -10
- data/doc/rdoc/permalink.gif +0 -0
- data/doc/rdoc/rdoc-style.css +0 -106
- data/doc/rdoc/rubyfr.png +0 -0
- data/doc/rdoc_iphone/classes/Capcode.html +0 -175
- data/doc/rdoc_iphone/classes/Capcode/HTTPError.html +0 -21
- data/doc/rdoc_iphone/classes/Capcode/Helpers.html +0 -153
- data/doc/rdoc_iphone/classes/Capcode/RenderError.html +0 -21
- data/doc/rdoc_iphone/classes/Capcode/Views.html +0 -21
- data/doc/rdoc_iphone/classes_index.html +0 -10
- data/doc/rdoc_iphone/created.rid +0 -1
- data/doc/rdoc_iphone/files/AUTHORS.html +0 -11
- data/doc/rdoc_iphone/files/COPYING.html +0 -435
- data/doc/rdoc_iphone/files/README.html +0 -325
- data/doc/rdoc_iphone/files/lib/capcode_rb.html +0 -435
- data/doc/rdoc_iphone/files_index.html +0 -7
- data/doc/rdoc_iphone/index.html +0 -51
- data/doc/rdoc_iphone/iui/backButton.png +0 -0
- data/doc/rdoc_iphone/iui/blueButton.png +0 -0
- data/doc/rdoc_iphone/iui/cancel.png +0 -0
- data/doc/rdoc_iphone/iui/grayButton.png +0 -0
- data/doc/rdoc_iphone/iui/iui-logo-touch-icon.png +0 -0
- data/doc/rdoc_iphone/iui/iui.css +0 -386
- data/doc/rdoc_iphone/iui/iui.js +0 -442
- data/doc/rdoc_iphone/iui/iuix.css +0 -1
- data/doc/rdoc_iphone/iui/iuix.js +0 -1
- data/doc/rdoc_iphone/iui/listArrow.png +0 -0
- data/doc/rdoc_iphone/iui/listArrowSel.png +0 -0
- data/doc/rdoc_iphone/iui/listGroup.png +0 -0
- data/doc/rdoc_iphone/iui/loading.gif +0 -0
- data/doc/rdoc_iphone/iui/pinstripes.png +0 -0
- data/doc/rdoc_iphone/iui/selection.png +0 -0
- data/doc/rdoc_iphone/iui/thumb.png +0 -0
- data/doc/rdoc_iphone/iui/toggle.png +0 -0
- data/doc/rdoc_iphone/iui/toggleOn.png +0 -0
- data/doc/rdoc_iphone/iui/toolButton.png +0 -0
- data/doc/rdoc_iphone/iui/toolbar.png +0 -0
- data/doc/rdoc_iphone/iui/whiteButton.png +0 -0
- data/doc/rdoc_iphone/rdoc-style.css +0 -0
data/{README → README.rdoc}
RENAMED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
Copyright (C) 2009 Gregoire Lejeune
|
4
4
|
|
5
|
-
* http://capcode.rubyforge.org
|
5
|
+
* home : http://capcode.rubyforge.org
|
6
|
+
* doc : http://rdoc.info/projects/glejeune/Capcode
|
7
|
+
* book (fr) : http://www.algorithmique.net/capcode/
|
6
8
|
|
7
9
|
== DESCRIPTION:
|
8
10
|
|
@@ -10,6 +12,15 @@ Capcode is a web microframework
|
|
10
12
|
|
11
13
|
== FEATURES/PROBLEMS:
|
12
14
|
|
15
|
+
=== 0.8.4
|
16
|
+
* Major (really MAJOR) bugs corrections in renderers
|
17
|
+
* Add many renderer' examples
|
18
|
+
* The static rendere now accept a new option : :exact_path. If :exact_path is set to true, the static rendere redirect you to the exact static url of the file. Else it just give the content of the file. Default is true. (see example render-static.rb)
|
19
|
+
* redirect now accept an optional HTTP status code as first parameter
|
20
|
+
|
21
|
+
=== 0.8.3
|
22
|
+
* Add PUT and DELETE actions (see rest example)
|
23
|
+
|
13
24
|
=== 0.8.2
|
14
25
|
* Add XML renderer (see rss example)
|
15
26
|
* Major bug corrections
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/haml'
|
4
|
+
require 'capcode/render/sass'
|
5
|
+
Capcode::Helpers.haml_path="haml"
|
6
|
+
Capcode::Helpers.sass_path="haml"
|
7
|
+
|
8
|
+
module Capcode
|
9
|
+
class Index < Route '/'
|
10
|
+
def get
|
11
|
+
render :haml => :cf, :layout => :cf_layout
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class CSS < Route '/style.css'
|
16
|
+
def get
|
17
|
+
render :sass => :style
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Capcode.run( )
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/markaby'
|
4
|
+
|
5
|
+
module Capcode
|
6
|
+
class Index < Route '/'
|
7
|
+
def get
|
8
|
+
render :markaby => :index
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Capcode::Views
|
14
|
+
def glop
|
15
|
+
html do
|
16
|
+
body do
|
17
|
+
yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def index
|
23
|
+
h1 "Hello !"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Capcode.run( )
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/static'
|
4
|
+
|
5
|
+
module Capcode
|
6
|
+
class Index < Route '/'
|
7
|
+
def get
|
8
|
+
render :static => "index.html"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
class Path < Route '/path'
|
12
|
+
def get
|
13
|
+
render :static => "index.html", :exact_path => false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Capcode.run( :static => "static" )
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/xml'
|
4
|
+
|
5
|
+
module Capcode
|
6
|
+
class Index < Route '/'
|
7
|
+
def get
|
8
|
+
render :xml => :index
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Capcode::Views
|
14
|
+
def index
|
15
|
+
xml? :version => '1.0'
|
16
|
+
html do
|
17
|
+
body do
|
18
|
+
h1 "Hello XML !"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Capcode.run( )
|
data/examples/rest.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/markaby'
|
4
|
+
|
5
|
+
module Capcode
|
6
|
+
class Index < Route '/'
|
7
|
+
def get
|
8
|
+
render :markaby => :index, :layout => :forms
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Action < Route "/action"
|
13
|
+
def get( )
|
14
|
+
@method = env["REQUEST_METHOD"]
|
15
|
+
@data = params["data"]
|
16
|
+
render :markaby => :action, :layout => :forms
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :post, :get
|
20
|
+
|
21
|
+
def delete
|
22
|
+
@method = "DELETE"
|
23
|
+
@data = params["data"]
|
24
|
+
render :markaby => :action, :layout => :forms
|
25
|
+
end
|
26
|
+
|
27
|
+
def put
|
28
|
+
@method = "PUT"
|
29
|
+
@data = params["data"]
|
30
|
+
render :markaby => :action, :layout => :forms
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Capcode::Views
|
37
|
+
def forms
|
38
|
+
html do
|
39
|
+
body do
|
40
|
+
yield
|
41
|
+
|
42
|
+
form :method => "GET", :action => URL(Capcode::Action) do
|
43
|
+
input :type => "text", :name => "data";
|
44
|
+
input :type => "submit", :value => "GET"
|
45
|
+
end
|
46
|
+
|
47
|
+
form :method => "POST", :action => URL(Capcode::Action) do
|
48
|
+
input :type => "text", :name => "data";
|
49
|
+
input :type => "submit", :value => "POST"
|
50
|
+
end
|
51
|
+
|
52
|
+
form :method => "POST", :action => URL(Capcode::Action) do
|
53
|
+
input :type => "hidden", :name => "_method", :value => "delete" ## <-- You need this
|
54
|
+
input :type => "text", :name => "data";
|
55
|
+
input :type => "submit", :value => "DELETE"
|
56
|
+
end
|
57
|
+
|
58
|
+
form :method => "POST", :action => URL(Capcode::Action) do
|
59
|
+
input :type => "hidden", :name => "_method", :value => "put" ## <-- You need this
|
60
|
+
input :type => "text", :name => "data";
|
61
|
+
input :type => "submit", :value => "PUT"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def index
|
68
|
+
h1 "Hello !"
|
69
|
+
end
|
70
|
+
|
71
|
+
def action
|
72
|
+
text "You send "; b @data; text " using a "; b @method; text " method!"; br
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
Capcode.run( )
|
data/examples/upload.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
$:.unshift( "../lib" )
|
2
2
|
require 'capcode'
|
3
3
|
require 'capcode/render/markaby'
|
4
4
|
require 'capcode/render/static'
|
@@ -34,6 +34,6 @@ module Capcode::Views
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
Capcode.run( :static => "data" ) {
|
38
|
+
FileUtils.mkdir_p 'data'
|
39
|
+
}
|
data/lib/capcode.rb
CHANGED
@@ -19,15 +19,17 @@ module Capcode
|
|
19
19
|
# @@__FILTERS << opts
|
20
20
|
# end
|
21
21
|
|
22
|
-
|
22
|
+
|
23
|
+
class ParameterError < ArgumentError #:nodoc: all
|
23
24
|
end
|
24
25
|
|
25
|
-
class RouteError < ArgumentError #:nodoc:
|
26
|
+
class RouteError < ArgumentError #:nodoc: all
|
26
27
|
end
|
27
28
|
|
28
|
-
class RenderError < ArgumentError
|
29
|
+
class RenderError < ArgumentError #:nodoc: all
|
29
30
|
end
|
30
31
|
|
32
|
+
# Views is an empty module in which you can store your markaby or xml views.
|
31
33
|
module Views; end
|
32
34
|
|
33
35
|
# Helpers contains methods available in your controllers
|
@@ -43,38 +45,45 @@ module Capcode
|
|
43
45
|
#
|
44
46
|
# * :markaby => :my_func : :my_func must be defined in Capcode::Views
|
45
47
|
# * :erb => :my_erb_file : this suppose that's my_erb_file.rhtml exist in erb_path
|
46
|
-
# * :haml => :my_haml_file : this suppose that's my_haml_file.
|
48
|
+
# * :haml => :my_haml_file : this suppose that's my_haml_file.haml exist in haml_path
|
49
|
+
# * :sass => :my_sass_file : this suppose that's my_sass_file.sass exist in sass_path
|
47
50
|
# * :text => "my text"
|
48
51
|
# * :json => MyObject : this suppose that's MyObject respond to .to_json
|
52
|
+
# * :static => "my_file.xxx" : this suppose that's my_file.xxx exist in the static directory
|
53
|
+
# * :xml => :my_func : :my_func must be defined in Capcode::Views
|
49
54
|
#
|
50
55
|
# If you want to use a specific layout, you can specify it with option
|
51
56
|
# :layout
|
52
|
-
def render(
|
53
|
-
if
|
57
|
+
def render( hash )
|
58
|
+
if hash.class == Hash
|
54
59
|
render_type = nil
|
55
60
|
|
56
|
-
|
57
|
-
if self.respond_to?("render_#{
|
61
|
+
hash.keys.each do |key|
|
62
|
+
if self.respond_to?("render_#{key.to_s}")
|
58
63
|
unless render_type.nil?
|
59
|
-
raise Capcode::RenderError, "Can't use multiple renderer (`#{render_type}' and `#{
|
64
|
+
raise Capcode::RenderError, "Can't use multiple renderer (`#{render_type}' and `#{key}') !", caller
|
60
65
|
end
|
61
|
-
render_type =
|
66
|
+
render_type = key
|
62
67
|
end
|
63
68
|
end
|
64
|
-
|
69
|
+
|
65
70
|
if render_type.nil?
|
66
71
|
raise Capcode::RenderError, "Renderer type not specified!", caller
|
67
72
|
end
|
68
73
|
|
69
|
-
|
74
|
+
unless self.respond_to?("render_#{render_type.to_s}")
|
75
|
+
raise Capcode::RenderError, "#{render_type} renderer not present ! please require 'capcode/render/#{render_type}'", caller
|
76
|
+
end
|
77
|
+
|
78
|
+
render_name = hash.delete(render_type)
|
70
79
|
|
71
80
|
begin
|
72
|
-
self.send( "render_#{render_type.to_s}", render_name,
|
81
|
+
self.send( "render_#{render_type.to_s}", render_name, hash )
|
73
82
|
rescue => e
|
74
83
|
raise Capcode::RenderError, "Error rendering `#{render_type.to_s}' : #{e.message}", caller
|
75
84
|
end
|
76
85
|
else
|
77
|
-
render( :text =>
|
86
|
+
render( :text => hash )
|
78
87
|
end
|
79
88
|
end
|
80
89
|
|
@@ -87,6 +96,8 @@ module Capcode
|
|
87
96
|
# end
|
88
97
|
# end
|
89
98
|
# end
|
99
|
+
#
|
100
|
+
# <b>DEPRECATED</b>, please use <tt>render( :json => o )</tt>
|
90
101
|
def json( d ) ## DELETE THIS IN 1.0.0
|
91
102
|
warn( "json is deprecated, please use `render( :json => ... )'" )
|
92
103
|
@response['Content-Type'] = 'application/json'
|
@@ -106,8 +117,29 @@ module Capcode
|
|
106
117
|
# end
|
107
118
|
# end
|
108
119
|
# end
|
120
|
+
#
|
121
|
+
# The first parameter can be a controller class name
|
122
|
+
#
|
123
|
+
# redirect( MyController )
|
124
|
+
#
|
125
|
+
# it can be a string path
|
126
|
+
#
|
127
|
+
# redirect( "/path/to/my/resource" )
|
128
|
+
#
|
129
|
+
# it can be an http status code (by default <tt>redirect</tt> use the http status code 302)
|
130
|
+
#
|
131
|
+
# redirect( 304, MyController )
|
132
|
+
#
|
133
|
+
# For more informations about HTTP status, see http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
|
109
134
|
def redirect( klass, *a )
|
110
|
-
|
135
|
+
httpCode = 302
|
136
|
+
|
137
|
+
if( klass.class == Fixnum )
|
138
|
+
httpCode = klass
|
139
|
+
klass = a.shift
|
140
|
+
end
|
141
|
+
|
142
|
+
[httpCode, {'Location' => URL(klass, *a)}, '']
|
111
143
|
end
|
112
144
|
|
113
145
|
# Builds an URL route to a controller or a path
|
@@ -122,7 +154,7 @@ module Capcode
|
|
122
154
|
#
|
123
155
|
# then
|
124
156
|
#
|
125
|
-
# URL( Hello, "you" ) # => /hello/you
|
157
|
+
# URL( Capcode::Hello, "you" ) # => /hello/you
|
126
158
|
def URL( klass, *a )
|
127
159
|
path = nil
|
128
160
|
a = a.delete_if{ |x| x.nil? }
|
@@ -139,6 +171,37 @@ module Capcode
|
|
139
171
|
end
|
140
172
|
|
141
173
|
# Calling content_for stores a block of markup in an identifier.
|
174
|
+
#
|
175
|
+
# module Capcode
|
176
|
+
# class ContentFor < Route '/'
|
177
|
+
# def get
|
178
|
+
# render( :markaby => :page, :layout => :layout )
|
179
|
+
# end
|
180
|
+
# end
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# module Capcode::Views
|
184
|
+
# def layout
|
185
|
+
# html do
|
186
|
+
# head do
|
187
|
+
# yield :header
|
188
|
+
# end
|
189
|
+
# body do
|
190
|
+
# yield :content
|
191
|
+
# end
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# def page
|
196
|
+
# content_for :header do
|
197
|
+
# title "This is the title!"
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# content_for :content do
|
201
|
+
# p "this is the content!"
|
202
|
+
# end
|
203
|
+
# end
|
204
|
+
# end
|
142
205
|
def content_for( x )
|
143
206
|
if @@__ARGS__.map{|_| _.to_s }.include?(x.to_s)
|
144
207
|
yield
|
@@ -146,6 +209,9 @@ module Capcode
|
|
146
209
|
end
|
147
210
|
|
148
211
|
# Return information about the static directory
|
212
|
+
#
|
213
|
+
# * <tt>static[:uri]</tt> give the static URI
|
214
|
+
# * <tt>static[:path]</tt> give the path to the static directory on the server
|
149
215
|
def static
|
150
216
|
{
|
151
217
|
:uri => Capcode.static,
|
@@ -171,7 +237,7 @@ module Capcode
|
|
171
237
|
#
|
172
238
|
# Do the same (r500, r501, r403) to customize 500, 501, 403 errors
|
173
239
|
class HTTPError
|
174
|
-
def initialize(app)#:nodoc:
|
240
|
+
def initialize(app) #:nodoc:
|
175
241
|
@app = app
|
176
242
|
end
|
177
243
|
|
@@ -207,29 +273,36 @@ module Capcode
|
|
207
273
|
# be set to <tt>you</tt> and <tt>arg2</tt> will be set to <tt>nil</tt>
|
208
274
|
#
|
209
275
|
# If the regexp in the route does not match, all arguments will be <tt>nil</tt>
|
210
|
-
def Route *
|
276
|
+
def Route *routes_paths
|
211
277
|
Class.new {
|
212
|
-
meta_def(:__urls__){
|
213
|
-
# < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'
|
214
|
-
# # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'},
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
278
|
+
meta_def(:__urls__) {
|
279
|
+
# < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent => /Songbird (\d\.\d)[\d\/]*?/
|
280
|
+
# # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'},
|
281
|
+
# 2,
|
282
|
+
# <Capcode::Klass>,
|
283
|
+
# {:agent => /Songbird (\d\.\d)[\d\/]*?/} ]
|
284
|
+
hash_of_routes = {}
|
285
|
+
max_captures_for_routes = 0
|
286
|
+
routes_paths.each do |current_route_path|
|
287
|
+
if current_route_path.class == String
|
288
|
+
m = /\/([^\/]*\(.*)/.match( current_route_path )
|
289
|
+
if m.nil?
|
290
|
+
raise Capcode::RouteError, "Route `#{current_route_path}' already defined with regexp `#{hash_of_routes[current_route_path]}' !", caller if hash_of_routes.keys.include?(current_route_path)
|
291
|
+
hash_of_routes[current_route_path] = ''
|
292
|
+
else
|
293
|
+
_pre = m.pre_match
|
294
|
+
_pre = "/" if _pre.size == 0
|
295
|
+
raise Capcode::RouteError, "Route `#{_pre}' already defined with regexp `#{hash_of_routes[_pre]}' !", caller if hash_of_routes.keys.include?(_pre)
|
296
|
+
hash_of_routes[_pre] = m.captures[0]
|
297
|
+
max_captures_for_routes = Regexp.new(m.captures[0]).number_of_captures if max_captures_for_routes < Regexp.new(m.captures[0]).number_of_captures
|
298
|
+
end
|
222
299
|
else
|
223
|
-
|
224
|
-
_pre = "/" if _pre.size == 0
|
225
|
-
raise Capcode::RouteError, "Route `#{_pre}' already defined with regexp `#{h[_pre]}' !", caller if h.keys.include?(_pre)
|
226
|
-
h[_pre] = m.captures[0]
|
227
|
-
max = Regexp.new(m.captures[0]).number_of_captures if max < Regexp.new(m.captures[0]).number_of_captures
|
300
|
+
raise Capcode::ParameterError, "Bad route declaration !", caller
|
228
301
|
end
|
229
302
|
end
|
230
|
-
[
|
303
|
+
[hash_of_routes, max_captures_for_routes, self]
|
231
304
|
}
|
232
|
-
|
305
|
+
|
233
306
|
# Hash containing all the request parameters (GET or POST)
|
234
307
|
def params
|
235
308
|
@request.params
|
@@ -240,7 +313,7 @@ module Capcode
|
|
240
313
|
@env
|
241
314
|
end
|
242
315
|
|
243
|
-
#
|
316
|
+
# Session hash
|
244
317
|
def session
|
245
318
|
@env['rack.session']
|
246
319
|
end
|
@@ -311,7 +384,8 @@ module Capcode
|
|
311
384
|
|
312
385
|
get( *args )
|
313
386
|
when "POST"
|
314
|
-
post
|
387
|
+
_method = params.delete( "_method" ) { |_| "post" }
|
388
|
+
send( _method.downcase.to_sym )
|
315
389
|
end
|
316
390
|
if r.respond_to?(:to_ary)
|
317
391
|
@response.status = r[0]
|
@@ -336,8 +410,8 @@ module Capcode
|
|
336
410
|
# Capcode.map( "/file" ) do
|
337
411
|
# Rack::File.new( "." )
|
338
412
|
# end
|
339
|
-
def map(
|
340
|
-
@@__ROUTES[
|
413
|
+
def map( route, &b )
|
414
|
+
@@__ROUTES[route] = yield
|
341
415
|
end
|
342
416
|
|
343
417
|
# Start your application.
|
@@ -438,10 +512,10 @@ module Capcode
|
|
438
512
|
Capcode.constants.each do |k|
|
439
513
|
begin
|
440
514
|
if eval "Capcode::#{k}.public_methods(true).include?( '__urls__' )"
|
441
|
-
|
442
|
-
|
443
|
-
raise Capcode::RouteError, "Route `#{
|
444
|
-
@@__ROUTES[
|
515
|
+
hash_of_routes, max_captures_for_routes, klass = eval "Capcode::#{k}.__urls__"
|
516
|
+
hash_of_routes.keys.each do |current_route_path|
|
517
|
+
raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if @@__ROUTES.keys.include?(current_route_path)
|
518
|
+
@@__ROUTES[current_route_path] = klass.new
|
445
519
|
end
|
446
520
|
end
|
447
521
|
rescue => e
|
@@ -530,6 +604,6 @@ module Capcode
|
|
530
604
|
|
531
605
|
def static #:nodoc:
|
532
606
|
@@__STATIC_DIR
|
533
|
-
end
|
607
|
+
end
|
534
608
|
end
|
535
609
|
end
|