ramaze 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +52 -19
- data/bin/ramaze +19 -6
- data/doc/CHANGELOG +33 -0
- data/doc/COPYING +1 -1
- data/doc/FAQ +92 -0
- data/doc/GPL +340 -0
- data/doc/INSTALL +34 -0
- data/doc/ProjectInfo +53 -0
- data/doc/README +187 -110
- data/doc/readme_chunks/appendix.txt +13 -0
- data/doc/readme_chunks/examples.txt +38 -0
- data/doc/readme_chunks/features.txt +82 -0
- data/doc/readme_chunks/getting_help.txt +5 -0
- data/doc/readme_chunks/getting_started.txt +18 -0
- data/doc/readme_chunks/installing.txt +41 -0
- data/doc/readme_chunks/introduction.txt +18 -0
- data/doc/readme_chunks/principles.txt +41 -0
- data/doc/readme_chunks/thanks.txt +59 -0
- data/doc/tutorial/todolist.txt +546 -0
- data/examples/blog/main.rb +1 -1
- data/examples/blog/src/controller.rb +13 -11
- data/examples/blog/src/element.rb +11 -6
- data/examples/blog/src/model.rb +8 -23
- data/examples/blog/template/edit.xhtml +3 -1
- data/examples/blog/template/index.xhtml +4 -4
- data/examples/caching.rb +4 -4
- data/examples/element.rb +10 -7
- data/examples/hello.rb +3 -4
- data/examples/simple.rb +5 -3
- data/examples/templates/template/external.amrita +19 -0
- data/examples/templates/template/{external.rmze → external.zmr} +2 -2
- data/examples/templates/template_amrita2.rb +48 -0
- data/examples/templates/template_erubis.rb +5 -2
- data/examples/templates/{template_ramaze.rb → template_ezamar.rb} +13 -7
- data/examples/templates/template_haml.rb +4 -1
- data/examples/templates/template_liquid.rb +2 -1
- data/examples/templates/template_markaby.rb +2 -1
- data/examples/todolist/conf/benchmark.yaml +35 -0
- data/examples/todolist/conf/debug.yaml +34 -0
- data/examples/todolist/conf/live.yaml +33 -0
- data/examples/todolist/conf/silent.yaml +31 -0
- data/examples/todolist/conf/stage.yaml +33 -0
- data/examples/todolist/main.rb +18 -0
- data/examples/todolist/public/404.jpg +0 -0
- data/examples/todolist/public/css/coderay.css +105 -0
- data/examples/todolist/public/css/ramaze_error.css +42 -0
- data/{lib/proto → examples/todolist}/public/error.xhtml +0 -0
- data/examples/todolist/public/favicon.ico +0 -0
- data/examples/todolist/public/js/jquery.js +1923 -0
- data/examples/todolist/public/ramaze.png +0 -0
- data/examples/todolist/src/controller/main.rb +56 -0
- data/examples/todolist/src/element/page.rb +26 -0
- data/examples/todolist/src/model.rb +14 -0
- data/examples/todolist/template/index.xhtml +17 -0
- data/examples/todolist/template/new.xhtml +7 -0
- data/examples/todolist/todolist.db +9 -0
- data/examples/whywiki/main.rb +3 -8
- data/examples/whywiki/template/show.xhtml +4 -0
- data/lib/proto/public/error.zmr +77 -0
- data/lib/proto/src/controller/main.rb +2 -1
- data/lib/proto/src/element/page.rb +2 -1
- data/lib/proto/src/model.rb +3 -2
- data/lib/ramaze.rb +7 -9
- data/lib/ramaze/adapter.rb +51 -0
- data/lib/ramaze/adapter/cgi.rb +23 -0
- data/lib/ramaze/adapter/fcgi.rb +22 -0
- data/lib/ramaze/adapter/mongrel.rb +7 -86
- data/lib/ramaze/adapter/webrick.rb +14 -133
- data/lib/ramaze/cache/memcached.rb +6 -0
- data/lib/ramaze/cache/yaml_store.rb +3 -1
- data/lib/ramaze/controller.rb +292 -2
- data/lib/ramaze/dispatcher.rb +85 -213
- data/lib/ramaze/error.rb +10 -0
- data/lib/ramaze/global.rb +8 -0
- data/lib/ramaze/helper/aspect.rb +30 -7
- data/lib/ramaze/helper/auth.rb +16 -9
- data/lib/ramaze/helper/cache.rb +40 -35
- data/lib/ramaze/helper/feed.rb +1 -1
- data/lib/ramaze/helper/flash.rb +34 -0
- data/lib/ramaze/helper/link.rb +8 -2
- data/lib/ramaze/helper/openid.rb +63 -0
- data/lib/ramaze/helper/redirect.rb +12 -11
- data/lib/ramaze/helper/stack.rb +5 -7
- data/lib/ramaze/inform.rb +12 -1
- data/lib/ramaze/snippets/kernel/aquire.rb +1 -1
- data/lib/ramaze/snippets/kernel/{self_method.rb → method.rb} +3 -18
- data/lib/ramaze/snippets/kernel/{rescue_require.rb → pretty_inspect.rb} +7 -6
- data/lib/ramaze/snippets/method/name.rb +22 -0
- data/lib/ramaze/snippets/{kernel → ramaze}/autoreload.rb +0 -0
- data/lib/ramaze/snippets/ramaze/caller_info.rb +14 -0
- data/lib/ramaze/snippets/{kernel → ramaze}/caller_lines.rb +3 -10
- data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +49 -23
- data/lib/ramaze/snippets/string/DIVIDE.rb +0 -1
- data/lib/ramaze/store/default.rb +58 -2
- data/lib/ramaze/store/yaml.rb +161 -0
- data/lib/ramaze/template.rb +27 -86
- data/lib/ramaze/template/amrita2.rb +14 -19
- data/lib/ramaze/template/erubis.rb +15 -38
- data/lib/ramaze/template/ezamar.rb +100 -0
- data/lib/ramaze/template/ezamar/element.rb +166 -0
- data/lib/ramaze/template/ezamar/engine.rb +124 -0
- data/lib/ramaze/template/ezamar/morpher.rb +155 -0
- data/lib/ramaze/template/haml.rb +16 -43
- data/lib/ramaze/template/liquid.rb +11 -51
- data/lib/ramaze/template/markaby.rb +44 -42
- data/lib/ramaze/tool/mime.rb +18 -0
- data/lib/ramaze/tool/mime_types.yaml +615 -0
- data/lib/ramaze/trinity/request.rb +20 -196
- data/lib/ramaze/trinity/response.rb +4 -33
- data/lib/ramaze/trinity/session.rb +150 -72
- data/lib/ramaze/version.rb +1 -1
- data/spec/adapter_spec.rb +20 -0
- data/spec/public/favicon.ico +0 -0
- data/spec/public/ramaze.png +0 -0
- data/spec/public/test_download.css +141 -0
- data/spec/{tc_request.rb → request_tc_helper.rb} +45 -21
- data/spec/spec_all.rb +77 -34
- data/spec/spec_helper.rb +8 -157
- data/spec/spec_helper_context.rb +72 -0
- data/spec/spec_helper_requester.rb +52 -0
- data/spec/spec_helper_simple_http.rb +433 -0
- data/spec/tc_adapter_mongrel.rb +3 -15
- data/spec/tc_adapter_webrick.rb +4 -14
- data/spec/tc_cache.rb +3 -5
- data/spec/tc_controller.rb +22 -12
- data/spec/tc_dependencies.rb +13 -0
- data/spec/tc_element.rb +8 -7
- data/spec/tc_error.rb +13 -7
- data/spec/tc_global.rb +16 -18
- data/spec/tc_helper_aspect.rb +2 -4
- data/spec/tc_helper_auth.rb +15 -14
- data/spec/tc_helper_cache.rb +5 -7
- data/spec/tc_helper_feed.rb +0 -2
- data/spec/tc_helper_flash.rb +103 -0
- data/spec/tc_helper_form.rb +4 -6
- data/spec/tc_helper_link.rb +1 -3
- data/spec/tc_helper_redirect.rb +23 -8
- data/spec/tc_helper_stack.rb +31 -15
- data/spec/tc_morpher.rb +1 -3
- data/spec/tc_params.rb +48 -7
- data/spec/tc_request_mongrel.rb +9 -0
- data/spec/tc_request_webrick.rb +5 -0
- data/spec/tc_session.rb +41 -25
- data/spec/tc_store.rb +55 -6
- data/spec/tc_store_yaml.rb +71 -0
- data/spec/tc_template_amrita2.rb +3 -3
- data/spec/tc_template_erubis.rb +2 -3
- data/spec/{tc_template_ramaze.rb → tc_template_ezamar.rb} +15 -5
- data/spec/tc_template_haml.rb +4 -3
- data/spec/tc_template_liquid.rb +3 -4
- data/spec/tc_template_markaby.rb +4 -6
- data/spec/tc_tidy.rb +1 -3
- data/spec/template/amrita2/{data.html → data.amrita} +0 -0
- data/spec/template/amrita2/{index.html → index.amrita} +0 -0
- data/spec/template/amrita2/{sum.html → sum.amrita} +0 -0
- data/spec/template/ezamar/another/long/action.zmr +1 -0
- data/spec/template/ezamar/combined.zmr +1 -0
- data/spec/template/{ramaze/file_only.rmze → ezamar/file_only.zmr} +0 -0
- data/spec/template/{ramaze/index.rmze → ezamar/index.zmr} +0 -0
- data/spec/template/{ramaze/nested.rmze → ezamar/nested.zmr} +0 -0
- data/spec/template/ezamar/some__long__action.zmr +1 -0
- data/spec/template/{ramaze/sum.rmze → ezamar/sum.zmr} +0 -0
- metadata +181 -123
- data/doc/allison/LICENSE +0 -184
- data/doc/allison/README +0 -37
- data/doc/allison/allison.css +0 -300
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +0 -307
- data/doc/allison/allison.rb +0 -287
- data/doc/allison/cache/BODY +0 -588
- data/doc/allison/cache/CLASS_INDEX +0 -4
- data/doc/allison/cache/CLASS_PAGE +0 -1
- data/doc/allison/cache/FILE_INDEX +0 -4
- data/doc/allison/cache/FILE_PAGE +0 -1
- data/doc/allison/cache/FONTS +0 -1
- data/doc/allison/cache/FR_INDEX_BODY +0 -1
- data/doc/allison/cache/IMGPATH +0 -1
- data/doc/allison/cache/INDEX +0 -1
- data/doc/allison/cache/JAVASCRIPT +0 -307
- data/doc/allison/cache/METHOD_INDEX +0 -4
- data/doc/allison/cache/METHOD_LIST +0 -1
- data/doc/allison/cache/SRC_PAGE +0 -1
- data/doc/allison/cache/STYLE +0 -322
- data/doc/allison/cache/URL +0 -1
- data/doc/changes.txt +0 -2021
- data/doc/changes.xml +0 -2024
- data/lib/ramaze/snippets/kernel/silently.rb +0 -13
- data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +0 -11
- data/lib/ramaze/template/haml/actionview_stub.rb +0 -20
- data/lib/ramaze/template/ramaze.rb +0 -177
- data/lib/ramaze/template/ramaze/element.rb +0 -166
- data/lib/ramaze/template/ramaze/morpher.rb +0 -156
- data/spec/tc_test.rb +0 -17
data/lib/ramaze/dispatcher.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
require 'timeout'
|
|
5
|
+
require 'ramaze/tool/mime'
|
|
5
6
|
|
|
6
7
|
module Ramaze
|
|
7
8
|
|
|
@@ -15,21 +16,30 @@ module Ramaze
|
|
|
15
16
|
# find any examples of how this is done exactly yet.
|
|
16
17
|
|
|
17
18
|
module Dispatcher
|
|
19
|
+
trait :filters => [
|
|
20
|
+
lambda{|path| handle_file path },
|
|
21
|
+
lambda{|path| handle_action path },
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
trait :handle_error => {
|
|
25
|
+
Exception => '/error',
|
|
26
|
+
Ramaze::Error::NoAction => '/error',
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
class << self
|
|
19
30
|
include Trinity
|
|
20
31
|
|
|
21
32
|
# handle a request/response pair as given by the adapter.
|
|
22
33
|
# has to answer with a response.
|
|
23
34
|
#
|
|
24
|
-
# It is built so it will
|
|
35
|
+
# It is built so it will rescue _all_ errors and exceptions
|
|
25
36
|
# thrown during processing of the request and #handle_error if
|
|
26
37
|
# a problem occurs.
|
|
27
38
|
|
|
28
|
-
def handle
|
|
29
|
-
|
|
30
|
-
respond
|
|
39
|
+
def handle rack_request, rack_response
|
|
40
|
+
setup_environment rack_request, rack_response
|
|
41
|
+
respond
|
|
31
42
|
rescue Object => exception
|
|
32
|
-
error(exception)
|
|
33
43
|
handle_error(exception)
|
|
34
44
|
end
|
|
35
45
|
|
|
@@ -53,249 +63,111 @@ module Ramaze
|
|
|
53
63
|
# anyway, the solution might be simple?
|
|
54
64
|
|
|
55
65
|
def handle_error exception
|
|
56
|
-
|
|
66
|
+
Informer.error exception
|
|
67
|
+
Informer.meth_debug :handle_error, exception
|
|
57
68
|
Thread.current[:exception] = exception
|
|
58
69
|
|
|
70
|
+
handle_error = trait[:handle_error]
|
|
71
|
+
|
|
59
72
|
case exception
|
|
60
|
-
when
|
|
61
|
-
|
|
73
|
+
when *handle_error.keys
|
|
74
|
+
error_path = handle_error[exception.class]
|
|
75
|
+
error_path ||= handle_error.find{|k,v| k === exception}.last
|
|
76
|
+
|
|
77
|
+
request.path_info = error_path
|
|
78
|
+
respond
|
|
62
79
|
else
|
|
63
80
|
if Global.error_page
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
unless ((req.request_uri.path = '/error') rescue false)
|
|
67
|
-
req.request.params['REQUEST_PATH'] = '/error'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
fill_out
|
|
81
|
+
request.path_info = '/error'
|
|
82
|
+
respond
|
|
71
83
|
else
|
|
72
84
|
build_response(exception.message, STATUS_CODE[:internal_server_error])
|
|
73
85
|
end
|
|
74
86
|
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# setup the #setup_environment (Trinity) and start #fill_out
|
|
78
|
-
|
|
79
|
-
def respond orig_response, orig_request
|
|
80
|
-
setup_environment orig_response, orig_request
|
|
81
|
-
fill_out
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
def build_response out = '', code = STATUS_CODE[:internal_server_error], head = {}
|
|
87
|
-
default_head = {
|
|
88
|
-
'Content-Type' => 'text/plain',
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if Global.cookies
|
|
92
|
-
default_head['Set-Cookie'] = session.export
|
|
93
|
-
else
|
|
94
|
-
head.delete('Set-Cookie')
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
head = default_head.merge(head)
|
|
98
87
|
|
|
99
|
-
|
|
88
|
+
respond
|
|
89
|
+
rescue Object => ex
|
|
90
|
+
Informer.error ex
|
|
91
|
+
build_response(ex.message, STATUS_CODE[:internal_server_error])
|
|
100
92
|
end
|
|
101
93
|
|
|
102
|
-
|
|
103
94
|
# Obtain the path requested from the request and search for a static
|
|
104
95
|
# file matching the request, #respond_file is called if it finds one,
|
|
105
96
|
# otherwise the path is given on to #respond_action.
|
|
106
97
|
# Answers with a response
|
|
107
98
|
|
|
108
|
-
def
|
|
109
|
-
path = request.
|
|
110
|
-
info "Request from #{request.remote_addr}: #{path}"
|
|
111
|
-
|
|
112
|
-
the_paths = $:.map{|way| (way/'public'/path) }
|
|
113
|
-
if file = the_paths.find{|way| File.exist?(way) and File.file?(way)}
|
|
114
|
-
respond_file file
|
|
115
|
-
else
|
|
116
|
-
respond_action path
|
|
117
|
-
end
|
|
118
|
-
response
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# takes a file and sets the response.out to the contents of the file
|
|
122
|
-
# If you are running mongrel as your adapter it will take advantage of
|
|
123
|
-
# mongrels #send_file
|
|
124
|
-
|
|
125
|
-
def respond_file file
|
|
126
|
-
debug "Responding with static file: #{file}"
|
|
99
|
+
def respond
|
|
100
|
+
path = request.path_info.squeeze('/')
|
|
101
|
+
Informer.info "Request from #{request.remote_addr}: #{path}"
|
|
127
102
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# Takes the path, figures out the controller by asking #resolve_controller
|
|
137
|
-
# for the controller, action and params for the path.
|
|
138
|
-
#
|
|
139
|
-
# Sets the cookies in the response.head if Global.cookies is set
|
|
140
|
-
#
|
|
141
|
-
# finally it runs #handle_controller
|
|
142
|
-
|
|
143
|
-
def respond_action path
|
|
144
|
-
debug "Responding with action: #{path}"
|
|
103
|
+
catch(:respond) do
|
|
104
|
+
redirection = catch(:redirect) do
|
|
105
|
+
filtered = [filter(path)].flatten.first
|
|
106
|
+
throw(:respond, build_response(filtered, response.status))
|
|
107
|
+
end
|
|
145
108
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
109
|
+
body, status, head = redirection.values_at(:body, :status, :head)
|
|
110
|
+
Informer.info("Redirect to `#{head['Location']}'")
|
|
111
|
+
throw(:respond, build_response(body, status, head))
|
|
149
112
|
end
|
|
150
113
|
end
|
|
151
114
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
# Ramaze::Error::NoAction # if no action but a controller is found
|
|
157
|
-
#
|
|
158
|
-
# It actually uses #resolve_action on almost every combination of
|
|
159
|
-
# so-called paractions (yet unsplit but possible combination of action
|
|
160
|
-
# and parameters for the action)
|
|
161
|
-
#
|
|
162
|
-
# If your templating is action-less, which means it does not depend on
|
|
163
|
-
# methods on the controller, but rather on templates or just dynamically
|
|
164
|
-
# calculated stuff you can set trait[:actionless] for your templating.
|
|
165
|
-
#
|
|
166
|
-
# Please see the documentation for Ramaze::Template::Amrita2 for an more
|
|
167
|
-
# specific example of how it is used in practice.
|
|
168
|
-
#
|
|
169
|
-
# Further it uses the Global.mapping to look up the controller to be used.
|
|
170
|
-
#
|
|
171
|
-
# Also, the action '/' will be expanded to 'index'
|
|
172
|
-
#
|
|
173
|
-
# Parameters are CGI.unescaped
|
|
174
|
-
|
|
175
|
-
def resolve_controller path
|
|
176
|
-
meth_debug :resolve_controller, path
|
|
177
|
-
track = path.split('/')
|
|
178
|
-
controller = false
|
|
179
|
-
action = false
|
|
180
|
-
tracks = []
|
|
181
|
-
|
|
182
|
-
track.unshift '/'
|
|
115
|
+
def filter path
|
|
116
|
+
last_error = $!
|
|
117
|
+
ancestral_trait[:filters].each do |filter|
|
|
118
|
+
filtered = run_filter(filter, path)
|
|
183
119
|
|
|
184
|
-
|
|
185
|
-
|
|
120
|
+
next unless filtered
|
|
121
|
+
return filtered unless filtered.is_a?(Exception)
|
|
122
|
+
last_error = filtered
|
|
186
123
|
end
|
|
187
124
|
|
|
188
|
-
|
|
189
|
-
current = Regexp.escape(tracks.pop.to_s)
|
|
190
|
-
paraction = path.gsub(/^#{current}/, '').split('/').map{|e| CGI.unescape(e)}
|
|
191
|
-
paraction.delete('')
|
|
192
|
-
if controller = Ramaze::Global.mapping[current]
|
|
193
|
-
if controller.ancestral_trait[:actionless] or paraction == ['error']
|
|
194
|
-
|
|
195
|
-
action = paraction.shift
|
|
196
|
-
params = paraction
|
|
197
|
-
action = 'index' if action == nil
|
|
198
|
-
else
|
|
199
|
-
action, params = resolve_action controller, paraction
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
raise Ramaze::Error::NoController, "No Controller found for #{path}" unless controller
|
|
205
|
-
raise Ramaze::Error::NoAction, "No Action found for #{path}" unless action
|
|
206
|
-
|
|
207
|
-
return controller, action, params
|
|
125
|
+
throw(:respond, handle_error(last_error))
|
|
208
126
|
end
|
|
209
127
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
# TODO:
|
|
216
|
-
# - find a solution for def x(a = :a) which has arity -1
|
|
217
|
-
# identical to def x(*a) for some odd reason
|
|
218
|
-
|
|
219
|
-
def resolve_action controller, paraction
|
|
220
|
-
meth_debug :resolve_action, controller, paraction
|
|
221
|
-
|
|
222
|
-
meths =
|
|
223
|
-
(controller.ancestors - [Kernel, Object]).inject([]) do |sum, klass|
|
|
224
|
-
sum | (klass.is_a?(Module) ? klass.instance_methods(false) : sum)
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
track = paraction.dup
|
|
228
|
-
tracks = []
|
|
229
|
-
action = false
|
|
128
|
+
def run_filter filter, path
|
|
129
|
+
filter[path]
|
|
130
|
+
rescue Object => ex
|
|
131
|
+
ex
|
|
132
|
+
end
|
|
230
133
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
tracks << atom.join('__')
|
|
235
|
-
end
|
|
134
|
+
def handle_action path
|
|
135
|
+
handler = Controller.handle(path)
|
|
136
|
+
end
|
|
236
137
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return current, params
|
|
249
|
-
elsif arity == -1
|
|
250
|
-
return current, params
|
|
251
|
-
end
|
|
252
|
-
end
|
|
138
|
+
def handle_file path
|
|
139
|
+
custom_publics = Global.controllers.map{|c| c.trait[:public]}.compact
|
|
140
|
+
the_paths = $:.map{|way| (way/'public'/path) }
|
|
141
|
+
the_paths << (BASEDIR/'proto'/'public'/path)
|
|
142
|
+
the_paths += custom_publics.map{|c| c/path }
|
|
143
|
+
file = the_paths.find{|way| File.file?(way)}
|
|
144
|
+
|
|
145
|
+
if file
|
|
146
|
+
response['Content-Type'] = Tool::MIME.type_for(file)
|
|
147
|
+
Informer.debug("Serving static: #{file}")
|
|
148
|
+
File.open(file)
|
|
253
149
|
end
|
|
254
150
|
end
|
|
255
151
|
|
|
256
|
-
#
|
|
257
|
-
#
|
|
258
|
-
#
|
|
152
|
+
# takes the content, code and head for a new response, will set the cookies
|
|
153
|
+
# if Global.cookies is true (which it is by default) and set the default
|
|
154
|
+
# Content-Type to 'text/plain'
|
|
259
155
|
|
|
260
|
-
def
|
|
261
|
-
if Global.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
handle_uncached_controller(controller, action, *params)
|
|
156
|
+
def build_response body = '', status = STATUS_CODE[:internal_server_error], head = {}
|
|
157
|
+
set_cookie if Global.cookies
|
|
158
|
+
head.each do |key, value|
|
|
159
|
+
response[key] = value
|
|
265
160
|
end
|
|
266
|
-
end
|
|
267
161
|
|
|
268
|
-
|
|
269
|
-
# the controller has to do is to respond with a string.
|
|
162
|
+
response.body, response.status = body, status
|
|
270
163
|
|
|
271
|
-
|
|
272
|
-
controller.handle_request(action, *params)
|
|
164
|
+
return response
|
|
273
165
|
end
|
|
274
166
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
# or directly
|
|
280
|
-
# Global.cache_actions[self] << 'index'
|
|
281
|
-
#
|
|
282
|
-
# Caching is done for [action, params] pairs per controller.
|
|
283
|
-
|
|
284
|
-
def handle_cached_controller controller, action, *params
|
|
285
|
-
Global.cached_actions ||= Global.cache.new
|
|
286
|
-
|
|
287
|
-
key = [action, params].inspect
|
|
288
|
-
|
|
289
|
-
Global.cached_actions[controller] ||= {key => nil}
|
|
290
|
-
|
|
291
|
-
if out = Global.cached_actions[controller][key]
|
|
292
|
-
debug "Using Cached version for #{key.inspect}"
|
|
293
|
-
return out
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
debug "Compiling Action: #{action} #{params.join(', ')}"
|
|
297
|
-
Global.cached_actions[controller][key] =
|
|
298
|
-
handle_uncached_controller(controller, action, *params)
|
|
167
|
+
def set_cookie
|
|
168
|
+
session.finalize
|
|
169
|
+
hash = {:value => session.session_id, :path => '/'}
|
|
170
|
+
response.set_cookie(Session::SESSION_KEY, hash)
|
|
299
171
|
end
|
|
300
172
|
|
|
301
173
|
# Setup the Trinity (Request, Response, Session) and store them as
|
|
@@ -304,11 +176,11 @@ module Ramaze
|
|
|
304
176
|
# Thread.current[:response] == Response.current
|
|
305
177
|
# Thread.current[:session] == Session.current
|
|
306
178
|
|
|
307
|
-
def setup_environment
|
|
179
|
+
def setup_environment rack_request, rack_response
|
|
308
180
|
this = Thread.current
|
|
309
|
-
this[:request] = Request.new(
|
|
181
|
+
this[:request] = Request.new(rack_request)
|
|
310
182
|
this[:session] = Session.new(request)
|
|
311
|
-
this[:response] =
|
|
183
|
+
this[:response] = rack_response
|
|
312
184
|
end
|
|
313
185
|
end
|
|
314
186
|
end
|
data/lib/ramaze/error.rb
CHANGED
|
@@ -2,10 +2,20 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
+
|
|
6
|
+
# The general Namespace for Ramazes Errorclasses
|
|
7
|
+
|
|
5
8
|
module Error
|
|
9
|
+
# No action found on Controller
|
|
6
10
|
class NoAction < StandardError; end
|
|
11
|
+
|
|
12
|
+
# No Controller found for request
|
|
7
13
|
class NoController < StandardError; end
|
|
14
|
+
|
|
15
|
+
# Wrong parameter count for action
|
|
8
16
|
class WrongParameterCount < StandardError; end
|
|
17
|
+
|
|
18
|
+
# Error while transformation in template
|
|
9
19
|
class Template < StandardError; end
|
|
10
20
|
end
|
|
11
21
|
end
|
data/lib/ramaze/global.rb
CHANGED
data/lib/ramaze/helper/aspect.rb
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
+
|
|
5
6
|
# A helper that provides the means to wrap actions of the controller with
|
|
6
7
|
# other methods.
|
|
8
|
+
#
|
|
7
9
|
# For examples please look at the test/tc_aspect.rb
|
|
8
|
-
#
|
|
10
|
+
#
|
|
11
|
+
# This is not a default helper due to the possible performance-issues.
|
|
9
12
|
# However, it should be only an overhead of about 6-8 calls, so if you
|
|
10
13
|
# want this feature it shouldn't have too large impact ;)
|
|
11
14
|
|
|
@@ -19,12 +22,28 @@ module Ramaze
|
|
|
19
22
|
unless defined?(Traits[klass][:aspects]) and Traits[klass][:aspects]
|
|
20
23
|
Traits[klass] = {:aspects => {:pre => {}, :post => {}, :wrap => {}}}
|
|
21
24
|
unless defined?(klass.old_render)
|
|
22
|
-
klass.
|
|
23
|
-
|
|
25
|
+
klass.class_eval do
|
|
26
|
+
class << self
|
|
27
|
+
include AspectHelperMixin
|
|
28
|
+
alias_method :old_render, :render
|
|
29
|
+
alias_method :render, :new_render
|
|
30
|
+
|
|
31
|
+
public :render
|
|
32
|
+
end
|
|
33
|
+
end
|
|
24
34
|
end
|
|
25
35
|
end
|
|
26
36
|
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# This is the actual Module to be included into the Controller you call
|
|
40
|
+
# helper :aspect
|
|
41
|
+
# from.
|
|
42
|
+
#
|
|
43
|
+
# The reason for that is to avoid recursion of inclusion in AspectHelper
|
|
44
|
+
# which does the aliasing and predefinition of the traits for the aspects.
|
|
27
45
|
|
|
46
|
+
module AspectHelperMixin
|
|
28
47
|
private
|
|
29
48
|
|
|
30
49
|
# define pre-aspect which calls render(:your_pre_aspect)
|
|
@@ -47,7 +66,7 @@ module Ramaze
|
|
|
47
66
|
# With great power comes great responsibility
|
|
48
67
|
#
|
|
49
68
|
# Example:
|
|
50
|
-
# class FooController <
|
|
69
|
+
# class FooController < Controller
|
|
51
70
|
#
|
|
52
71
|
# def index
|
|
53
72
|
# 'foo'
|
|
@@ -93,7 +112,7 @@ module Ramaze
|
|
|
93
112
|
# With great power comes great responsibility
|
|
94
113
|
#
|
|
95
114
|
# Example:
|
|
96
|
-
# class FooController <
|
|
115
|
+
# class FooController < Controller
|
|
97
116
|
#
|
|
98
117
|
# def index
|
|
99
118
|
# 'foo'
|
|
@@ -175,12 +194,16 @@ module Ramaze
|
|
|
175
194
|
|
|
176
195
|
if pre
|
|
177
196
|
arity = arity_for[pre].abs
|
|
178
|
-
pre_content = old_render(pre, *params[0,arity])
|
|
197
|
+
pre_content = old_render(pre, *params[0,arity])
|
|
179
198
|
end
|
|
180
199
|
|
|
181
200
|
unless (pre_content.delete(:skip_next_aspects) rescue false)
|
|
182
201
|
content = old_render(action, *params)
|
|
183
|
-
|
|
202
|
+
|
|
203
|
+
if post
|
|
204
|
+
arity = arity_for[post].abs
|
|
205
|
+
post_content = old_render(post, *params[0,arity])
|
|
206
|
+
end
|
|
184
207
|
end
|
|
185
208
|
|
|
186
209
|
[pre_content, content, post_content].join
|