ramaze 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/Rakefile +360 -0
  2. data/bin/ramaze +152 -0
  3. data/doc/CHANGELOG +2021 -0
  4. data/doc/COPYING +56 -0
  5. data/doc/COPYING.ja +51 -0
  6. data/doc/README +275 -0
  7. data/doc/TODO +33 -0
  8. data/doc/allison/LICENSE +184 -0
  9. data/doc/allison/README +37 -0
  10. data/doc/allison/allison.css +300 -0
  11. data/doc/allison/allison.gif +0 -0
  12. data/doc/allison/allison.js +307 -0
  13. data/doc/allison/allison.rb +287 -0
  14. data/doc/allison/cache/BODY +588 -0
  15. data/doc/allison/cache/CLASS_INDEX +4 -0
  16. data/doc/allison/cache/CLASS_PAGE +1 -0
  17. data/doc/allison/cache/FILE_INDEX +4 -0
  18. data/doc/allison/cache/FILE_PAGE +1 -0
  19. data/doc/allison/cache/FONTS +1 -0
  20. data/doc/allison/cache/FR_INDEX_BODY +1 -0
  21. data/doc/allison/cache/IMGPATH +1 -0
  22. data/doc/allison/cache/INDEX +1 -0
  23. data/doc/allison/cache/JAVASCRIPT +307 -0
  24. data/doc/allison/cache/METHOD_INDEX +4 -0
  25. data/doc/allison/cache/METHOD_LIST +1 -0
  26. data/doc/allison/cache/SRC_PAGE +1 -0
  27. data/doc/allison/cache/STYLE +322 -0
  28. data/doc/allison/cache/URL +1 -0
  29. data/examples/blog/main.rb +16 -0
  30. data/examples/blog/public/screen.css +106 -0
  31. data/examples/blog/src/controller.rb +50 -0
  32. data/examples/blog/src/element.rb +53 -0
  33. data/examples/blog/src/model.rb +29 -0
  34. data/examples/blog/template/edit.xhtml +6 -0
  35. data/examples/blog/template/index.xhtml +24 -0
  36. data/examples/blog/template/new.xhtml +5 -0
  37. data/examples/blog/template/view.xhtml +15 -0
  38. data/examples/blog/test/tc_entry.rb +18 -0
  39. data/examples/caching.rb +23 -0
  40. data/examples/element.rb +40 -0
  41. data/examples/hello.rb +23 -0
  42. data/examples/simple.rb +60 -0
  43. data/examples/templates/template/external.haml +21 -0
  44. data/examples/templates/template/external.liquid +28 -0
  45. data/examples/templates/template/external.mab +27 -0
  46. data/examples/templates/template/external.rhtml +29 -0
  47. data/examples/templates/template/external.rmze +24 -0
  48. data/examples/templates/template_erubis.rb +50 -0
  49. data/examples/templates/template_haml.rb +48 -0
  50. data/examples/templates/template_liquid.rb +64 -0
  51. data/examples/templates/template_markaby.rb +52 -0
  52. data/examples/templates/template_ramaze.rb +49 -0
  53. data/examples/whywiki/main.rb +56 -0
  54. data/examples/whywiki/template/edit.xhtml +14 -0
  55. data/examples/whywiki/template/show.xhtml +17 -0
  56. data/lib/proto/conf/benchmark.yaml +35 -0
  57. data/lib/proto/conf/debug.yaml +34 -0
  58. data/lib/proto/conf/live.yaml +33 -0
  59. data/lib/proto/conf/silent.yaml +31 -0
  60. data/lib/proto/conf/stage.yaml +33 -0
  61. data/lib/proto/main.rb +18 -0
  62. data/lib/proto/public/404.jpg +0 -0
  63. data/lib/proto/public/css/coderay.css +105 -0
  64. data/lib/proto/public/css/ramaze_error.css +42 -0
  65. data/lib/proto/public/error.xhtml +74 -0
  66. data/lib/proto/public/favicon.ico +0 -0
  67. data/lib/proto/public/js/jquery.js +1923 -0
  68. data/lib/proto/public/ramaze.png +0 -0
  69. data/lib/proto/src/controller/main.rb +7 -0
  70. data/lib/proto/src/element/page.rb +16 -0
  71. data/lib/proto/src/model.rb +5 -0
  72. data/lib/proto/template/index.xhtml +6 -0
  73. data/lib/ramaze.rb +317 -0
  74. data/lib/ramaze/adapter/mongrel.rb +111 -0
  75. data/lib/ramaze/adapter/webrick.rb +161 -0
  76. data/lib/ramaze/cache.rb +11 -0
  77. data/lib/ramaze/cache/memcached.rb +52 -0
  78. data/lib/ramaze/cache/memory.rb +6 -0
  79. data/lib/ramaze/cache/yaml_store.rb +37 -0
  80. data/lib/ramaze/controller.rb +10 -0
  81. data/lib/ramaze/dispatcher.rb +315 -0
  82. data/lib/ramaze/error.rb +11 -0
  83. data/lib/ramaze/gestalt.rb +108 -0
  84. data/lib/ramaze/global.rb +120 -0
  85. data/lib/ramaze/helper.rb +32 -0
  86. data/lib/ramaze/helper/aspect.rb +189 -0
  87. data/lib/ramaze/helper/auth.rb +120 -0
  88. data/lib/ramaze/helper/cache.rb +52 -0
  89. data/lib/ramaze/helper/feed.rb +135 -0
  90. data/lib/ramaze/helper/form.rb +204 -0
  91. data/lib/ramaze/helper/link.rb +80 -0
  92. data/lib/ramaze/helper/redirect.rb +48 -0
  93. data/lib/ramaze/helper/stack.rb +67 -0
  94. data/lib/ramaze/http_status.rb +66 -0
  95. data/lib/ramaze/inform.rb +166 -0
  96. data/lib/ramaze/snippets.rb +5 -0
  97. data/lib/ramaze/snippets/hash/keys_to_sym.rb +19 -0
  98. data/lib/ramaze/snippets/kernel/aquire.rb +22 -0
  99. data/lib/ramaze/snippets/kernel/autoreload.rb +79 -0
  100. data/lib/ramaze/snippets/kernel/caller_lines.rb +58 -0
  101. data/lib/ramaze/snippets/kernel/constant.rb +24 -0
  102. data/lib/ramaze/snippets/kernel/rescue_require.rb +12 -0
  103. data/lib/ramaze/snippets/kernel/self_method.rb +41 -0
  104. data/lib/ramaze/snippets/kernel/silently.rb +13 -0
  105. data/lib/ramaze/snippets/object/traits.rb +60 -0
  106. data/lib/ramaze/snippets/openstruct/temp.rb +10 -0
  107. data/lib/ramaze/snippets/string/DIVIDE.rb +16 -0
  108. data/lib/ramaze/snippets/string/camel_case.rb +14 -0
  109. data/lib/ramaze/snippets/string/snake_case.rb +12 -0
  110. data/lib/ramaze/snippets/symbol/to_proc.rb +14 -0
  111. data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +11 -0
  112. data/lib/ramaze/store/default.rb +48 -0
  113. data/lib/ramaze/template.rb +102 -0
  114. data/lib/ramaze/template/amrita2.rb +40 -0
  115. data/lib/ramaze/template/erubis.rb +58 -0
  116. data/lib/ramaze/template/haml.rb +65 -0
  117. data/lib/ramaze/template/haml/actionview_stub.rb +20 -0
  118. data/lib/ramaze/template/liquid.rb +74 -0
  119. data/lib/ramaze/template/markaby.rb +68 -0
  120. data/lib/ramaze/template/ramaze.rb +177 -0
  121. data/lib/ramaze/template/ramaze/element.rb +166 -0
  122. data/lib/ramaze/template/ramaze/morpher.rb +156 -0
  123. data/lib/ramaze/tool/create.rb +70 -0
  124. data/lib/ramaze/tool/tidy.rb +71 -0
  125. data/lib/ramaze/trinity.rb +38 -0
  126. data/lib/ramaze/trinity/request.rb +244 -0
  127. data/lib/ramaze/trinity/response.rb +41 -0
  128. data/lib/ramaze/trinity/session.rb +129 -0
  129. data/lib/ramaze/version.rb +14 -0
  130. data/spec/spec_all.rb +73 -0
  131. data/spec/spec_helper.rb +215 -0
  132. data/spec/tc_adapter_mongrel.rb +24 -0
  133. data/spec/tc_adapter_webrick.rb +22 -0
  134. data/spec/tc_cache.rb +79 -0
  135. data/spec/tc_controller.rb +39 -0
  136. data/spec/tc_element.rb +100 -0
  137. data/spec/tc_error.rb +23 -0
  138. data/spec/tc_gestalt.rb +90 -0
  139. data/spec/tc_global.rb +46 -0
  140. data/spec/tc_helper_aspect.rb +65 -0
  141. data/spec/tc_helper_auth.rb +61 -0
  142. data/spec/tc_helper_cache.rb +81 -0
  143. data/spec/tc_helper_feed.rb +129 -0
  144. data/spec/tc_helper_form.rb +146 -0
  145. data/spec/tc_helper_link.rb +58 -0
  146. data/spec/tc_helper_redirect.rb +51 -0
  147. data/spec/tc_helper_stack.rb +55 -0
  148. data/spec/tc_morpher.rb +90 -0
  149. data/spec/tc_params.rb +84 -0
  150. data/spec/tc_request.rb +111 -0
  151. data/spec/tc_session.rb +56 -0
  152. data/spec/tc_store.rb +25 -0
  153. data/spec/tc_template_amrita2.rb +34 -0
  154. data/spec/tc_template_erubis.rb +41 -0
  155. data/spec/tc_template_haml.rb +44 -0
  156. data/spec/tc_template_liquid.rb +98 -0
  157. data/spec/tc_template_markaby.rb +74 -0
  158. data/spec/tc_template_ramaze.rb +54 -0
  159. data/spec/tc_tidy.rb +14 -0
  160. data/spec/template/amrita2/data.html +6 -0
  161. data/spec/template/amrita2/index.html +1 -0
  162. data/spec/template/amrita2/sum.html +1 -0
  163. data/spec/template/erubis/sum.rhtml +1 -0
  164. data/spec/template/haml/index.haml +5 -0
  165. data/spec/template/haml/with_vars.haml +4 -0
  166. data/spec/template/liquid/index.liquid +1 -0
  167. data/spec/template/liquid/products.liquid +45 -0
  168. data/spec/template/markaby/external.mab +8 -0
  169. data/spec/template/markaby/sum.mab +1 -0
  170. data/spec/template/ramaze/file_only.rmze +1 -0
  171. data/spec/template/ramaze/index.rmze +1 -0
  172. data/spec/template/ramaze/nested.rmze +1 -0
  173. data/spec/template/ramaze/sum.rmze +1 -0
  174. metadata +317 -0
@@ -0,0 +1,7 @@
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
+ class MainController < Template::Ramaze
4
+ def index
5
+ "Hello, World"
6
+ end
7
+ end
@@ -0,0 +1,16 @@
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
+ class Page < Element
4
+ def render
5
+ %{
6
+ <html>
7
+ <head>
8
+ <title>Welcome to Ramaze</title>
9
+ </head>
10
+ <body>
11
+ #{content}
12
+ </body>
13
+ </html>
14
+ }
15
+ end
16
+ end
@@ -0,0 +1,5 @@
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
+ require 'yaml/store'
4
+
5
+ Db = YAML::Store.new('yaml.db')
@@ -0,0 +1,6 @@
1
+ <Page>
2
+ <h1>Welcome to Ramaze</h1>
3
+ <p>
4
+ blah, blah, blah
5
+ </p>
6
+ </Page>
@@ -0,0 +1,317 @@
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
+ # The main namespace for Ramaze
5
+ module Ramaze
6
+ BASEDIR = File.dirname(File.expand_path(__FILE__))
7
+ end
8
+
9
+ $:.unshift Ramaze::BASEDIR
10
+
11
+ require 'timeout'
12
+ require 'ostruct'
13
+ require 'socket'
14
+ require 'yaml'
15
+ require 'set'
16
+ require 'pp'
17
+
18
+ require 'ramaze/snippets'
19
+ require 'ramaze/cache'
20
+ require 'ramaze/controller'
21
+ require 'ramaze/dispatcher'
22
+ require 'ramaze/error'
23
+ require 'ramaze/gestalt'
24
+ require 'ramaze/global'
25
+ require 'ramaze/inform'
26
+ require 'ramaze/http_status'
27
+ require 'ramaze/snippets'
28
+ require 'ramaze/helper'
29
+ require 'ramaze/template'
30
+ require 'ramaze/version'
31
+
32
+ module Ramaze
33
+ include Inform
34
+
35
+ # This initializes all the other stuff, Controller, Adapter and Global
36
+ # which in turn kickstart Ramaze into duty.
37
+ # additionally it starts up the autoreload , which reloads all the stuff every
38
+ # second in case it has changed.
39
+ # please note that Ramaze will catch SIGINT (^C) and kill the running adapter
40
+ # at that event, this provides a nice and clean way to shut down.
41
+ #
42
+ # The start might be a bit odd, but i think it is a quite decent hack, what
43
+ # it does is following.
44
+ # It looks up who called the start-method, and if the method that called it
45
+ # is not the file that was run first, it will return without doing anything
46
+ # The use of this is:
47
+ # If you start ramaze over the CLI, using ruby main.rb
48
+ # and the start-method is called in your main.rb, it will run, using the
49
+ # configuration from you without any modifcation (just with the defaults)
50
+ # In case you start it via the ramaze-command however, you may pass options
51
+ # that could be overwritten by your application, but you just want to use
52
+ # these options temporarily - in this case the start-call from your main.rb
53
+ # will simply be ignored, the start from bin/ramaze is invoked which in turn
54
+ # sets the options you passed on the commandline.
55
+ # If you pertout want to run with bin/ramaze, pass commandline-options _and_
56
+ # use the start-method your own application, use start(:force => true)
57
+ # This also applies if your start is in another file than the file you
58
+ # called first, therefor giving you the option to layout your application
59
+ # as it pleases you.
60
+
61
+ def start options = {}
62
+ starter = caller[0].split(':').first
63
+ return unless $0 == starter or options.delete(:force)
64
+
65
+ init_global options
66
+
67
+ Thread.abort_on_exception = true
68
+
69
+ return if options.delete(:fake_start)
70
+
71
+ info "Starting up Ramaze (Version #{VERSION})"
72
+
73
+ startup
74
+ end
75
+
76
+ alias run start
77
+ alias new start
78
+
79
+ # same as start(:force => true)
80
+
81
+ def force_start(options = {})
82
+ start options.merge(:force => true)
83
+ end
84
+
85
+ alias force_run force_start
86
+
87
+ # Execute the tasks specified in Global.startup
88
+ # (where you can define your own tasks)
89
+ # and afterwards the ones in Global.ramaze_startup
90
+ # (reserved for the usage of Ramaze itself)
91
+
92
+ def startup
93
+ tasks = Global.startup + Global.ramaze_startup
94
+ execute *tasks
95
+ end
96
+
97
+ # Execute the tasks specified in Global.shutdown
98
+ # (where you can define your own tasks)
99
+ # and afterwards the ones in Global.ramaze_shutdown
100
+ # (reserved for the usage of Ramaze itself)
101
+
102
+ def shutdown
103
+ tasks = Global.shutdown + Global.ramaze_shutdown
104
+ execute *tasks
105
+ end
106
+
107
+ # executes a list of tasks, depending on the task-object, if it responds to
108
+ # :call it will be called upon, otherwise the task is sent to self ( the
109
+ # module Ramaze ).
110
+
111
+ def execute *tasks
112
+ tasks.flatten.each do |task|
113
+ begin
114
+ if task.respond_to?(:call)
115
+ task.call
116
+ else
117
+ send(task)
118
+ end
119
+ rescue Object => ex
120
+ exit if ex.is_a?(SystemExit)
121
+ error ex
122
+ end
123
+ end
124
+ end
125
+
126
+ # kill all threads except Thread.main before #shutdown
127
+
128
+ def kill_threads
129
+ info "Killing the Threads"
130
+ Global.adapter_klass.stop rescue nil
131
+ (Thread.list - [Thread.main]).each do |thread|
132
+ Timeout.timeout(2) do
133
+ thread.kill
134
+ end
135
+ end
136
+ end
137
+
138
+ # closes the IO that Global.inform_to points to.
139
+
140
+ def close_inform
141
+ if to = Global.inform_to and to.respond_to?(:close)
142
+ debug "close #{to.inspect}"
143
+ to.close until to.closed?
144
+ end
145
+ end
146
+
147
+ # first, search for all the classes that end with 'Controller'
148
+ # like FooController, BarController and so on
149
+ # then we search the classes within Ramaze::Controller as well
150
+
151
+ def find_controllers
152
+ Global.controllers ||= Set.new
153
+
154
+ Module.constants.each do |klass|
155
+ Global.controllers << constant(klass) if klass =~ /.+?Controller/
156
+ end
157
+
158
+ Ramaze::Controller.constants.each do |klass|
159
+ klass = constant("Ramaze::Controller::#{klass}")
160
+ Global.controllers << klass
161
+ end
162
+
163
+ debug "Found following Controllers: #{Global.controllers.inspect}"
164
+ end
165
+
166
+ # Setup the Controllers
167
+ # This autogenerates a mapping and also includes Ramaze::Controller
168
+ # in every found Controller.
169
+
170
+ def setup_controllers
171
+ Global.mapping ||= {}
172
+
173
+ Global.mapping.dup.each do |route, controller|
174
+ Global.mapping[route] = constant(controller.to_s)
175
+ end
176
+
177
+ mapping = {}
178
+
179
+ Global.controllers.each do |c|
180
+ name = c.to_s.gsub('Controller', '').split('::').last
181
+ if %w[Main Base Index].include?(name)
182
+ mapping['/'] = c
183
+ else
184
+ mapping["/#{name.split('::').last.snake_case}"] = c
185
+ end
186
+ c.__send__(:send, :include, Ramaze::Controller)
187
+ end
188
+
189
+ Global.mapping.merge!(mapping) if Global.mapping.empty?
190
+
191
+ # Now we make them to real Ramaze::Controller s :)
192
+ # also we set controller-variable as we go along, in case there
193
+ # is only one controller it ends up hooked on '/'
194
+ # otherwise we get some random one ...
195
+
196
+ Global.controllers.map! do |controller|
197
+ controller = constant(controller)
198
+ controller.send(:include, Ramaze::Controller)
199
+ end
200
+ end
201
+
202
+ # Initialize the Kernel#autoreload with the value of Global.autoreload
203
+
204
+ def init_autoreload
205
+ return unless Global.autoreload
206
+ Ramaze.autoreload Global.autoreload
207
+ end
208
+
209
+ # initialize the Global, setting a default-mapping if none is given yet.
210
+ #
211
+ # You may pass :force_setup => true in your options if you want your options
212
+ # to override everything else set till now.
213
+
214
+ def init_global options = {}
215
+ tmp_mapping = Global.mapping || {}
216
+
217
+ if options.delete(:force_setup)
218
+ Global.setup(options)
219
+ else
220
+ Global.update(options)
221
+ end
222
+
223
+ Global.mapping = tmp_mapping.merge(Global.mapping)
224
+ end
225
+
226
+ # Finally decide wether to use a main-thread to run Ramaze
227
+ # so that further stuff can be done outside (very useful for testcases)
228
+ # or we run it in standalone-mode, which is the default and waits
229
+ # until the adapter is finished. (hopefully never ;)
230
+ # change this behaviour by setting Global.run_loose = (true|false)
231
+ # In every case the running adapter-thread is assigned to
232
+ # Global.running_adapter
233
+
234
+ def init_adapter
235
+ (Thread.list - [Thread.current]).each do |thread|
236
+ thread.kill if thread[:task] == :adapter
237
+ end
238
+
239
+ Thread.new do
240
+ Thread.current.priority = 99
241
+ Thread.current[:task] = :adapter
242
+ Global.running_adapter = run_adapter
243
+
244
+ trap(Global.shutdown_trap){ shutdown } rescue nil
245
+ end
246
+
247
+ Timeout.timeout(3) do
248
+ sleep 0.1 until Global.running_adapter
249
+ end
250
+ Global.running_adapter.join unless Global.run_loose
251
+ rescue Object => ex
252
+ debug ex.message unless ex.is_a? Interrupt
253
+ shutdown
254
+ end
255
+
256
+ # This first picks the right adapter according to Global.adapter
257
+ # It also looks for Global.host and Global.port and passes it on
258
+ # to the class-method of the adapter ::start
259
+
260
+ def run_adapter
261
+ adapter, host, port = Global.values_at(:adapter, :host, :port)
262
+ require_adapter(adapter)
263
+
264
+ adapter_klass = Ramaze::Adapter.const_get(adapter.to_s.capitalize)
265
+ Global.adapter_klass = adapter_klass
266
+
267
+ info "Found adapter: #{adapter_klass}, trying to connect to #{host}:#{port} ..."
268
+
269
+ parse_port(port)
270
+ shutdown unless test_connections(host, Global.ports)
271
+ info "and we're running: #{host}:#{port}"
272
+
273
+ adapter_klass.start host, Global.ports
274
+ end
275
+
276
+ # require the specified adapter from 'ramaze/adapter/name.to_s.downcase'
277
+
278
+ def require_adapter adapter
279
+ require "ramaze/adapter" / adapter.to_s.downcase
280
+ rescue LoadError => ex
281
+ puts ex
282
+ puts "Please make sure you have an adapter called #{adapter}"
283
+ shutdown
284
+ end
285
+
286
+ # convert ports given as string (7000..7007) to an actual range.
287
+ # sets Global.port to the first of the ports given
288
+ # sets Global.ports to the range (if one port given just a range from
289
+ # that to the same (7000..7000)
290
+
291
+ def parse_port port
292
+ if (from_port, to_port = port.to_s.split('..')).compact.size == 2
293
+ Global.ports = from_port.to_i..to_port.to_i
294
+ else
295
+ Global.ports = from_port.to_i..from_port.to_i
296
+ end
297
+ Global.port = Global.ports.begin
298
+ end
299
+
300
+ # test if a connection can be made at the specified host/ports.
301
+
302
+ def test_connections host, ports
303
+ ports.map{|port| connection_possible(host, port) }.all?
304
+ end
305
+
306
+ # check connectivity to a specific host/port
307
+
308
+ def connection_possible host, port
309
+ Timeout.timeout(1) do
310
+ TCPServer.open(host, port){ true }
311
+ end
312
+ rescue => ex
313
+ puts ex.message
314
+ false
315
+ end
316
+ extend self
317
+ end
@@ -0,0 +1,111 @@
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 'benchmark'
5
+
6
+ require 'mongrel'
7
+ require 'ramaze/tool/tidy'
8
+
9
+ # for OSX compatibility
10
+ Socket.do_not_reverse_lookup = true
11
+
12
+ module Mongrel
13
+ class Configurator
14
+
15
+ # the default for log is Informer#<< like WEBrick
16
+
17
+ def log(msg)
18
+ Informer << "Mongrel: #{msg}"
19
+ end
20
+ end
21
+ end
22
+
23
+ module Ramaze::Adapter
24
+ class Mongrel < ::Mongrel::HttpHandler
25
+
26
+ class << self
27
+
28
+ # starts a range of servers on the given host/ports.
29
+ # answers with the first adapter it creates.
30
+
31
+ def start host, ports
32
+ ports.map{|port| run_server(host, port) }.first
33
+ end
34
+
35
+ # run the actual adapter on host/port, answering with the Thread
36
+ # mongrel creates.
37
+
38
+ def run_server host, port
39
+ h = ::Mongrel::HttpServer.new host, port
40
+ h.register "/", self.new
41
+
42
+ h.run
43
+ end
44
+
45
+ # doesn't do anything, for the time being.
46
+
47
+ def stop
48
+ debug "stopping Mongrel"
49
+ end
50
+ end
51
+
52
+ # Process a request and give a response, based on the objects
53
+ # Mongrel gives it.
54
+ #
55
+ # if the Global.inform_tags include :benchmark it will run #bench_process,
56
+ # otherwise simply #respond.
57
+
58
+ def process(request, response)
59
+ @request, @response = request, response
60
+ Global.inform_tags.include?(:benchmark) ? bench_respond : respond
61
+ end
62
+
63
+ # benchmark the current request/respond cycle and output the result
64
+ # via Inform#debug (so make sure you got :debug in your Global.inform_tags
65
+ #
66
+ # It works as a simple wrapper with no other impacts on the rest
67
+ # of the system.
68
+
69
+ def bench_respond
70
+ time = Benchmark.measure do
71
+ respond
72
+ end
73
+ info "request took #{time.real}s"
74
+ end
75
+
76
+ # simply respond to a given request, #set_head and #set_out in the process
77
+ # as well as setting the response-status (which is, in case it is not
78
+ # given, 500, if nothing goes wrong it should be 200 or 302)
79
+
80
+ def respond
81
+ @our_response = Dispatcher.handle(@request, @response)
82
+ code = @our_response.code || STATUS_CODE[:internal_server_error]
83
+ @response.start(code) do |head, out|
84
+ set_head head
85
+ set_out out
86
+ end
87
+ end
88
+
89
+ # map the respond.head[key] to @response[key]
90
+
91
+ def set_head head
92
+ @our_response.head.each do |key, value|
93
+ head[key] = value
94
+ end
95
+ end
96
+
97
+ # set the body... in case you have Global.tidy = true it will run it
98
+ # through Tool::Tidy.tidy first (if your content-type is text/html)
99
+
100
+ def set_out out
101
+ our_out =
102
+ if Global.tidy and @our_response.content_type == 'text/html'
103
+ Tool::Tidy.tidy(@our_response.out)
104
+ else
105
+ @our_response.out
106
+ end
107
+ out << our_out
108
+ end
109
+
110
+ end
111
+ end