nitro 0.31.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nitro +135 -37
- data/doc/CHANGELOG.1 +108 -108
- data/doc/CHANGELOG.2 +89 -89
- data/doc/CHANGELOG.3 +105 -105
- data/{CHANGELOG → doc/CHANGELOG.4} +509 -509
- data/doc/{AUTHORS → CONTRIBUTORS} +49 -37
- data/doc/LIBRARIES +13 -0
- data/doc/LICENSE +2 -3
- data/doc/MIGRATION +45 -0
- data/doc/RELEASES +131 -11
- data/doc/TODO +67 -0
- data/lib/glue/magick.rb +0 -3
- data/lib/glue/sweeper.rb +30 -15
- data/lib/glue/thumbnails.rb +0 -2
- data/lib/glue/webfile.rb +23 -11
- data/lib/nitro.rb +37 -44
- data/lib/nitro/adapter/cgi.rb +0 -3
- data/lib/nitro/adapter/console.rb +0 -2
- data/lib/nitro/adapter/fastcgi.rb +6 -3
- data/lib/nitro/adapter/mongrel.rb +97 -58
- data/lib/nitro/adapter/script.rb +4 -6
- data/lib/nitro/adapter/webrick.rb +33 -87
- data/lib/nitro/adapter/webrick/vcr.rb +85 -0
- data/lib/nitro/caching.rb +0 -2
- data/lib/nitro/caching/actions.rb +0 -2
- data/lib/nitro/caching/fragments.rb +0 -2
- data/lib/nitro/caching/output.rb +45 -16
- data/lib/nitro/caching/proxy.rb +49 -0
- data/lib/nitro/cgi.rb +3 -6
- data/lib/nitro/cgi/cookie.rb +0 -3
- data/lib/nitro/cgi/request.rb +67 -24
- data/lib/nitro/cgi/response.rb +0 -2
- data/lib/nitro/cgi/{sendfile.rb → send_file.rb} +7 -6
- data/lib/nitro/compiler.rb +62 -55
- data/lib/nitro/compiler/cleanup.rb +0 -3
- data/lib/nitro/compiler/elements.rb +31 -28
- data/lib/nitro/compiler/errors.rb +2 -5
- data/lib/nitro/compiler/include.rb +10 -8
- data/lib/nitro/compiler/layout.rb +0 -2
- data/lib/nitro/compiler/localization.rb +0 -2
- data/lib/nitro/compiler/markup.rb +14 -6
- data/lib/nitro/compiler/morphing.rb +1 -5
- data/lib/nitro/compiler/script.rb +2 -4
- data/lib/nitro/compiler/squeeze.rb +0 -2
- data/lib/nitro/compiler/xslt.rb +0 -2
- data/lib/nitro/context.rb +10 -5
- data/lib/nitro/control.rb +18 -0
- data/lib/nitro/control/attribute.rb +88 -0
- data/lib/nitro/control/attribute/checkbox.rb +19 -0
- data/lib/nitro/control/attribute/datetime.rb +21 -0
- data/lib/nitro/control/attribute/file.rb +20 -0
- data/lib/nitro/control/attribute/fixnum.rb +26 -0
- data/lib/nitro/control/attribute/float.rb +26 -0
- data/lib/nitro/control/attribute/options.rb +38 -0
- data/lib/nitro/control/attribute/password.rb +16 -0
- data/lib/nitro/control/attribute/text.rb +16 -0
- data/lib/nitro/control/attribute/textarea.rb +16 -0
- data/lib/nitro/control/none.rb +16 -0
- data/lib/nitro/control/relation.rb +53 -0
- data/lib/nitro/control/relation/belongs_to.rb +0 -0
- data/lib/nitro/control/relation/has_many.rb +97 -0
- data/lib/nitro/control/relation/joins_many.rb +0 -0
- data/lib/nitro/control/relation/many_to_many.rb +0 -0
- data/lib/nitro/control/relation/refers_to.rb +29 -0
- data/lib/nitro/controller.rb +7 -296
- data/lib/nitro/dispatcher.rb +72 -34
- data/lib/nitro/element.rb +36 -10
- data/lib/nitro/element/javascript.rb +0 -2
- data/lib/nitro/flash.rb +23 -10
- data/lib/nitro/global.rb +36 -11
- data/lib/nitro/helper.rb +22 -8
- data/lib/nitro/helper/benchmark.rb +0 -2
- data/lib/nitro/helper/buffer.rb +0 -3
- data/lib/nitro/helper/css.rb +12 -0
- data/lib/nitro/helper/debug.rb +1 -3
- data/lib/nitro/helper/default.rb +1 -0
- data/lib/nitro/helper/feed.rb +400 -386
- data/lib/nitro/helper/form.rb +246 -116
- data/lib/nitro/helper/javascript.rb +28 -2
- data/lib/nitro/helper/javascript/morphing.rb +0 -2
- data/lib/nitro/helper/javascript/prototype.rb +0 -2
- data/lib/nitro/helper/javascript/scriptaculous.rb +0 -1
- data/lib/nitro/helper/layout.rb +0 -2
- data/lib/nitro/helper/navigation.rb +87 -0
- data/lib/nitro/helper/pager.rb +11 -22
- data/lib/nitro/helper/table.rb +9 -32
- data/lib/nitro/helper/url.rb +104 -0
- data/lib/nitro/helper/xhtml.rb +20 -4
- data/lib/nitro/helper/xml.rb +0 -2
- data/lib/nitro/markup.rb +131 -0
- data/lib/nitro/part.rb +52 -7
- data/lib/nitro/publishable.rb +328 -0
- data/lib/nitro/render.rb +30 -61
- data/lib/nitro/router.rb +12 -4
- data/lib/nitro/sanitize.rb +48 -0
- data/lib/nitro/scaffold.rb +9 -11
- data/lib/nitro/scaffold/controller.rb +25 -0
- data/lib/nitro/scaffold/model.rb +150 -0
- data/lib/nitro/scaffolding.rb +1 -3
- data/lib/nitro/server.rb +57 -32
- data/lib/nitro/server/drb.rb +16 -2
- data/lib/nitro/server/runner.rb +80 -102
- data/lib/nitro/service.rb +0 -1
- data/lib/nitro/service/xmlrpc.rb +0 -2
- data/lib/nitro/session.rb +26 -18
- data/lib/nitro/session/drb.rb +2 -16
- data/lib/nitro/session/memory.rb +0 -2
- data/lib/nitro/template.rb +219 -0
- data/lib/nitro/test/assertions.rb +1 -3
- data/lib/nitro/test/context.rb +0 -1
- data/lib/nitro/test/testcase.rb +0 -1
- data/lib/nitro/version.rb +6 -0
- data/lib/part/admin.rb +16 -0
- data/lib/part/admin/controller.rb +19 -0
- data/lib/part/admin/helper.rb +30 -0
- data/lib/part/admin/og/controller.rb +114 -0
- data/lib/part/admin/og/customize.rb +4 -0
- data/lib/part/admin/og/template/index.xhtml +27 -0
- data/lib/part/admin/og/template/list.xhtml +38 -0
- data/lib/part/admin/og/template/search.xhtml +20 -0
- data/lib/part/admin/og/template/update.xhtml +25 -0
- data/lib/part/admin/skin.rb +207 -0
- data/lib/part/admin/template/denied.xhtml +13 -0
- data/lib/part/admin/template/index.xhtml +12 -0
- data/lib/part/admin/todo.txt +2 -0
- data/proto/public/error.xhtml +4 -2
- data/proto/run.rb +0 -2
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/cgi/tc_request.rb +23 -0
- data/test/nitro/helper/tc_feed.rb +0 -3
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_table.rb +2 -0
- data/test/nitro/tc_cgi.rb +72 -19
- data/test/nitro/tc_controller.rb +35 -26
- data/test/nitro/tc_controller_aspect.rb +1 -0
- data/test/nitro/tc_controller_params.rb +864 -0
- data/test/nitro/tc_dispatcher.rb +2 -2
- data/test/nitro/tc_element.rb +16 -16
- data/test/nitro/tc_flash.rb +3 -3
- data/test/nitro/tc_markup.rb +31 -0
- data/test/nitro/tc_render.rb +12 -14
- data/test/nitro/tc_session.rb +9 -7
- data/test/nitro/tc_template.rb +34 -0
- metadata +217 -198
- data/INSTALL +0 -121
- data/ProjectInfo +0 -74
- data/README +0 -555
- data/doc/apache.txt +0 -9
- data/doc/config.txt +0 -28
- data/doc/faq.txt +0 -7
- data/doc/lhttpd.txt +0 -7
- data/lib/nitro/adapter/scgi.rb +0 -239
- data/lib/nitro/helper/form/builder.rb +0 -144
- data/lib/nitro/helper/form/controls.rb +0 -389
- data/lib/nitro/helper/rss.rb +0 -72
- data/proto/conf/apache.conf +0 -51
- data/proto/public/scaffold/advanced_search.xhtml +0 -30
- data/proto/public/scaffold/edit.xhtml +0 -11
- data/proto/public/scaffold/form.xhtml +0 -1
- data/proto/public/scaffold/index.xhtml +0 -20
- data/proto/public/scaffold/list.xhtml +0 -32
- data/proto/public/scaffold/new.xhtml +0 -11
- data/proto/public/scaffold/search.xhtml +0 -29
- data/proto/public/scaffold/view.xhtml +0 -8
- data/proto/script/scgi_ctl +0 -221
- data/proto/script/scgi_service +0 -128
- data/setup.rb +0 -1585
- data/src/part/admin.rb +0 -16
- data/src/part/admin/controller.rb +0 -81
- data/src/part/admin/skin.rb +0 -21
- data/src/part/admin/system.css +0 -135
- data/src/part/admin/template/denied.xhtml +0 -1
- data/src/part/admin/template/index.xhtml +0 -43
- data/test/nitro/helper/tc_rss.rb +0 -24
data/lib/nitro/dispatcher.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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
|
-
|
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
|
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
|
-
|
216
|
-
context.headers['QUERY_STRING'] = "#{parts.join(';')};#{context.headers['QUERY_STRING']}"
|
217
|
-
end
|
260
|
+
context.headers['ACTION_PARAMS'] = parts
|
218
261
|
|
219
|
-
|
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>
|
data/lib/nitro/element.rb
CHANGED
@@ -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 '
|
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
|
-
|
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 #{
|
198
|
+
# dir is #{Nitro::Template.root}/element
|
171
199
|
|
172
|
-
if File.exist?(File.join(
|
173
|
-
default_root = File.join(
|
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 =~ /\.#{
|
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>
|
data/lib/nitro/flash.rb
CHANGED
@@ -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 :
|
69
|
-
# flash.push :
|
71
|
+
# flash.push :ERRORS, 'This is the first error'
|
72
|
+
# flash.push :ERRORS, 'This is the second error'
|
70
73
|
#
|
71
|
-
# flash[:
|
74
|
+
# flash[:ERRORS] # => []
|
72
75
|
|
73
|
-
def push(key,
|
74
|
-
|
75
|
-
|
76
|
+
def push(key, *values)
|
77
|
+
val = self[key]
|
78
|
+
val ||= []
|
79
|
+
if values.size == 1
|
80
|
+
val << values[0]
|
76
81
|
else
|
77
|
-
|
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>
|
data/lib/nitro/global.rb
CHANGED
@@ -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
|
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
|
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>
|
data/lib/nitro/helper.rb
CHANGED
@@ -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?
|
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
|
48
|
-
|
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
|
-
|
62
|
+
modname = mod.to_s.camelize
|
54
63
|
# gmosx: check xxxHelper before xxx.
|
55
|
-
mod = Utils.const("#{
|
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>
|