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.
Files changed (193) hide show
  1. data/Rakefile +14 -259
  2. data/bin/ramaze +52 -25
  3. data/doc/AUTHORS +6 -0
  4. data/doc/CHANGELOG +1363 -42
  5. data/doc/INSTALL +1 -1
  6. data/doc/README +48 -35
  7. data/doc/README.html +637 -0
  8. data/doc/TODO +7 -16
  9. data/doc/allison/allison.css +6 -7
  10. data/doc/allison/allison.gif +0 -0
  11. data/doc/allison/cache/STYLE +1 -2
  12. data/doc/changes.txt +3375 -0
  13. data/doc/changes.xml +3378 -0
  14. data/doc/meta/announcement.txt +47 -0
  15. data/doc/meta/configuration.txt +179 -0
  16. data/doc/meta/internals.txt +111 -0
  17. data/doc/readme_chunks/features.txt +8 -16
  18. data/doc/readme_chunks/installing.txt +7 -1
  19. data/doc/tutorial/todolist.txt +2 -3
  20. data/examples/blog/main.rb +9 -8
  21. data/examples/blog/public/styles/blog.css +132 -0
  22. data/examples/blog/src/controller.rb +14 -41
  23. data/examples/blog/src/model.rb +12 -13
  24. data/examples/blog/src/view.rb +16 -0
  25. data/examples/blog/template/edit.xhtml +19 -8
  26. data/examples/blog/template/index.xhtml +14 -22
  27. data/examples/blog/template/new.xhtml +18 -5
  28. data/examples/caching.rb +5 -8
  29. data/examples/element.rb +3 -3
  30. data/examples/hello.rb +3 -5
  31. data/examples/simple.rb +4 -7
  32. data/examples/templates/template/external.haml +8 -7
  33. data/examples/templates/template/external.mab +11 -8
  34. data/examples/templates/template_amrita2.rb +4 -4
  35. data/examples/templates/template_erubis.rb +3 -3
  36. data/examples/templates/template_ezamar.rb +1 -2
  37. data/examples/templates/template_haml.rb +24 -23
  38. data/examples/templates/template_liquid.rb +3 -1
  39. data/examples/templates/template_markaby.rb +15 -9
  40. data/examples/todolist/src/element/page.rb +1 -1
  41. data/lib/proto/conf/benchmark.yaml +6 -20
  42. data/lib/proto/conf/debug.yaml +6 -19
  43. data/lib/proto/conf/live.yaml +7 -19
  44. data/lib/proto/conf/silent.yaml +6 -16
  45. data/lib/proto/conf/stage.yaml +6 -18
  46. data/lib/proto/public/error.zmr +2 -2
  47. data/lib/ramaze.rb +34 -72
  48. data/lib/ramaze/adapter.rb +21 -18
  49. data/lib/ramaze/adapter/mongrel.rb +0 -3
  50. data/lib/ramaze/adapter/webrick.rb +6 -6
  51. data/lib/ramaze/cache/memcached.rb +3 -0
  52. data/lib/ramaze/controller.rb +227 -183
  53. data/lib/ramaze/dispatcher.rb +34 -129
  54. data/lib/ramaze/dispatcher/action.rb +28 -0
  55. data/lib/ramaze/dispatcher/error.rb +43 -0
  56. data/lib/ramaze/dispatcher/file.rb +34 -0
  57. data/lib/ramaze/global.rb +89 -48
  58. data/lib/ramaze/helper/aspect.rb +8 -6
  59. data/lib/ramaze/helper/auth.rb +3 -3
  60. data/lib/ramaze/helper/cache.rb +2 -2
  61. data/lib/ramaze/helper/file.rb +14 -0
  62. data/lib/ramaze/helper/inform.rb +36 -0
  63. data/lib/ramaze/helper/link.rb +7 -3
  64. data/lib/ramaze/helper/markaby.rb +30 -0
  65. data/lib/ramaze/helper/redirect.rb +2 -0
  66. data/lib/ramaze/inform.rb +8 -182
  67. data/lib/ramaze/inform/analogger.rb +19 -0
  68. data/lib/ramaze/inform/growl.rb +28 -0
  69. data/lib/ramaze/inform/hub.rb +26 -0
  70. data/lib/ramaze/inform/informer.rb +92 -0
  71. data/lib/ramaze/inform/informing.rb +44 -0
  72. data/lib/ramaze/inform/syslog.rb +27 -0
  73. data/lib/ramaze/inform/xosd.rb +42 -0
  74. data/lib/ramaze/snippets.rb +6 -2
  75. data/lib/ramaze/snippets/object/traits.rb +13 -1
  76. data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
  77. data/lib/ramaze/snippets/string/color.rb +27 -0
  78. data/lib/ramaze/snippets/string/each.rb +6 -0
  79. data/lib/ramaze/snippets/struct/fill.rb +15 -0
  80. data/lib/ramaze/template/ezamar.rb +13 -22
  81. data/lib/ramaze/template/ezamar/element.rb +12 -12
  82. data/lib/ramaze/template/liquid.rb +19 -18
  83. data/lib/ramaze/template/markaby.rb +37 -58
  84. data/lib/ramaze/tool/localize.rb +128 -0
  85. data/lib/ramaze/tool/tidy.rb +51 -21
  86. data/lib/ramaze/trinity.rb +3 -3
  87. data/lib/ramaze/trinity/request.rb +41 -23
  88. data/lib/ramaze/trinity/response.rb +10 -5
  89. data/lib/ramaze/trinity/session.rb +17 -3
  90. data/lib/ramaze/version.rb +2 -2
  91. data/rake_tasks/conf.rake +56 -0
  92. data/rake_tasks/gem.rake +44 -0
  93. data/rake_tasks/maintaince.rake +187 -0
  94. data/spec/all.rb +32 -0
  95. data/spec/examples/caching.rb +19 -0
  96. data/spec/examples/element.rb +15 -0
  97. data/spec/examples/hello.rb +11 -0
  98. data/spec/examples/simple.rb +51 -0
  99. data/spec/examples/templates/template_amrita2.rb +14 -0
  100. data/spec/examples/templates/template_erubis.rb +21 -0
  101. data/spec/examples/templates/template_ezamar.rb +22 -0
  102. data/spec/examples/templates/template_haml.rb +23 -0
  103. data/spec/examples/templates/template_liquid.rb +24 -0
  104. data/spec/examples/templates/template_markaby.rb +21 -0
  105. data/spec/helper.rb +81 -0
  106. data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
  107. data/spec/helper/layout.rb +55 -0
  108. data/spec/helper/mock_http.rb +66 -0
  109. data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
  110. data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
  111. data/spec/helper/wrap.rb +193 -0
  112. data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
  113. data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
  114. data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
  115. data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
  116. data/spec/ramaze/conf/locale_de.yaml +6 -0
  117. data/spec/ramaze/conf/locale_en.yaml +6 -0
  118. data/spec/ramaze/controller.rb +184 -0
  119. data/spec/ramaze/controller/template/greet.xhtml +1 -0
  120. data/spec/ramaze/controller/template_resolving.rb +54 -0
  121. data/spec/ramaze/dependencies.rb +16 -0
  122. data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
  123. data/spec/ramaze/error.rb +64 -0
  124. data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
  125. data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
  126. data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
  127. data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
  128. data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
  129. data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
  130. data/spec/ramaze/helper/file.rb +17 -0
  131. data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
  132. data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
  133. data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
  134. data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
  135. data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
  136. data/spec/ramaze/inform/informer.rb +40 -0
  137. data/spec/ramaze/inform/syslog.rb +10 -0
  138. data/spec/ramaze/localize.rb +40 -0
  139. data/spec/ramaze/morpher.rb +82 -0
  140. data/spec/ramaze/params.rb +124 -0
  141. data/spec/{public → ramaze/public}/error404.xhtml +0 -0
  142. data/spec/{public → ramaze/public}/favicon.ico +0 -0
  143. data/spec/{public → ramaze/public}/ramaze.png +0 -0
  144. data/spec/{public → ramaze/public}/test_download.css +0 -0
  145. data/spec/ramaze/request.rb +129 -0
  146. data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
  147. data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
  148. data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
  149. data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
  150. data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
  151. data/spec/ramaze/template.rb +86 -0
  152. data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
  153. data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
  154. data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
  155. data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
  156. data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
  157. data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
  158. data/spec/ramaze/template/ezamar.rb +62 -0
  159. data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
  160. data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
  161. data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
  162. data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
  163. data/spec/ramaze/template/ezamar/nested.zmr +1 -0
  164. data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
  165. data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
  166. data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
  167. data/spec/{template → ramaze/template}/haml/index.haml +0 -0
  168. data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
  169. data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
  170. data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
  171. data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
  172. data/spec/ramaze/template/markaby.rb +59 -0
  173. data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
  174. data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
  175. data/spec/ramaze/template/ramaze/external.test +1 -0
  176. data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
  177. metadata +145 -81
  178. data/examples/blog/public/screen.css +0 -106
  179. data/examples/blog/src/element.rb +0 -58
  180. data/examples/blog/template/view.xhtml +0 -15
  181. data/examples/blog/test/tc_entry.rb +0 -18
  182. data/lib/proto/public/404.jpg +0 -0
  183. data/spec/request_tc_helper.rb +0 -135
  184. data/spec/spec_all.rb +0 -118
  185. data/spec/spec_helper.rb +0 -66
  186. data/spec/tc_controller.rb +0 -49
  187. data/spec/tc_dependencies.rb +0 -13
  188. data/spec/tc_error.rb +0 -43
  189. data/spec/tc_morpher.rb +0 -88
  190. data/spec/tc_params.rb +0 -125
  191. data/spec/tc_template_ezamar.rb +0 -64
  192. data/spec/tc_template_markaby.rb +0 -72
  193. data/spec/template/ezamar/nested.zmr +0 -1
@@ -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
- module Ramaze
6
+ require 'ramaze/adapter'
7
+ require 'ramaze/tool/mime'
8
8
 
9
- # The Dispatcher is the very heart of Ramaze itself.
10
- #
11
- # It will take requests and guide the request through all parts of the
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
- trait :filters => [
20
- lambda{|path| handle_file path },
21
- lambda{|path| handle_action path },
22
- ]
15
+
16
+ trait :dispatch => [
17
+ Dispatcher::File,
18
+ Dispatcher::Action,
19
+ ]
23
20
 
24
21
  trait :handle_error => {
25
- Exception => '/error',
26
- Ramaze::Error::NoAction => '/error',
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 rack_request, rack_response
41
- respond
42
- rescue Object => exception
43
- handle_error(exception)
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
- # Obtain the path requested from the request and search for a static
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
- Informer.info "Request from #{request.remote_addr}: #{path}"
39
+ Inform.info("Request from #{request.remote_addr}: #{path}")
108
40
 
109
41
  catch(:respond) do
110
42
  redirection = catch(:redirect) do
111
- filtered = [filter(path)].flatten.first
112
- throw(:respond, build_response(filtered, response.status))
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
- Informer.info("Redirect to `#{head['Location']}'")
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 filter path
122
- last_error = $!
123
- ancestral_trait[:filters].each do |filter|
124
- filtered = run_filter(filter, path)
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 run_filter filter, path
135
- filter[path]
136
- rescue Object => ex
137
- ex
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
- # takes the content, code and head for a new response, will set the cookies
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] = Request.new(rack_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
@@ -6,26 +6,19 @@ require 'set'
6
6
 
7
7
  module Ramaze
8
8
  class GlobalStruct < OpenStruct
9
- # autoreload - Interval for autoreloading changed source in seconds
10
- # adapter - Webserver-adapter ( :mongrel | :webrick )
11
- # cache - Cache to use ( MemcachedCache | MemoryCache | YamlStoreCache )
12
- # cache_actions - Finegrained caching based on actions (see CacheHelper)
13
- # cache_all - Naive caching for all responses ( true | false )
14
- # error_page - Show default errorpage with inspection and backtrace ( true | false )
15
- # host - Host to respond to ( '0.0.0.0' )
16
- # mapping - Route to controller map ( {} )
17
- # port - First port of the port-range the adapters run on. ( 7000 )
18
- # run_loose - Don't wait for the servers to finish, useful for testing ( true | false )
19
- # tidy - Run all text/html responses through Tidy ( true | false )
20
- # template_root - Default directory for your templates.
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 => 5,
38
- :adapter => :webrick,
39
- :cache => MemoryCache,
40
- :cache_actions => Hash.new{|h,k| h[k] = Set.new},
41
- :cache_all => false,
42
- :cookies => true,
43
- :error_page => true,
44
- :host => '0.0.0.0',
45
- :mapping => {},
46
- :port => 7000,
47
- :run_loose => false,
48
- :tidy => false,
49
- :template_root => 'template',
50
-
51
- :inform_to => $stdout,
52
- :inform_tags => Set.new([:debug, :info, :error]),
53
- :inform_backtrace_size => 10,
54
- :inform_timestamp => "%Y-%m-%d %H:%M:%S",
55
- :inform_prefix_info => 'INFO ',
56
- :inform_prefix_debug => 'DEBUG',
57
- :inform_prefix_error => 'ERROR',
58
-
59
- :startup => [],
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
- :find_controllers, :setup_controllers, :init_autoreload, :init_adapter
62
- ],
57
+ :setup_controllers, :init_autoreload, :init_adapter
58
+ ],
63
59
 
64
60
  :shutdown => [],
65
61
  :ramaze_shutdown => [
66
62
  :kill_threads,
67
- :close_inform,
68
- lambda{ puts "Shutdown Ramaze (it's save to kill me now if i hang)" },
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)