nitro 0.31.0 → 0.40.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 (174) hide show
  1. data/bin/nitro +135 -37
  2. data/doc/CHANGELOG.1 +108 -108
  3. data/doc/CHANGELOG.2 +89 -89
  4. data/doc/CHANGELOG.3 +105 -105
  5. data/{CHANGELOG → doc/CHANGELOG.4} +509 -509
  6. data/doc/{AUTHORS → CONTRIBUTORS} +49 -37
  7. data/doc/LIBRARIES +13 -0
  8. data/doc/LICENSE +2 -3
  9. data/doc/MIGRATION +45 -0
  10. data/doc/RELEASES +131 -11
  11. data/doc/TODO +67 -0
  12. data/lib/glue/magick.rb +0 -3
  13. data/lib/glue/sweeper.rb +30 -15
  14. data/lib/glue/thumbnails.rb +0 -2
  15. data/lib/glue/webfile.rb +23 -11
  16. data/lib/nitro.rb +37 -44
  17. data/lib/nitro/adapter/cgi.rb +0 -3
  18. data/lib/nitro/adapter/console.rb +0 -2
  19. data/lib/nitro/adapter/fastcgi.rb +6 -3
  20. data/lib/nitro/adapter/mongrel.rb +97 -58
  21. data/lib/nitro/adapter/script.rb +4 -6
  22. data/lib/nitro/adapter/webrick.rb +33 -87
  23. data/lib/nitro/adapter/webrick/vcr.rb +85 -0
  24. data/lib/nitro/caching.rb +0 -2
  25. data/lib/nitro/caching/actions.rb +0 -2
  26. data/lib/nitro/caching/fragments.rb +0 -2
  27. data/lib/nitro/caching/output.rb +45 -16
  28. data/lib/nitro/caching/proxy.rb +49 -0
  29. data/lib/nitro/cgi.rb +3 -6
  30. data/lib/nitro/cgi/cookie.rb +0 -3
  31. data/lib/nitro/cgi/request.rb +67 -24
  32. data/lib/nitro/cgi/response.rb +0 -2
  33. data/lib/nitro/cgi/{sendfile.rb → send_file.rb} +7 -6
  34. data/lib/nitro/compiler.rb +62 -55
  35. data/lib/nitro/compiler/cleanup.rb +0 -3
  36. data/lib/nitro/compiler/elements.rb +31 -28
  37. data/lib/nitro/compiler/errors.rb +2 -5
  38. data/lib/nitro/compiler/include.rb +10 -8
  39. data/lib/nitro/compiler/layout.rb +0 -2
  40. data/lib/nitro/compiler/localization.rb +0 -2
  41. data/lib/nitro/compiler/markup.rb +14 -6
  42. data/lib/nitro/compiler/morphing.rb +1 -5
  43. data/lib/nitro/compiler/script.rb +2 -4
  44. data/lib/nitro/compiler/squeeze.rb +0 -2
  45. data/lib/nitro/compiler/xslt.rb +0 -2
  46. data/lib/nitro/context.rb +10 -5
  47. data/lib/nitro/control.rb +18 -0
  48. data/lib/nitro/control/attribute.rb +88 -0
  49. data/lib/nitro/control/attribute/checkbox.rb +19 -0
  50. data/lib/nitro/control/attribute/datetime.rb +21 -0
  51. data/lib/nitro/control/attribute/file.rb +20 -0
  52. data/lib/nitro/control/attribute/fixnum.rb +26 -0
  53. data/lib/nitro/control/attribute/float.rb +26 -0
  54. data/lib/nitro/control/attribute/options.rb +38 -0
  55. data/lib/nitro/control/attribute/password.rb +16 -0
  56. data/lib/nitro/control/attribute/text.rb +16 -0
  57. data/lib/nitro/control/attribute/textarea.rb +16 -0
  58. data/lib/nitro/control/none.rb +16 -0
  59. data/lib/nitro/control/relation.rb +53 -0
  60. data/lib/nitro/control/relation/belongs_to.rb +0 -0
  61. data/lib/nitro/control/relation/has_many.rb +97 -0
  62. data/lib/nitro/control/relation/joins_many.rb +0 -0
  63. data/lib/nitro/control/relation/many_to_many.rb +0 -0
  64. data/lib/nitro/control/relation/refers_to.rb +29 -0
  65. data/lib/nitro/controller.rb +7 -296
  66. data/lib/nitro/dispatcher.rb +72 -34
  67. data/lib/nitro/element.rb +36 -10
  68. data/lib/nitro/element/javascript.rb +0 -2
  69. data/lib/nitro/flash.rb +23 -10
  70. data/lib/nitro/global.rb +36 -11
  71. data/lib/nitro/helper.rb +22 -8
  72. data/lib/nitro/helper/benchmark.rb +0 -2
  73. data/lib/nitro/helper/buffer.rb +0 -3
  74. data/lib/nitro/helper/css.rb +12 -0
  75. data/lib/nitro/helper/debug.rb +1 -3
  76. data/lib/nitro/helper/default.rb +1 -0
  77. data/lib/nitro/helper/feed.rb +400 -386
  78. data/lib/nitro/helper/form.rb +246 -116
  79. data/lib/nitro/helper/javascript.rb +28 -2
  80. data/lib/nitro/helper/javascript/morphing.rb +0 -2
  81. data/lib/nitro/helper/javascript/prototype.rb +0 -2
  82. data/lib/nitro/helper/javascript/scriptaculous.rb +0 -1
  83. data/lib/nitro/helper/layout.rb +0 -2
  84. data/lib/nitro/helper/navigation.rb +87 -0
  85. data/lib/nitro/helper/pager.rb +11 -22
  86. data/lib/nitro/helper/table.rb +9 -32
  87. data/lib/nitro/helper/url.rb +104 -0
  88. data/lib/nitro/helper/xhtml.rb +20 -4
  89. data/lib/nitro/helper/xml.rb +0 -2
  90. data/lib/nitro/markup.rb +131 -0
  91. data/lib/nitro/part.rb +52 -7
  92. data/lib/nitro/publishable.rb +328 -0
  93. data/lib/nitro/render.rb +30 -61
  94. data/lib/nitro/router.rb +12 -4
  95. data/lib/nitro/sanitize.rb +48 -0
  96. data/lib/nitro/scaffold.rb +9 -11
  97. data/lib/nitro/scaffold/controller.rb +25 -0
  98. data/lib/nitro/scaffold/model.rb +150 -0
  99. data/lib/nitro/scaffolding.rb +1 -3
  100. data/lib/nitro/server.rb +57 -32
  101. data/lib/nitro/server/drb.rb +16 -2
  102. data/lib/nitro/server/runner.rb +80 -102
  103. data/lib/nitro/service.rb +0 -1
  104. data/lib/nitro/service/xmlrpc.rb +0 -2
  105. data/lib/nitro/session.rb +26 -18
  106. data/lib/nitro/session/drb.rb +2 -16
  107. data/lib/nitro/session/memory.rb +0 -2
  108. data/lib/nitro/template.rb +219 -0
  109. data/lib/nitro/test/assertions.rb +1 -3
  110. data/lib/nitro/test/context.rb +0 -1
  111. data/lib/nitro/test/testcase.rb +0 -1
  112. data/lib/nitro/version.rb +6 -0
  113. data/lib/part/admin.rb +16 -0
  114. data/lib/part/admin/controller.rb +19 -0
  115. data/lib/part/admin/helper.rb +30 -0
  116. data/lib/part/admin/og/controller.rb +114 -0
  117. data/lib/part/admin/og/customize.rb +4 -0
  118. data/lib/part/admin/og/template/index.xhtml +27 -0
  119. data/lib/part/admin/og/template/list.xhtml +38 -0
  120. data/lib/part/admin/og/template/search.xhtml +20 -0
  121. data/lib/part/admin/og/template/update.xhtml +25 -0
  122. data/lib/part/admin/skin.rb +207 -0
  123. data/lib/part/admin/template/denied.xhtml +13 -0
  124. data/lib/part/admin/template/index.xhtml +12 -0
  125. data/lib/part/admin/todo.txt +2 -0
  126. data/proto/public/error.xhtml +4 -2
  127. data/proto/run.rb +0 -2
  128. data/test/glue/tc_webfile.rb +1 -0
  129. data/test/nitro/cgi/tc_request.rb +23 -0
  130. data/test/nitro/helper/tc_feed.rb +0 -3
  131. data/test/nitro/helper/tc_navbar.rb +74 -0
  132. data/test/nitro/helper/tc_table.rb +2 -0
  133. data/test/nitro/tc_cgi.rb +72 -19
  134. data/test/nitro/tc_controller.rb +35 -26
  135. data/test/nitro/tc_controller_aspect.rb +1 -0
  136. data/test/nitro/tc_controller_params.rb +864 -0
  137. data/test/nitro/tc_dispatcher.rb +2 -2
  138. data/test/nitro/tc_element.rb +16 -16
  139. data/test/nitro/tc_flash.rb +3 -3
  140. data/test/nitro/tc_markup.rb +31 -0
  141. data/test/nitro/tc_render.rb +12 -14
  142. data/test/nitro/tc_session.rb +9 -7
  143. data/test/nitro/tc_template.rb +34 -0
  144. metadata +217 -198
  145. data/INSTALL +0 -121
  146. data/ProjectInfo +0 -74
  147. data/README +0 -555
  148. data/doc/apache.txt +0 -9
  149. data/doc/config.txt +0 -28
  150. data/doc/faq.txt +0 -7
  151. data/doc/lhttpd.txt +0 -7
  152. data/lib/nitro/adapter/scgi.rb +0 -239
  153. data/lib/nitro/helper/form/builder.rb +0 -144
  154. data/lib/nitro/helper/form/controls.rb +0 -389
  155. data/lib/nitro/helper/rss.rb +0 -72
  156. data/proto/conf/apache.conf +0 -51
  157. data/proto/public/scaffold/advanced_search.xhtml +0 -30
  158. data/proto/public/scaffold/edit.xhtml +0 -11
  159. data/proto/public/scaffold/form.xhtml +0 -1
  160. data/proto/public/scaffold/index.xhtml +0 -20
  161. data/proto/public/scaffold/list.xhtml +0 -32
  162. data/proto/public/scaffold/new.xhtml +0 -11
  163. data/proto/public/scaffold/search.xhtml +0 -29
  164. data/proto/public/scaffold/view.xhtml +0 -8
  165. data/proto/script/scgi_ctl +0 -221
  166. data/proto/script/scgi_service +0 -128
  167. data/setup.rb +0 -1585
  168. data/src/part/admin.rb +0 -16
  169. data/src/part/admin/controller.rb +0 -81
  170. data/src/part/admin/skin.rb +0 -21
  171. data/src/part/admin/system.css +0 -135
  172. data/src/part/admin/template/denied.xhtml +0 -1
  173. data/src/part/admin/template/index.xhtml +0 -43
  174. data/test/nitro/helper/tc_rss.rb +0 -24
@@ -8,7 +8,7 @@ module Nitro
8
8
  # Raised when an action can not be found for a path
9
9
  # check for this in your error action to catch as if 404
10
10
 
11
- class NoActionError < NoMethodError; end
11
+ class ActionError < NoMethodError; end
12
12
 
13
13
  # The Dispatcher manages a set of controllers. It maps
14
14
  # a request uri to a [controller, action] pair.
@@ -17,7 +17,11 @@ class Dispatcher
17
17
  include Router
18
18
 
19
19
  ROOT = '/'
20
+
21
+ # The server.
20
22
 
23
+ attr_accessor :server
24
+
21
25
  # The controllers map.
22
26
 
23
27
  attr_accessor :controllers
@@ -69,7 +73,7 @@ class Dispatcher
69
73
  end
70
74
 
71
75
  # Automatically mixin controller helpers.
72
-
76
+
73
77
  mixin_auto_helpers(klass)
74
78
 
75
79
  # Customize the class for mounting at the given path.
@@ -80,8 +84,12 @@ class Dispatcher
80
84
  # paths, plus simplifying the code. This instance will
81
85
  # be dup-ed for each request.
82
86
  #++
83
-
87
+
84
88
  klass.mount_at(path)
89
+
90
+ # Call the mounted callback to allow for post mount
91
+ # initialization.
92
+
85
93
  klass.mounted(path) if klass.respond_to?(:mounted)
86
94
  end
87
95
 
@@ -100,7 +108,9 @@ class Dispatcher
100
108
 
101
109
  def mixin_auto_helpers(klass)
102
110
  klass.helper(Nitro::DefaultHelper)
103
-
111
+
112
+ return # FIXME: make the following work again!
113
+
104
114
  begin
105
115
  if helper = Module.by_name("#{klass}Helper")
106
116
  klass.helper(helper)
@@ -128,7 +138,7 @@ class Dispatcher
128
138
  for m in c.action_methods
129
139
  m = m.to_sym
130
140
  if route = c.ann(m).route and (!route.nil?)
131
- add_rule(route.first, :controller => c, :action => m, :params => route.last)
141
+ add_rule(:match => route.first, :controller => c, :action => m, :params => route.last)
132
142
  end
133
143
  end
134
144
  end
@@ -136,7 +146,6 @@ class Dispatcher
136
146
 
137
147
  # Processes the path and dispatches to the corresponding
138
148
  # controller/action pair.
139
- # The base returned contains a trailing '/'.
140
149
  #
141
150
  # [+path+]
142
151
  # The path to dispatch.
@@ -149,9 +158,9 @@ class Dispatcher
149
158
  # Action containing '/' separators look for templates
150
159
  # in subdirectories. The '/' char is converted to '__'
151
160
  # to find the actual action.
161
+ # The dispatcher also handles nested controllers.
152
162
  #
153
- # Returns the dispatcher class, the action name and the
154
- # base url. For the root path, the base url is nil.
163
+ # Returns the dispatcher class and the action name.
155
164
  #--
156
165
  # FIXME: this is a critical method that should be optimized
157
166
  # watch out for excessive String creation.
@@ -163,33 +172,44 @@ class Dispatcher
163
172
 
164
173
  klass, action, params = decode_route(path)
165
174
  if klass
166
- context.params.update(params) if params
175
+ # This adds parameter values from the setup from the route to the normal
176
+ # query strings.
177
+ context.headers['QUERY_STRING'] ||= ''
178
+ extra = params.map { |k, v| "#{k}=#{v}"}.join(';') if params
179
+ if context.headers['QUERY_STRING'].empty?
180
+ context.headers['QUERY_STRING'] = extra
181
+ else
182
+ context.headers['QUERY_STRING'] << ';' << extra
183
+ end
184
+
185
+ context.headers['ACTION_PARAMS'] = params.values
186
+
187
+ # context.params.update(params) if params
167
188
  # gmosx, FIXME/OPTIMIZE: no annotation for mount point!!
168
189
  return klass, "#{action}_action", klass.mount_path
169
190
  end
170
-
171
- path = path.sub(/#{Router.strip_path}/, '') if Router.strip_path
172
- parts = path.split('/')
173
- parts.shift # get rid of the leading '/'.
174
191
 
175
- if klass = controller_class_for("/#{parts.first}")
176
- base = "/#{parts.shift}"
177
- else
178
- base = nil
179
- klass = controller_class_for(ROOT)
180
- end
192
+ key, * = path.split('?', 2)
193
+ key = key.split('/')
194
+ parts = []
195
+
196
+ while (not key.empty?) and (klass = controller_class_for("#{key.join('/')}")).nil?
197
+ parts.unshift(key.pop)
198
+ end
199
+
200
+ klass = controller_class_for(ROOT) unless klass
181
201
 
182
202
  idx = 0
183
203
  found = false
204
+
205
+ # gmosx, HACKFIX!
184
206
 
185
- # default to index
186
-
187
- parts << 'index' if parts.empty?
188
-
207
+ parts.shift if parts.first == ''
208
+
189
209
  # Try to find the first valid action substring
190
210
 
191
211
  action = ''
192
-
212
+
193
213
  for part in parts
194
214
  action << part
195
215
  if klass.respond_to_action_or_template?(action)
@@ -199,26 +219,47 @@ class Dispatcher
199
219
  action << '__'
200
220
  idx += 1
201
221
  end
222
+
223
+ # Check the index action.
224
+
225
+ unless found
226
+ action = :index
227
+ if klass.respond_to_action? action
228
+ a = klass.instance_method(action).arity
229
+ found = true if a < 0 || a >= parts.size
230
+ elsif klass.respond_to_template? action
231
+ found = true if parts.size == 0
232
+ end
233
+ idx = -1 if found
234
+ end
202
235
 
203
236
  if found
204
237
  parts.slice!(0, idx + 1)
238
+ =begin
239
+ if $DBG
240
+ # Some extra checking of the parameters. Only enabled
241
+ # on debug mode, because it slows down dispatching.
242
+
243
+ a = klass.instance_method(action).arity
244
+
245
+ if a > 0 and a != parts.size
246
+ raise ActionError, "Invalid parameters for action, expects #{a} parameters, received #{parts.size}"
247
+ end
248
+ end
249
+ =end
205
250
  else
206
251
  #--
207
252
  # FIXME: no raise to make testable.
208
253
  #++
209
- raise NoActionError, "No action for path '#{path}' on '#{klass}'"
254
+ raise ActionError, "No action for path '#{path}' on '#{klass}'"
210
255
  end
211
256
 
212
257
  # push any remaining parts of the url onto the query
213
258
  # string for use with request
214
259
 
215
- unless parts.empty?
216
- context.headers['QUERY_STRING'] = "#{parts.join(';')};#{context.headers['QUERY_STRING']}"
217
- end
260
+ context.headers['ACTION_PARAMS'] = parts
218
261
 
219
- base = nil if base == ROOT
220
-
221
- return klass, "#{action}_action", base
262
+ return klass, "#{action}_action"
222
263
  end
223
264
  alias_method :split_path, :dispatch
224
265
 
@@ -244,6 +285,3 @@ private
244
285
  end
245
286
 
246
287
  end
247
-
248
- # * George Moschovitis <gm@navel.gr>
249
- # * Chris Farmiloe <chris.farmiloe@farmiloe.com>
@@ -2,10 +2,9 @@ require 'facet/string/capitalized'
2
2
  require 'facet/string/camelize'
3
3
  require 'facet/class/method_name'
4
4
  require 'facet/dir/self/recurse'
5
- require 'facet/annotation'
6
5
 
7
6
  require 'glue/configuration'
8
- require 'glue/template'
7
+ require 'nitro/template'
9
8
 
10
9
  module Nitro
11
10
 
@@ -75,13 +74,41 @@ module ElementMixin
75
74
  # the content of the named child element.
76
75
  #
77
76
  # eg. #{content :child_element_id}
77
+ #
78
+ # === Example
79
+ #
80
+ # <Page>
81
+ # ..
82
+ #
83
+ # <Box id="hello">
84
+ # ..
85
+ # </Box>
86
+ #
87
+ # <Box id="world">
88
+ # ..
89
+ # </Box>
90
+ #
91
+ # <Sidebar>
92
+ # ..
93
+ # </Sidebar>
94
+ #
95
+ # ..
96
+ #
97
+ # </Page>
98
+ #
99
+ # Access children content from within the enclosing element
100
+ # (Page) like this:
101
+ #
102
+ # {content :hello}
103
+ # {content :world}
104
+ # {content :sidebar}
78
105
 
79
106
  def content(cname = nil)
80
107
  if cname
81
108
  if c = @_children[cname.to_s]
82
109
  c.content
83
110
  else
84
- Logger.error "Undefined sub-element '#{cname}' for element '#{self.class}'"
111
+ return nil
85
112
  end
86
113
  else
87
114
  @_text
@@ -110,10 +137,11 @@ module ElementMixin
110
137
 
111
138
  def add_child(child)
112
139
  child._parent = self
113
- @_children[child.id] = child
140
+ @_children[child.instance_variable_get('@id')] = child
114
141
  end
115
142
 
116
143
  alias_method :children, :_children
144
+
117
145
  end
118
146
 
119
147
  # A programmatically generated element.
@@ -167,10 +195,10 @@ class Element
167
195
  setting :auto_extend, :default => true, :doc => 'Allow auto extension of element classes?'
168
196
 
169
197
  # The directory where element templates reside. The default
170
- # dir is #{Glue::Template.root}/element
198
+ # dir is #{Nitro::Template.root}/element
171
199
 
172
- if File.exist?(File.join(Glue::Template.root, 'element'))
173
- default_root = File.join(Glue::Template.root, 'element')
200
+ if File.exist?(File.join(Nitro::Template.root, 'element'))
201
+ default_root = File.join(Nitro::Template.root, 'element')
174
202
  else
175
203
  default_root = 'element'
176
204
  end
@@ -193,7 +221,7 @@ class Element
193
221
  def compile_template_elements
194
222
  if File.exist? Element.template_root
195
223
  Dir.recurse(Element.template_root) do |filename|
196
- if filename =~ /\.#{Glue::Template.extension}$/
224
+ if filename =~ /\.#{Nitro::Template.extension}$/
197
225
  name = File.basename(filename).split('.').first.camelize
198
226
  Nitro::Element.module_eval %{
199
227
  class #{name} < Nitro::Element
@@ -217,5 +245,3 @@ end
217
245
  Element.compile_template_elements
218
246
 
219
247
  end
220
-
221
- # * George Moschovitis <gm@navel.gr>
@@ -17,5 +17,3 @@ class Javascript
17
17
  end
18
18
 
19
19
  end
20
-
21
- # * George Moschovitis <gm@navel.gr>
@@ -19,7 +19,10 @@ module Nitro
19
19
  #
20
20
  # You may want to use the Flash to pass error messages or
21
21
  # other short lived objects.
22
-
22
+ #
23
+ # Use capitalized keys to denote system variables. Reserve
24
+ # lower case keys for user application variables.
25
+
23
26
  class Flash < Hash
24
27
 
25
28
  def initialize
@@ -65,17 +68,20 @@ module Nitro
65
68
  #
66
69
  # === Example
67
70
  #
68
- # flash.push :errors, 'This is the first error'
69
- # flash.push :errors, 'This is the second error'
71
+ # flash.push :ERRORS, 'This is the first error'
72
+ # flash.push :ERRORS, 'This is the second error'
70
73
  #
71
- # flash[:errors] # => []
74
+ # flash[:ERRORS] # => []
72
75
 
73
- def push(key, value)
74
- if value.is_a? Array
75
- (self[key] ||= []).concat(value)
76
+ def push(key, *values)
77
+ val = self[key]
78
+ val ||= []
79
+ if values.size == 1
80
+ val << values[0]
76
81
  else
77
- (self[key] ||= []) << value
82
+ val << values
78
83
  end
84
+ self[key] = val
79
85
  end
80
86
 
81
87
  # Pop a value from an array flash variable.
@@ -91,6 +97,15 @@ module Nitro
91
97
  return nil
92
98
  end
93
99
 
100
+ # Another helper, concats a whole array to the given flash
101
+ # key.
102
+
103
+ def concat(key, arr)
104
+ for val in arr.to_a
105
+ push key, val
106
+ end
107
+ end
108
+
94
109
  # Join helper
95
110
 
96
111
  def join(key, sep = ', ')
@@ -148,5 +163,3 @@ module Nitro
148
163
  end
149
164
 
150
165
  end
151
-
152
- # * George Moschovitis <gm@navel.gr>
@@ -1,22 +1,49 @@
1
- require 'glue/cache/memory'
2
-
3
1
  # Global scoped variables. This is backed by a Cache store.
2
+ #--
3
+ # TODO: implement as a refactoring of session?
4
+ #++
4
5
 
5
6
  class Global
6
7
 
8
+ # The type of the global cache. The generalized caching
9
+ # system in Glue is used. The following options are available:
10
+ #
11
+ # * :memory [default]
12
+ # * :drb
13
+ # * :og
14
+ # * :file
15
+ # * :memcached
16
+
17
+ setting :cache_type, :default => :memory, :doc => 'The type of global cache'
18
+
7
19
  # The address of the store.
8
20
 
9
- setting :cache_address, :default => '127.0.0.1', :doc => 'The address of the store'
21
+ setting :cache_address, :default => '127.0.0.1', :doc => 'The address of the global cache'
10
22
 
11
23
  # The port of the store.
12
24
 
13
- setting :cache_port, :default => 9079, :doc => 'The port of the store'
14
-
15
- # The cache store that backs global variables.
16
-
17
- setting :cache, :default => ::Glue::MemoryCache.new, :doc => 'The cache store that backs global variables'
25
+ setting :cache_port, :default => 9079, :doc => 'The port of the global cache'
18
26
 
19
27
  class << self
28
+ # The global cache (store).
29
+
30
+ attr_accessor :cache
31
+
32
+ # Init the correct Global cache.
33
+
34
+ def setup(type = Global.cache_type)
35
+ return if Global.cache
36
+
37
+ case type
38
+ when :memory
39
+ require 'glue/cache/memory'
40
+ Global.cache = Glue::MemoryCache.new
41
+
42
+ when :drb
43
+ require 'glue/cache/drb'
44
+ Global.cache = DrbCache.new(Global.cache_address, Global.cache_port)
45
+ end
46
+ end
20
47
 
21
48
  # Initialize a global value once.
22
49
 
@@ -42,7 +69,7 @@ class Global
42
69
  # Global.update(:USERS) do |users|
43
70
  # users << 'gmosx'
44
71
  # end
45
-
72
+
46
73
  def update(key)
47
74
  if block_given?
48
75
  # update, also handles distributed stores.
@@ -59,5 +86,3 @@ class Global
59
86
  end
60
87
 
61
88
  end
62
-
63
- # * George Moschovitis <gm@navel.gr>
@@ -36,27 +36,43 @@ module Helpers
36
36
  base.module_eval do
37
37
  def self.helper(*modules)
38
38
  for mod in modules
39
+
40
+ # If the mod is a string or symbol, also try to
41
+ # auto require the source file.
39
42
  #--
40
43
  # gmosx, FIXME: temp solution, will fix!
41
44
  #++
42
45
 
43
- if mod.is_a? String
46
+ if mod.is_a?(String) or mod.is_a?(Symbol)
44
47
  begin
45
48
  # gmosx: dont interpolate (RDoc fix).
46
- require('src/helper/' + mod)
47
- rescue Object
48
- require('nitro/helper/' + mod) rescue nil
49
+ require('src/helper/' + mod.to_s)
50
+ rescue LoadError #do not hide SyntaxError, NameError
51
+
52
+ # you can do helper "foo" to load a module withouth requiring
53
+ begin
54
+ require('nitro/helper/' + mod.to_s)
55
+ rescue LoadError
56
+ # supress this error.
57
+ end
49
58
  end
50
59
  end
51
60
 
52
61
  unless mod.is_a? Module
53
- mod = mod.to_s.camelize
62
+ modname = mod.to_s.camelize
54
63
  # gmosx: check xxxHelper before xxx.
55
- mod = Utils.const("#{mod}Helper") || Utils.const("Nitro::#{mod}Helper") || Utils.const(mod)
64
+ mod = Utils.const("#{modname}Helper") ||
65
+ Utils.const("Nitro::#{modname}Helper") ||
66
+ Utils.const(modname)
67
+ end
68
+ # name mismatch
69
+ unless mod
70
+ raise "helper #{modname} not found (module not defined), check name"
56
71
  end
57
72
  symbols = mod.instance_methods.collect { |m| m.to_sym }
58
73
  self.send(:include, mod)
59
74
  self.send(:private, *symbols)
75
+ self.send(:private, mod.to_s[/[^:]+$/].to_sym)
60
76
  end
61
77
  end
62
78
  end
@@ -65,5 +81,3 @@ module Helpers
65
81
  end
66
82
 
67
83
  end
68
-
69
- # * George Moschovitis <gm@navel.gr>