ramaze 0.0.9 → 0.1.0
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 +14 -259
- data/bin/ramaze +52 -25
- data/doc/AUTHORS +6 -0
- data/doc/CHANGELOG +1363 -42
- data/doc/INSTALL +1 -1
- data/doc/README +48 -35
- data/doc/README.html +637 -0
- data/doc/TODO +7 -16
- data/doc/allison/allison.css +6 -7
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/cache/STYLE +1 -2
- data/doc/changes.txt +3375 -0
- data/doc/changes.xml +3378 -0
- data/doc/meta/announcement.txt +47 -0
- data/doc/meta/configuration.txt +179 -0
- data/doc/meta/internals.txt +111 -0
- data/doc/readme_chunks/features.txt +8 -16
- data/doc/readme_chunks/installing.txt +7 -1
- data/doc/tutorial/todolist.txt +2 -3
- data/examples/blog/main.rb +9 -8
- data/examples/blog/public/styles/blog.css +132 -0
- data/examples/blog/src/controller.rb +14 -41
- data/examples/blog/src/model.rb +12 -13
- data/examples/blog/src/view.rb +16 -0
- data/examples/blog/template/edit.xhtml +19 -8
- data/examples/blog/template/index.xhtml +14 -22
- data/examples/blog/template/new.xhtml +18 -5
- data/examples/caching.rb +5 -8
- data/examples/element.rb +3 -3
- data/examples/hello.rb +3 -5
- data/examples/simple.rb +4 -7
- data/examples/templates/template/external.haml +8 -7
- data/examples/templates/template/external.mab +11 -8
- data/examples/templates/template_amrita2.rb +4 -4
- data/examples/templates/template_erubis.rb +3 -3
- data/examples/templates/template_ezamar.rb +1 -2
- data/examples/templates/template_haml.rb +24 -23
- data/examples/templates/template_liquid.rb +3 -1
- data/examples/templates/template_markaby.rb +15 -9
- data/examples/todolist/src/element/page.rb +1 -1
- data/lib/proto/conf/benchmark.yaml +6 -20
- data/lib/proto/conf/debug.yaml +6 -19
- data/lib/proto/conf/live.yaml +7 -19
- data/lib/proto/conf/silent.yaml +6 -16
- data/lib/proto/conf/stage.yaml +6 -18
- data/lib/proto/public/error.zmr +2 -2
- data/lib/ramaze.rb +34 -72
- data/lib/ramaze/adapter.rb +21 -18
- data/lib/ramaze/adapter/mongrel.rb +0 -3
- data/lib/ramaze/adapter/webrick.rb +6 -6
- data/lib/ramaze/cache/memcached.rb +3 -0
- data/lib/ramaze/controller.rb +227 -183
- data/lib/ramaze/dispatcher.rb +34 -129
- data/lib/ramaze/dispatcher/action.rb +28 -0
- data/lib/ramaze/dispatcher/error.rb +43 -0
- data/lib/ramaze/dispatcher/file.rb +34 -0
- data/lib/ramaze/global.rb +89 -48
- data/lib/ramaze/helper/aspect.rb +8 -6
- data/lib/ramaze/helper/auth.rb +3 -3
- data/lib/ramaze/helper/cache.rb +2 -2
- data/lib/ramaze/helper/file.rb +14 -0
- data/lib/ramaze/helper/inform.rb +36 -0
- data/lib/ramaze/helper/link.rb +7 -3
- data/lib/ramaze/helper/markaby.rb +30 -0
- data/lib/ramaze/helper/redirect.rb +2 -0
- data/lib/ramaze/inform.rb +8 -182
- data/lib/ramaze/inform/analogger.rb +19 -0
- data/lib/ramaze/inform/growl.rb +28 -0
- data/lib/ramaze/inform/hub.rb +26 -0
- data/lib/ramaze/inform/informer.rb +92 -0
- data/lib/ramaze/inform/informing.rb +44 -0
- data/lib/ramaze/inform/syslog.rb +27 -0
- data/lib/ramaze/inform/xosd.rb +42 -0
- data/lib/ramaze/snippets.rb +6 -2
- data/lib/ramaze/snippets/object/traits.rb +13 -1
- data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
- data/lib/ramaze/snippets/string/color.rb +27 -0
- data/lib/ramaze/snippets/string/each.rb +6 -0
- data/lib/ramaze/snippets/struct/fill.rb +15 -0
- data/lib/ramaze/template/ezamar.rb +13 -22
- data/lib/ramaze/template/ezamar/element.rb +12 -12
- data/lib/ramaze/template/liquid.rb +19 -18
- data/lib/ramaze/template/markaby.rb +37 -58
- data/lib/ramaze/tool/localize.rb +128 -0
- data/lib/ramaze/tool/tidy.rb +51 -21
- data/lib/ramaze/trinity.rb +3 -3
- data/lib/ramaze/trinity/request.rb +41 -23
- data/lib/ramaze/trinity/response.rb +10 -5
- data/lib/ramaze/trinity/session.rb +17 -3
- data/lib/ramaze/version.rb +2 -2
- data/rake_tasks/conf.rake +56 -0
- data/rake_tasks/gem.rake +44 -0
- data/rake_tasks/maintaince.rake +187 -0
- data/spec/all.rb +32 -0
- data/spec/examples/caching.rb +19 -0
- data/spec/examples/element.rb +15 -0
- data/spec/examples/hello.rb +11 -0
- data/spec/examples/simple.rb +51 -0
- data/spec/examples/templates/template_amrita2.rb +14 -0
- data/spec/examples/templates/template_erubis.rb +21 -0
- data/spec/examples/templates/template_ezamar.rb +22 -0
- data/spec/examples/templates/template_haml.rb +23 -0
- data/spec/examples/templates/template_liquid.rb +24 -0
- data/spec/examples/templates/template_markaby.rb +21 -0
- data/spec/helper.rb +81 -0
- data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
- data/spec/helper/layout.rb +55 -0
- data/spec/helper/mock_http.rb +66 -0
- data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
- data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
- data/spec/helper/wrap.rb +193 -0
- data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
- data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
- data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
- data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
- data/spec/ramaze/conf/locale_de.yaml +6 -0
- data/spec/ramaze/conf/locale_en.yaml +6 -0
- data/spec/ramaze/controller.rb +184 -0
- data/spec/ramaze/controller/template/greet.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +54 -0
- data/spec/ramaze/dependencies.rb +16 -0
- data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
- data/spec/ramaze/error.rb +64 -0
- data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
- data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
- data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
- data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
- data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
- data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
- data/spec/ramaze/helper/file.rb +17 -0
- data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
- data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
- data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
- data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
- data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
- data/spec/ramaze/inform/informer.rb +40 -0
- data/spec/ramaze/inform/syslog.rb +10 -0
- data/spec/ramaze/localize.rb +40 -0
- data/spec/ramaze/morpher.rb +82 -0
- data/spec/ramaze/params.rb +124 -0
- data/spec/{public → ramaze/public}/error404.xhtml +0 -0
- data/spec/{public → ramaze/public}/favicon.ico +0 -0
- data/spec/{public → ramaze/public}/ramaze.png +0 -0
- data/spec/{public → ramaze/public}/test_download.css +0 -0
- data/spec/ramaze/request.rb +129 -0
- data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
- data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
- data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
- data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
- data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
- data/spec/ramaze/template.rb +86 -0
- data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
- data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
- data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
- data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
- data/spec/ramaze/template/ezamar.rb +62 -0
- data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
- data/spec/ramaze/template/ezamar/nested.zmr +1 -0
- data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
- data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
- data/spec/{template → ramaze/template}/haml/index.haml +0 -0
- data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
- data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
- data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
- data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
- data/spec/ramaze/template/markaby.rb +59 -0
- data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
- data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
- data/spec/ramaze/template/ramaze/external.test +1 -0
- data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
- metadata +145 -81
- data/examples/blog/public/screen.css +0 -106
- data/examples/blog/src/element.rb +0 -58
- data/examples/blog/template/view.xhtml +0 -15
- data/examples/blog/test/tc_entry.rb +0 -18
- data/lib/proto/public/404.jpg +0 -0
- data/spec/request_tc_helper.rb +0 -135
- data/spec/spec_all.rb +0 -118
- data/spec/spec_helper.rb +0 -66
- data/spec/tc_controller.rb +0 -49
- data/spec/tc_dependencies.rb +0 -13
- data/spec/tc_error.rb +0 -43
- data/spec/tc_morpher.rb +0 -88
- data/spec/tc_params.rb +0 -125
- data/spec/tc_template_ezamar.rb +0 -64
- data/spec/tc_template_markaby.rb +0 -72
- data/spec/template/ezamar/nested.zmr +0 -1
data/lib/ramaze/dispatcher.rb
CHANGED
|
@@ -2,164 +2,69 @@
|
|
|
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'
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
require 'ramaze/adapter'
|
|
7
|
+
require 'ramaze/tool/mime'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# framework and your application.
|
|
13
|
-
#
|
|
14
|
-
# It is built in a way that lets you easily replace it with something you
|
|
15
|
-
# like better, since i'm very fond of the current implementation you can't
|
|
16
|
-
# find any examples of how this is done exactly yet.
|
|
9
|
+
require 'ramaze/dispatcher/action'
|
|
10
|
+
require 'ramaze/dispatcher/error'
|
|
11
|
+
require 'ramaze/dispatcher/file'
|
|
17
12
|
|
|
13
|
+
module Ramaze
|
|
18
14
|
module Dispatcher
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
|
|
16
|
+
trait :dispatch => [
|
|
17
|
+
Dispatcher::File,
|
|
18
|
+
Dispatcher::Action,
|
|
19
|
+
]
|
|
23
20
|
|
|
24
21
|
trait :handle_error => {
|
|
25
|
-
Exception
|
|
26
|
-
Ramaze::Error::NoAction
|
|
22
|
+
Exception => [500, '/error'],
|
|
23
|
+
Ramaze::Error::NoAction => [404, '/error'],
|
|
24
|
+
Ramaze::Error::NoController => [404, '/error'],
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
class << self
|
|
30
28
|
include Trinity
|
|
31
29
|
|
|
32
|
-
# handle a request/response pair as given by the adapter.
|
|
33
|
-
# has to answer with a response.
|
|
34
|
-
#
|
|
35
|
-
# It is built so it will rescue _all_ errors and exceptions
|
|
36
|
-
# thrown during processing of the request and #handle_error if
|
|
37
|
-
# a problem occurs.
|
|
38
|
-
|
|
39
30
|
def handle rack_request, rack_response
|
|
40
|
-
setup_environment
|
|
41
|
-
|
|
42
|
-
rescue Object =>
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# The handle_error method takes an exception and decides based on that
|
|
47
|
-
# how it is going to respond in case of an error.
|
|
48
|
-
#
|
|
49
|
-
# In future this will become more and more configurable, right now
|
|
50
|
-
# you can provide your own error-method and error.xhtml inside either
|
|
51
|
-
# your trait[:template_root] or trait[:public].
|
|
52
|
-
#
|
|
53
|
-
# As more and more error-classes are being added to Ramaze you will get
|
|
54
|
-
# the ability to define your own response-pages and/or behaviour like
|
|
55
|
-
# automatic redirects.
|
|
56
|
-
#
|
|
57
|
-
# This feature is only available if your Global.error is true, which is
|
|
58
|
-
# the default.
|
|
59
|
-
#
|
|
60
|
-
#--
|
|
61
|
-
#
|
|
62
|
-
# Yes, again, webrick _has_ to be really obscure, I searched for half an hour
|
|
63
|
-
# and still have not the faintest idea how request_path is related to
|
|
64
|
-
# request_uri...
|
|
65
|
-
# anyway, the solution might be simple?
|
|
66
|
-
|
|
67
|
-
def handle_error exception
|
|
68
|
-
Informer.error exception
|
|
69
|
-
Informer.meth_debug :handle_error, exception
|
|
70
|
-
Thread.current[:exception] = exception
|
|
71
|
-
|
|
72
|
-
handle_error = trait[:handle_error]
|
|
73
|
-
|
|
74
|
-
case exception
|
|
75
|
-
when *handle_error.keys
|
|
76
|
-
error_path = handle_error[exception.class]
|
|
77
|
-
error_path ||= handle_error.find{|k,v| k === exception}.last
|
|
78
|
-
|
|
79
|
-
if exception.message =~ /`#{error_path.split('/').last}'/
|
|
80
|
-
build_response(exception.message, STATUS_CODE[:internal_server_error])
|
|
81
|
-
else
|
|
82
|
-
request.path_info = error_path
|
|
83
|
-
respond
|
|
84
|
-
end
|
|
85
|
-
else
|
|
86
|
-
if Global.error_page
|
|
87
|
-
request.path_info = '/error'
|
|
88
|
-
respond
|
|
89
|
-
else
|
|
90
|
-
build_response(exception.message, STATUS_CODE[:internal_server_error])
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
response
|
|
95
|
-
rescue Object => ex
|
|
96
|
-
Informer.error ex
|
|
97
|
-
build_response(ex.message, STATUS_CODE[:internal_server_error])
|
|
31
|
+
setup_environment(rack_request, rack_response)
|
|
32
|
+
dispatch
|
|
33
|
+
rescue Object => error
|
|
34
|
+
Dispatcher::Error.process(error)
|
|
98
35
|
end
|
|
99
36
|
|
|
100
|
-
|
|
101
|
-
# file matching the request, #respond_file is called if it finds one,
|
|
102
|
-
# otherwise the path is given on to #respond_action.
|
|
103
|
-
# Answers with a response
|
|
104
|
-
|
|
105
|
-
def respond
|
|
37
|
+
def dispatch
|
|
106
38
|
path = request.path_info.squeeze('/')
|
|
107
|
-
|
|
39
|
+
Inform.info("Request from #{request.remote_addr}: #{path}")
|
|
108
40
|
|
|
109
41
|
catch(:respond) do
|
|
110
42
|
redirection = catch(:redirect) do
|
|
111
|
-
|
|
112
|
-
throw(:respond,
|
|
43
|
+
found = filter(path)
|
|
44
|
+
throw(:respond, found)
|
|
113
45
|
end
|
|
114
46
|
|
|
115
47
|
body, status, head = redirection.values_at(:body, :status, :head)
|
|
116
|
-
|
|
48
|
+
Inform.info("Redirect to `#{head['Location']}'")
|
|
117
49
|
throw(:respond, build_response(body, status, head))
|
|
118
50
|
end
|
|
119
51
|
end
|
|
120
52
|
|
|
121
|
-
def
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
next unless filtered
|
|
127
|
-
return filtered unless filtered.is_a?(Exception)
|
|
128
|
-
last_error = filtered
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
throw(:respond, handle_error(last_error))
|
|
53
|
+
def dispatch_to path
|
|
54
|
+
raise "Redirect to #{path} from #{path}" if request.path_info == path
|
|
55
|
+
request.path_info = path
|
|
56
|
+
dispatch
|
|
132
57
|
end
|
|
133
58
|
|
|
134
|
-
def
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def handle_action path
|
|
141
|
-
handler = Controller.handle(path)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def handle_file path
|
|
145
|
-
custom_publics = Global.controllers.map{|c| c.trait[:public]}.compact
|
|
146
|
-
the_paths = $:.map{|way| (way/'public'/path) }
|
|
147
|
-
the_paths << (BASEDIR/'proto'/'public'/path)
|
|
148
|
-
the_paths += custom_publics.map{|c| c/path }
|
|
149
|
-
file = the_paths.find{|way| File.file?(way)}
|
|
150
|
-
|
|
151
|
-
if file
|
|
152
|
-
response['Content-Type'] = Tool::MIME.type_for(file)
|
|
153
|
-
Informer.debug("Serving static: #{file}")
|
|
154
|
-
File.open(file, 'rb')
|
|
59
|
+
def filter path
|
|
60
|
+
trait[:dispatch].each do |dispatcher|
|
|
61
|
+
result = dispatcher.process(path)
|
|
62
|
+
return result if result
|
|
155
63
|
end
|
|
64
|
+
raise Ramaze::Error::NoAction, "No Dispatcher found for `#{path}'"
|
|
156
65
|
end
|
|
157
66
|
|
|
158
|
-
|
|
159
|
-
# if Global.cookies is true (which it is by default) and set the default
|
|
160
|
-
# Content-Type to 'text/plain'
|
|
161
|
-
|
|
162
|
-
def build_response body = '', status = STATUS_CODE[:internal_server_error], head = {}
|
|
67
|
+
def build_response body = response.body, status = response.status, head = response.header
|
|
163
68
|
set_cookie if Global.cookies
|
|
164
69
|
head.each do |key, value|
|
|
165
70
|
response[key] = value
|
|
@@ -184,7 +89,7 @@ module Ramaze
|
|
|
184
89
|
|
|
185
90
|
def setup_environment rack_request, rack_response
|
|
186
91
|
this = Thread.current
|
|
187
|
-
this[:request] =
|
|
92
|
+
this[:request] = rack_request
|
|
188
93
|
this[:session] = Session.new(request)
|
|
189
94
|
this[:response] = rack_response
|
|
190
95
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
# require 'ramaze/tool/tidy'
|
|
5
|
+
# require 'ramaze/tool/localize'
|
|
6
|
+
|
|
7
|
+
module Ramaze
|
|
8
|
+
module Dispatcher
|
|
9
|
+
class Action
|
|
10
|
+
|
|
11
|
+
# The response is passed to each filter by sending .call(response) to it.
|
|
12
|
+
|
|
13
|
+
trait :filter => [
|
|
14
|
+
# Ramaze::Tool::Localize,
|
|
15
|
+
# Ramaze::Tool::Tidy
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
def process(path)
|
|
20
|
+
body = Controller.handle(path)
|
|
21
|
+
response = Dispatcher.build_response(body)
|
|
22
|
+
filter = ancestral_trait[:filter]
|
|
23
|
+
filter.inject(response){|r,f| f.call(r) }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
module Dispatcher
|
|
6
|
+
class Error
|
|
7
|
+
class << self
|
|
8
|
+
trait :last_error => nil
|
|
9
|
+
|
|
10
|
+
def process error
|
|
11
|
+
log_error(error)
|
|
12
|
+
|
|
13
|
+
Thread.current[:exception] = error
|
|
14
|
+
handle_error = Dispatcher.trait[:handle_error]
|
|
15
|
+
|
|
16
|
+
key = error.class.ancestors.find{|a| handle_error[a]}
|
|
17
|
+
status, path = *handle_error[key || Exception]
|
|
18
|
+
|
|
19
|
+
unless error.message =~ %r(`#{path.split('/').last}')
|
|
20
|
+
Response.current.status = status
|
|
21
|
+
return Dispatcher.dispatch_to(path) if path and Global.error_page
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Dispatcher.build_response(error.message, status)
|
|
25
|
+
rescue Object => ex
|
|
26
|
+
Inform.error(ex)
|
|
27
|
+
Dispatcher.build_response(ex.message, status || 500)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def log_error error
|
|
31
|
+
error_message = error.message
|
|
32
|
+
|
|
33
|
+
if trait[:last_error] == error_message
|
|
34
|
+
Inform.error(error_message)
|
|
35
|
+
else
|
|
36
|
+
trait[:last_error] = error_message
|
|
37
|
+
Inform.error(error)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
module Dispatcher
|
|
6
|
+
class File
|
|
7
|
+
class << self
|
|
8
|
+
def process(path)
|
|
9
|
+
return unless file = open_file(path)
|
|
10
|
+
Dispatcher.build_response(file, Ramaze::STATUS_CODE[:ok])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def lookup_paths
|
|
14
|
+
[ (BASEDIR/'proto'/'public'),
|
|
15
|
+
Global.controllers.map{|c| c.trait[:public]},
|
|
16
|
+
'./public'
|
|
17
|
+
].flatten.select{|f| ::File.directory?(f.to_s)}.map{|f| ::File.expand_path(f)}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def open_file(path)
|
|
21
|
+
paths = lookup_paths.map{|pa| pa/path}
|
|
22
|
+
file = paths.find{|way| ::File.file?(way)}
|
|
23
|
+
|
|
24
|
+
if file
|
|
25
|
+
response = Response.current
|
|
26
|
+
response['Content-Type'] = Tool::MIME.type_for(file)
|
|
27
|
+
Inform.debug("Serving static: #{file}")
|
|
28
|
+
::File.open(file, 'rb')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/ramaze/global.rb
CHANGED
|
@@ -6,26 +6,19 @@ require 'set'
|
|
|
6
6
|
|
|
7
7
|
module Ramaze
|
|
8
8
|
class GlobalStruct < OpenStruct
|
|
9
|
-
# autoreload
|
|
10
|
-
# adapter
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
# inform_to - :stdout/'stdout'/$stderr (similar for stdout) or some path to a file
|
|
23
|
-
# inform_tags - a Set with any of [ :debug, :info, :error ]
|
|
24
|
-
# inform_backtrace_size - size of backtrace to be logged (and show on error-page).
|
|
25
|
-
# inform_timestamp - parameter for Time.strftime
|
|
26
|
-
# inform_prefix_info - prefix for all the Inform#info messages
|
|
27
|
-
# inform_prefix_debug - prefix for all the Inform#debug messages
|
|
28
|
-
# inform_prefix_error - prefix for all the Inform#error messages
|
|
9
|
+
# autoreload - Interval for autoreloading changed source in seconds
|
|
10
|
+
# adapter - Webserver-adapter ( :mongrel | :webrick )
|
|
11
|
+
# backtrace_size - size of backtrace to be logged (and shown on error-page).
|
|
12
|
+
# benchmarking - enable timing of each request
|
|
13
|
+
# cache - Cache to use ( MemcachedCache | MemoryCache | YamlStoreCache )
|
|
14
|
+
# cache_all - Naive caching for all responses ( true | false )
|
|
15
|
+
# cookies -
|
|
16
|
+
# error_page - Show default errorpage with inspection and backtrace ( true | false )
|
|
17
|
+
# host - Host to respond to ( '0.0.0.0' )
|
|
18
|
+
# mapping - Route to controller map ( {} )
|
|
19
|
+
# port - First port of the port-range the adapters run on. ( 7000 )
|
|
20
|
+
# run_loose - Don't wait for the servers to finish, useful for testing ( true | false )
|
|
21
|
+
# template_root - Default directory for your templates.
|
|
29
22
|
#
|
|
30
23
|
# startup - List of methods and lambdas that are executed on startup
|
|
31
24
|
# ramaze_startup - Internal list of methods and lambdas that are executed on startup
|
|
@@ -34,40 +27,45 @@ module Ramaze
|
|
|
34
27
|
# ramaze_shutdown - Internal list of methods and lambdas that are executed on shutdown
|
|
35
28
|
|
|
36
29
|
DEFAULT = {
|
|
37
|
-
:autoreload
|
|
38
|
-
:adapter
|
|
39
|
-
:
|
|
40
|
-
:
|
|
41
|
-
:
|
|
42
|
-
:
|
|
43
|
-
:
|
|
44
|
-
:
|
|
45
|
-
:
|
|
46
|
-
:
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
50
|
-
|
|
51
|
-
:
|
|
52
|
-
:
|
|
53
|
-
:
|
|
54
|
-
:
|
|
55
|
-
:
|
|
56
|
-
|
|
57
|
-
:
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
:autoreload => 5,
|
|
31
|
+
:adapter => :webrick,
|
|
32
|
+
:backtrace_size => 10,
|
|
33
|
+
:benchmarking => false,
|
|
34
|
+
:cache => MemoryCache,
|
|
35
|
+
:cache_all => false,
|
|
36
|
+
:controllers => Set.new,
|
|
37
|
+
:cookies => true,
|
|
38
|
+
:error_page => true,
|
|
39
|
+
:host => '0.0.0.0',
|
|
40
|
+
:localize => lambda{ Ramaze::Tool::Localize.trait },
|
|
41
|
+
:logger => Ramaze::Informer.new($stdout),
|
|
42
|
+
:mapping => {},
|
|
43
|
+
:port => 7000,
|
|
44
|
+
:run_loose => false,
|
|
45
|
+
:template_root => 'template',
|
|
46
|
+
:tidy => lambda{ Ramaze::Tool::Tidy.trait },
|
|
47
|
+
:test_connections => true,
|
|
48
|
+
:shutdown_trap => 'SIGINT',
|
|
49
|
+
|
|
50
|
+
:startup => [
|
|
51
|
+
lambda{
|
|
52
|
+
Ramaze::Inform = Global.logger unless defined?(Inform)
|
|
53
|
+
Inform.info("Starting up Ramaze (Version #{VERSION})")
|
|
54
|
+
}
|
|
55
|
+
],
|
|
60
56
|
:ramaze_startup => [
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
:setup_controllers, :init_autoreload, :init_adapter
|
|
58
|
+
],
|
|
63
59
|
|
|
64
60
|
:shutdown => [],
|
|
65
61
|
:ramaze_shutdown => [
|
|
66
62
|
:kill_threads,
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
lambda{
|
|
64
|
+
Inform.shutdown
|
|
65
|
+
puts("Shutdown Ramaze (it's save to kill me now if i hang)")
|
|
66
|
+
},
|
|
69
67
|
:exit
|
|
70
|
-
|
|
68
|
+
],
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
# takes an hash of options and optionally an block that is evaled in this
|
|
@@ -106,6 +104,12 @@ module Ramaze
|
|
|
106
104
|
table.values_at(*keys.map(&:to_sym))
|
|
107
105
|
end
|
|
108
106
|
|
|
107
|
+
# all keys already set
|
|
108
|
+
|
|
109
|
+
def keys
|
|
110
|
+
table.keys
|
|
111
|
+
end
|
|
112
|
+
|
|
109
113
|
# iterate over the GlobalStruct, no guarantee on the order.
|
|
110
114
|
|
|
111
115
|
def each
|
|
@@ -121,6 +125,43 @@ module Ramaze
|
|
|
121
125
|
def pretty_inspect
|
|
122
126
|
table.pretty_inspect
|
|
123
127
|
end
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def new_ostruct_member(name)
|
|
131
|
+
name = name.to_sym
|
|
132
|
+
unless self.respond_to?(name)
|
|
133
|
+
class << self; self; end.class_eval do
|
|
134
|
+
define_method(name) { @table[name] }
|
|
135
|
+
define_method(:"#{name}=") { |x| @table[name] = x }
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def new_ostruct_member(name)
|
|
141
|
+
name = name.to_sym
|
|
142
|
+
unless self.respond_to?(name)
|
|
143
|
+
meta = (class << self; self; end)
|
|
144
|
+
meta.class_eval do
|
|
145
|
+
define_method(name) do
|
|
146
|
+
sel = @table[name]
|
|
147
|
+
if sel.respond_to?(:call)
|
|
148
|
+
sel.call
|
|
149
|
+
else
|
|
150
|
+
sel
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
define_method(:"#{name}=") do |x|
|
|
155
|
+
sel = @table[name]
|
|
156
|
+
if sel.respond_to?(:call)
|
|
157
|
+
sel.call("#{name}=", x)
|
|
158
|
+
else
|
|
159
|
+
@table[name] = x
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
124
165
|
end
|
|
125
166
|
|
|
126
167
|
Thread.current[:global] = GlobalStruct.new(GlobalStruct::DEFAULT)
|