nitro 0.8.0 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -4
- data/ChangeLog +418 -0
- data/LICENSE +1 -1
- data/README +157 -89
- data/RELEASES +50 -0
- data/Rakefile +5 -7
- data/benchmark/nitro/bench.rb +5 -0
- data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
- data/benchmark/nitro/static-webrick-n-200.txt +43 -0
- data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
- data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
- data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
- data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
- data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
- data/bin/proto/README +2 -2
- data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
- data/bin/proto/conf/app.conf.rb +22 -0
- data/bin/proto/conf/lhttpd.conf +236 -0
- data/bin/proto/ctl +4 -0
- data/bin/proto/lib/README +5 -0
- data/bin/proto/log/README +3 -0
- data/bin/proto/root/fcgi.rb +6 -0
- data/bin/proto/root/index.xhtml +65 -7
- data/bin/proto/root/m/nitro.png +0 -0
- data/examples/blog/README +7 -5
- data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
- data/examples/blog/conf/app.conf.rb +56 -0
- data/examples/blog/conf/lhttpd.conf +236 -0
- data/examples/blog/ctl +4 -0
- data/examples/blog/lib/blog.rb +11 -136
- data/examples/blog/lib/blog/controller.rb +99 -0
- data/examples/blog/lib/blog/model.rb +39 -0
- data/examples/blog/log/README +3 -0
- data/examples/blog/root/comments.xhtml +2 -2
- data/examples/blog/root/fcgi.rb +6 -0
- data/examples/blog/root/index.xhtml +4 -5
- data/examples/blog/root/login.xhtml +2 -2
- data/examples/blog/root/style.xsl +9 -9
- data/examples/blog/root/view_entry.xhtml +2 -2
- data/examples/flash/conf/app.conf.rb +23 -0
- data/examples/flash/ctl +4 -0
- data/examples/flash/log/README +3 -0
- data/examples/flash/root/index.xhtml +0 -9
- data/examples/flash/root/show_inline_text.xhtml +10 -5
- data/examples/no_xsl_blog/README +12 -0
- data/examples/no_xsl_blog/conf/apache.conf +0 -0
- data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
- data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
- data/examples/no_xsl_blog/ctl +4 -0
- data/examples/no_xsl_blog/lib/blog.rb +20 -0
- data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
- data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
- data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
- data/examples/no_xsl_blog/log/README +3 -0
- data/examples/no_xsl_blog/root/comments.xhtml +41 -0
- data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
- data/examples/no_xsl_blog/root/fcgi.rb +6 -0
- data/examples/no_xsl_blog/root/index.xhtml +39 -0
- data/examples/no_xsl_blog/root/login.xhtml +21 -0
- data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
- data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
- data/examples/no_xsl_blog/root/m/down.gif +0 -0
- data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
- data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
- data/examples/no_xsl_blog/root/m/obull.gif +0 -0
- data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/rss.gif +0 -0
- data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
- data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
- data/examples/no_xsl_blog/root/style.css +301 -0
- data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
- data/examples/no_xsl_blog/root/view_entry.xml +12 -0
- data/examples/og/run.rb +2 -2
- data/examples/tiny/README +2 -2
- data/examples/tiny/conf/apache.conf +5 -0
- data/examples/tiny/conf/app.conf.rb +21 -0
- data/examples/tiny/conf/lhttpd.conf +236 -0
- data/examples/tiny/ctl +4 -0
- data/examples/tiny/log/README +3 -0
- data/examples/tiny/root/fcgi.rb +6 -0
- data/examples/tiny/root/index.xhtml +7 -4
- data/examples/tiny/root/nitro.png +0 -0
- data/lib/glue.rb +13 -9
- data/lib/glue/array.rb +1 -1
- data/lib/glue/cache.rb +1 -1
- data/lib/glue/flexob.rb +12 -0
- data/lib/glue/hash.rb +1 -1
- data/lib/glue/inflector.rb +2 -2
- data/lib/glue/logger.rb +4 -8
- data/lib/glue/misc.rb +14 -0
- data/lib/glue/number.rb +1 -1
- data/lib/glue/object.rb +26 -0
- data/lib/glue/pool.rb +1 -1
- data/lib/glue/property.rb +84 -91
- data/lib/glue/string.rb +1 -1
- data/lib/glue/time.rb +1 -1
- data/lib/glue/validation.rb +1 -1
- data/lib/nitro.rb +18 -6
- data/lib/nitro/adaptors/cgi.rb +291 -0
- data/lib/nitro/adaptors/fastcgi.rb +42 -0
- data/lib/nitro/adaptors/runner.rb +123 -0
- data/lib/nitro/adaptors/webrick.rb +110 -0
- data/lib/nitro/buffering.rb +43 -0
- data/lib/nitro/builders/form.rb +1 -1
- data/lib/nitro/builders/rss.rb +1 -1
- data/{bin → lib/nitro}/cluster.rb +26 -30
- data/lib/nitro/context.rb +82 -0
- data/lib/nitro/controller.rb +50 -0
- data/lib/nitro/cookie.rb +46 -0
- data/lib/nitro/dispatcher.rb +105 -0
- data/lib/nitro/filters.rb +9 -10
- data/lib/nitro/localization.rb +42 -0
- data/lib/nitro/mail.rb +11 -14
- data/lib/nitro/render.rb +275 -0
- data/lib/nitro/request.rb +128 -0
- data/lib/nitro/response.rb +38 -0
- data/lib/nitro/scaffold.rb +11 -11
- data/lib/nitro/session.rb +84 -0
- data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
- data/lib/nitro/ui/pager.rb +23 -26
- data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
- data/lib/nitro/uri.rb +1 -1
- data/lib/nitro/version.rb +10 -8
- data/lib/og.rb +66 -65
- data/lib/og/backend.rb +1 -1
- data/lib/og/backends/mysql.rb +48 -52
- data/lib/og/backends/psql.rb +34 -37
- data/lib/og/connection.rb +15 -15
- data/lib/og/enchant.rb +16 -9
- data/lib/og/meta.rb +127 -54
- data/lib/og/mock.rb +18 -18
- data/lib/og/version.rb +6 -4
- data/lib/parts/content.rb +4 -8
- data/test/glue/tc_logger.rb +3 -0
- data/test/glue/tc_property.rb +19 -3
- data/test/nitro/adaptors/tc_cgi.rb +63 -0
- data/test/nitro/adaptors/tc_webrick.rb +15 -0
- data/test/nitro/builders/tc_xml.rb +2 -2
- data/test/nitro/tc_context.rb +13 -0
- data/test/nitro/tc_controller.rb +47 -0
- data/test/nitro/tc_dispatcher.rb +64 -0
- data/test/nitro/tc_session.rb +20 -0
- data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
- data/test/root/blog/list.xhtml +6 -0
- data/test/tc_og.rb +41 -4
- metadata +115 -59
- data/bin/proto/app.rb +0 -20
- data/bin/proto/config.rb +0 -77
- data/examples/blog/app.rb +0 -21
- data/examples/blog/config.rb +0 -95
- data/examples/blog/env.rb +0 -22
- data/examples/flash/README +0 -34
- data/examples/flash/app.rb +0 -20
- data/examples/flash/config.rb +0 -38
- data/examples/flash/lib/flash.rb +0 -40
- data/examples/flash/tmp.swf +0 -0
- data/examples/tiny/app.rb +0 -19
- data/examples/tiny/config.rb +0 -29
- data/examples/tiny/root/nitro-small.png +0 -0
- data/lib/nitro/application.rb +0 -217
- data/lib/nitro/config.rb +0 -128
- data/lib/nitro/events.rb +0 -122
- data/lib/nitro/html.rb +0 -151
- data/lib/nitro/http.rb +0 -102
- data/lib/nitro/l10n.rb +0 -30
- data/lib/nitro/server.rb +0 -59
- data/lib/nitro/server/appserver.rb +0 -67
- data/lib/nitro/server/cookie.rb +0 -87
- data/lib/nitro/server/dispatcher.rb +0 -62
- data/lib/nitro/server/filters.rb +0 -75
- data/lib/nitro/server/filters/autologin.rb +0 -51
- data/lib/nitro/server/fragment.rb +0 -70
- data/lib/nitro/server/handlers.rb +0 -127
- data/lib/nitro/server/render.rb +0 -426
- data/lib/nitro/server/request.rb +0 -658
- data/lib/nitro/server/requestpart.rb +0 -54
- data/lib/nitro/server/script.rb +0 -387
- data/lib/nitro/server/server.rb +0 -57
- data/lib/nitro/server/session.rb +0 -220
- data/lib/nitro/server/user.rb +0 -46
- data/lib/nitro/server/webrick.rb +0 -180
- data/lib/nitro/service.rb +0 -26
- data/lib/xsl/ui.xsl +0 -51
- data/lib/xsl/xforms.xsl +0 -28
- data/test/nitro/server/tc_cookie.rb +0 -34
- data/test/nitro/server/tc_filters.rb +0 -38
- data/test/nitro/server/tc_request.rb +0 -70
- data/test/nitro/server/tc_requestpart.rb +0 -28
- data/test/nitro/server/tc_session.rb +0 -34
- data/test/nitro/tc_events.rb +0 -44
- data/test/nitro/tc_html.rb +0 -79
- data/test/nitro/tc_http.rb +0 -18
@@ -1,54 +0,0 @@
|
|
1
|
-
# code:
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
3
|
-
#
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: requestpart.rb 167 2004-11-23 14:03:10Z gmosx $
|
6
|
-
|
7
|
-
require "cgi"
|
8
|
-
require "ftools"
|
9
|
-
|
10
|
-
require "glue/string"
|
11
|
-
require "nitro/uri"
|
12
|
-
require "nitro/http"
|
13
|
-
require "nitro/server/cookie"
|
14
|
-
|
15
|
-
module N
|
16
|
-
|
17
|
-
# RequestPart
|
18
|
-
#
|
19
|
-
# This class encapsulates a part in a multipart request.
|
20
|
-
# A part is typically an uploaded files.
|
21
|
-
#
|
22
|
-
class RequestPart
|
23
|
-
# the filename of the part
|
24
|
-
attr_accessor :filename
|
25
|
-
|
26
|
-
# the original filename path
|
27
|
-
attr_accessor :original_path
|
28
|
-
|
29
|
-
# the temp filename path
|
30
|
-
attr_accessor :body
|
31
|
-
|
32
|
-
# the content-type
|
33
|
-
attr_accessor :content_type
|
34
|
-
|
35
|
-
def initialize(original_path, body, content_type = nil)
|
36
|
-
@original_path = original_path
|
37
|
-
@body = body
|
38
|
-
@content_type = content_type
|
39
|
-
# handle dos + unix separators.
|
40
|
-
@filename = @original_path.split(/\/|\\/).last
|
41
|
-
end
|
42
|
-
|
43
|
-
# gmosx:
|
44
|
-
# Hack fixed save for webrick!
|
45
|
-
#
|
46
|
-
def save(prefix, forced_filename = nil, forced_extension = nil)
|
47
|
-
::FileUtils.mkdir_p(prefix)
|
48
|
-
save_path = "#{prefix}/#{@filename}"
|
49
|
-
::File.open(save_path, "wb") {|f| f.write @body }
|
50
|
-
return save_path
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end # module
|
data/lib/nitro/server/script.rb
DELETED
@@ -1,387 +0,0 @@
|
|
1
|
-
# code:
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
3
|
-
#
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: script.rb 167 2004-11-23 14:03:10Z gmosx $
|
6
|
-
|
7
|
-
require "fileutils"
|
8
|
-
|
9
|
-
require "glue/cache"
|
10
|
-
require "nitro/server/fragment"
|
11
|
-
|
12
|
-
module N
|
13
|
-
|
14
|
-
# = ScriptExitException
|
15
|
-
#
|
16
|
-
# Raise this Exception in your Script to avoid processing.
|
17
|
-
# Typicaly used in request.redirect scenarios!
|
18
|
-
#
|
19
|
-
class ScriptExitException < Exception; end
|
20
|
-
|
21
|
-
end # module
|
22
|
-
|
23
|
-
module N
|
24
|
-
|
25
|
-
# = Script
|
26
|
-
#
|
27
|
-
# Base class for scripts. Typically a handler evaluates a script.
|
28
|
-
# The base class describing a script is defined here.
|
29
|
-
# A generalized fragment caching system is also defined.
|
30
|
-
#
|
31
|
-
# see handlers/page-handler::PageScript for more information.
|
32
|
-
#--
|
33
|
-
# no need to prepend __ to the attributes! (@ is prepended)
|
34
|
-
#++
|
35
|
-
#
|
36
|
-
class Script
|
37
|
-
# gmosx: it would be a good idea to make this a singleton, but we
|
38
|
-
# had some problems when redefining the class when monitor_scripts
|
39
|
-
# is enabled. investigate this!
|
40
|
-
# include Singleton
|
41
|
-
|
42
|
-
# the full path to the actual script file
|
43
|
-
attr_accessor :path
|
44
|
-
|
45
|
-
# the sub scripts.
|
46
|
-
attr_accessor :sub_scripts
|
47
|
-
|
48
|
-
attr_accessor :key
|
49
|
-
|
50
|
-
# is this script cacheable? NONE, SERVER, DOWNSTREAM, CLIENT
|
51
|
-
attr_accessor :cacheability
|
52
|
-
|
53
|
-
def initialize(path)
|
54
|
-
@path = "#$root_dir/#{path}"
|
55
|
-
|
56
|
-
# gmosx, INVESTIGATE: createtime == filemtime ?
|
57
|
-
|
58
|
-
# the creation time for this script-class
|
59
|
-
@create_time = Time.now
|
60
|
-
|
61
|
-
# when the filename was last modified
|
62
|
-
@file_mtime = File.mtime(@path).to_i
|
63
|
-
|
64
|
-
# sub-scripts set: a set of files this script depends on.
|
65
|
-
# We use a hash to implement a set.
|
66
|
-
@sub_scripts = N::SafeArray.new
|
67
|
-
|
68
|
-
# a cache for the script outputs (fragments). Keeps multiple revisions
|
69
|
-
# of the script output according to user, access rights etc.
|
70
|
-
# must be thread safe because it is shared accross threads.
|
71
|
-
#
|
72
|
-
# gmosx: DONT DEPRECATE THIS! if we switch to FastCGI, perhaps
|
73
|
-
# this will be needed!
|
74
|
-
#
|
75
|
-
# DISK CACHING IS SLOW!
|
76
|
-
#
|
77
|
-
@fragment_cache = N::LRUCache.new(1000)
|
78
|
-
|
79
|
-
__init()
|
80
|
-
end
|
81
|
-
|
82
|
-
# This method is called at compile time to perform
|
83
|
-
# additional initialization.
|
84
|
-
#
|
85
|
-
def __init
|
86
|
-
end
|
87
|
-
|
88
|
-
# This method is called before rendering to perform
|
89
|
-
# additional initialization.
|
90
|
-
#
|
91
|
-
def __init_render(request)
|
92
|
-
# nop
|
93
|
-
end
|
94
|
-
|
95
|
-
# Tag for this request
|
96
|
-
#
|
97
|
-
def __tag(request)
|
98
|
-
# gmosx: dont return nil!
|
99
|
-
return ""
|
100
|
-
end
|
101
|
-
|
102
|
-
# Recursively calculate tag.
|
103
|
-
#
|
104
|
-
def __calc_tag(request)
|
105
|
-
tag = __tag(request)
|
106
|
-
|
107
|
-
if @sub_scripts
|
108
|
-
for script in @sub_scripts
|
109
|
-
tag << script.__calc_tag(request)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
return tag
|
114
|
-
end
|
115
|
-
|
116
|
-
# Calculate LastModified for HTTP1.1 caching
|
117
|
-
# Return the last modified time for this script.
|
118
|
-
#
|
119
|
-
def __lm(request)
|
120
|
-
return nil
|
121
|
-
end
|
122
|
-
|
123
|
-
# Calculate LastModified for HTTP1.1 caching
|
124
|
-
# takes into account all subscripts! also takes into account
|
125
|
-
# the script file modification
|
126
|
-
#
|
127
|
-
def __calc_lm(request)
|
128
|
-
unless lm = __lm(request)
|
129
|
-
lm = @file_mtime
|
130
|
-
else
|
131
|
-
lm = @file_mtime if @file_mtime > lm
|
132
|
-
end
|
133
|
-
|
134
|
-
if @sub_scripts
|
135
|
-
for script in @sub_scripts
|
136
|
-
if slm = script.__calc_lm(request)
|
137
|
-
unless lm
|
138
|
-
lm = slm
|
139
|
-
else
|
140
|
-
lm = slm if slm > lm
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
return lm
|
147
|
-
end
|
148
|
-
|
149
|
-
# Calculates the ETag fof HTTP1.1 caching. This etag is typically
|
150
|
-
# used in the downstream, so we can be VERY granular :-) ie
|
151
|
-
# we can even encode a user id!
|
152
|
-
#
|
153
|
-
# Coded by top level scripts only!
|
154
|
-
# Typically combines __tag and __last_modified
|
155
|
-
#
|
156
|
-
def __etag(request)
|
157
|
-
return "#{__calc_lm(request)}#{__calc_tag(request)}#{request.tag}" # .hash.to_s
|
158
|
-
end
|
159
|
-
|
160
|
-
# Is this script cacheable for this request?
|
161
|
-
#
|
162
|
-
def __cache?(request)
|
163
|
-
# By default if lm is overriden the page is cacheable
|
164
|
-
return __lm(request)
|
165
|
-
end
|
166
|
-
|
167
|
-
#---------------------------------------------------------------------
|
168
|
-
# Caching logic:
|
169
|
-
#
|
170
|
-
|
171
|
-
# gmosx, DEPRECATED: the following caching methods are deprecated!
|
172
|
-
# they are still used by rx handler though!
|
173
|
-
|
174
|
-
# clear the fragment_cache
|
175
|
-
#
|
176
|
-
def __cache_clear
|
177
|
-
@fragment_cache.clear
|
178
|
-
end
|
179
|
-
|
180
|
-
# get a fragment from the fragment cache in a thread safe manner.
|
181
|
-
#
|
182
|
-
# Output:
|
183
|
-
# the fragment object encapsulating the output of this script.
|
184
|
-
#
|
185
|
-
def __cache_get(key)
|
186
|
-
return @fragment_cache[key]
|
187
|
-
end
|
188
|
-
|
189
|
-
# add a new fragment in the fragment cache in a thread safe manner.
|
190
|
-
# encapsulate the fragment text (== body) in a fragment object.
|
191
|
-
#
|
192
|
-
def __cache_put(key, fragment)
|
193
|
-
@fragment_cache[key] = fragment
|
194
|
-
end
|
195
|
-
|
196
|
-
#--------------------------------------------------------------------------
|
197
|
-
# Rendering logic:
|
198
|
-
|
199
|
-
# renders the script as html output to be send to the
|
200
|
-
# borwser.
|
201
|
-
# the output of this script is the script fragment.
|
202
|
-
# this method is constructed dynamically by the handler.
|
203
|
-
#
|
204
|
-
# Design:
|
205
|
-
#
|
206
|
-
# the parameters to this method are visible to page scripts.
|
207
|
-
# in order to avoid namespace pollution and dangerous bugs in the
|
208
|
-
# scripts we prepend an underscore to differentiate them. n1 used
|
209
|
-
# @variables (class attributes) but we believe they where thread-unsafe.
|
210
|
-
#
|
211
|
-
def __render(request)
|
212
|
-
end
|
213
|
-
|
214
|
-
# Dynamically include ("inject") a subpage (fragment) in this page.
|
215
|
-
# Dynamic means at run-time.
|
216
|
-
#
|
217
|
-
def __inject(url, request)
|
218
|
-
return ""
|
219
|
-
end
|
220
|
-
|
221
|
-
# Dynamically include ("inject") a subpage (fragment) in this page.
|
222
|
-
# Dynamic means at run-time.
|
223
|
-
|
224
|
-
def __include(url, request)
|
225
|
-
return ""
|
226
|
-
end
|
227
|
-
|
228
|
-
def __create_time
|
229
|
-
return @create_time
|
230
|
-
end
|
231
|
-
|
232
|
-
def __file_mtime
|
233
|
-
return @file_mtime
|
234
|
-
end
|
235
|
-
|
236
|
-
def __path
|
237
|
-
return @path
|
238
|
-
end
|
239
|
-
|
240
|
-
#--------------------------------------------------------------------------
|
241
|
-
# Actions:
|
242
|
-
|
243
|
-
def admin?(request)
|
244
|
-
return false;
|
245
|
-
end
|
246
|
-
|
247
|
-
# Encodes an action url to the same page.
|
248
|
-
# Params is almost always != nil, no need to optimize the case.
|
249
|
-
#
|
250
|
-
def __action(request, params = nil)
|
251
|
-
if request.parameters.empty?
|
252
|
-
return "#{request.translated_uri}?#{params}"
|
253
|
-
else
|
254
|
-
return "#{request.translated_uri}?#{request.query_string};#{params}"
|
255
|
-
end
|
256
|
-
end
|
257
|
-
alias_method :_a, :__action
|
258
|
-
|
259
|
-
#--------------------------------------------------------------------------
|
260
|
-
# Hooks:
|
261
|
-
|
262
|
-
# executed prior to script evaluation, even for cached fragments!
|
263
|
-
# not used yet.
|
264
|
-
#
|
265
|
-
def __pre_evaluate(request)
|
266
|
-
end
|
267
|
-
|
268
|
-
# executed after script evaluation, even for cached fragments!
|
269
|
-
# not used yet.
|
270
|
-
|
271
|
-
def __post_evaluate(request)
|
272
|
-
end
|
273
|
-
|
274
|
-
# Pre-render hook. NOT executed for cached fragments
|
275
|
-
# not used yet.
|
276
|
-
#
|
277
|
-
# Returns:
|
278
|
-
# text that is prepended to the request, by default the EMPTY_STRING
|
279
|
-
#
|
280
|
-
def __pre_render(request)
|
281
|
-
return EMPTY_STRING
|
282
|
-
end
|
283
|
-
|
284
|
-
# Post-render hook. NOT executed for cached fragments.
|
285
|
-
# not used yet.
|
286
|
-
#
|
287
|
-
# Returns:
|
288
|
-
# text that is appended to the request, by default the EMPTY_STRING
|
289
|
-
#
|
290
|
-
def __post_render(request)
|
291
|
-
return EMPTY_STRING
|
292
|
-
end
|
293
|
-
|
294
|
-
# Calculate a hash modifier (flag) to differentiate caching according
|
295
|
-
# to user roles or other dynamic conditions. The calculated flag
|
296
|
-
# is appended to the fragmant hash.
|
297
|
-
#
|
298
|
-
# Design:
|
299
|
-
# use this separate method to allow the top level page to
|
300
|
-
# collect the flags for all sub-pages and build
|
301
|
-
# a super-flag.
|
302
|
-
#
|
303
|
-
def cache_flag(request)
|
304
|
-
return Fragment::ADMIN_FLAG if admin?(request)
|
305
|
-
end
|
306
|
-
|
307
|
-
# enable fragment caching for this script?
|
308
|
-
# to avoid storing in the cache uncacheable fragments
|
309
|
-
#
|
310
|
-
def cache?(request)
|
311
|
-
# gmosx: AAAAAAAAARGHHH!!! NASTY keep this false!
|
312
|
-
# to save memory!
|
313
|
-
return false
|
314
|
-
end
|
315
|
-
|
316
|
-
# is the output of the script (the fragment) valid for this request?
|
317
|
-
# used for cache invalidation calculations. By default returns false.
|
318
|
-
#
|
319
|
-
# Input:
|
320
|
-
# __fragment_key: the server automatically generates a fragment_key (typically
|
321
|
-
# the request.real_path) and passes this to this methods for further
|
322
|
-
# customization. The key passed is the base key, the method is responsible to
|
323
|
-
# build the final key (taking user roles, etc into account).
|
324
|
-
# request: used to customize the fragment_key for this request.
|
325
|
-
# customized fragment_keys denote request classes.
|
326
|
-
#
|
327
|
-
# Output:
|
328
|
-
# is the fragment valid for this request?
|
329
|
-
#
|
330
|
-
# Side-effects:
|
331
|
-
# WARNING: the method potentially modifies __fragment_key!
|
332
|
-
#
|
333
|
-
def cache_valid?(fragment, request)
|
334
|
-
return false
|
335
|
-
end
|
336
|
-
|
337
|
-
# authorize access to this script ?
|
338
|
-
#
|
339
|
-
def __authorize?(request)
|
340
|
-
return true
|
341
|
-
end
|
342
|
-
|
343
|
-
# get the shader to use for this script
|
344
|
-
#
|
345
|
-
def __shader(request)
|
346
|
-
return nil
|
347
|
-
end
|
348
|
-
|
349
|
-
# force a logged-in user for this page.
|
350
|
-
# implemented like the n1-version to avoid checking everytime
|
351
|
-
# for login, use the if __force method.
|
352
|
-
#
|
353
|
-
def __force_login(request)
|
354
|
-
if request.session["USER"].anonymous?
|
355
|
-
request.redirect("/id/login.sx?_go=#{request.uri}")
|
356
|
-
return false
|
357
|
-
end
|
358
|
-
return true
|
359
|
-
end
|
360
|
-
|
361
|
-
# --------------------------------------------------------------------
|
362
|
-
# Macros
|
363
|
-
# TODO: create more usefull macros for admin?/cache_valid? etc.
|
364
|
-
|
365
|
-
# Sets cache?() to return true
|
366
|
-
#
|
367
|
-
def self.enable_cache!
|
368
|
-
class_eval %{
|
369
|
-
def __cache?(request)
|
370
|
-
return true
|
371
|
-
end
|
372
|
-
}
|
373
|
-
end
|
374
|
-
|
375
|
-
# Evals a standard admin?() method.
|
376
|
-
#
|
377
|
-
def self.admin_role(role)
|
378
|
-
class_eval %{
|
379
|
-
def admin?(request)
|
380
|
-
return request.user.role?("#{role}")
|
381
|
-
end
|
382
|
-
}
|
383
|
-
end
|
384
|
-
|
385
|
-
end
|
386
|
-
|
387
|
-
end # module
|
data/lib/nitro/server/server.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# code:
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
3
|
-
#
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: server.rb 167 2004-11-23 14:03:10Z gmosx $
|
6
|
-
|
7
|
-
require "drb"
|
8
|
-
|
9
|
-
require "nitro/application"
|
10
|
-
require "nitro/server"
|
11
|
-
require "nitro/app/session"
|
12
|
-
|
13
|
-
module N; module App
|
14
|
-
|
15
|
-
# = ServerMixin
|
16
|
-
#
|
17
|
-
# Usefull application server related methods.
|
18
|
-
#
|
19
|
-
module ServerMixin
|
20
|
-
|
21
|
-
def initialize_app
|
22
|
-
if $drb_state
|
23
|
-
# Cluster mode: use distributed Ruby objects.
|
24
|
-
$lm = N::Cluster::Slm.new($drb_lm_server, "druby://:8000")
|
25
|
-
$sessions = DRbObject.new(nil, $drb_sessions_cluster)
|
26
|
-
else
|
27
|
-
# NoCluster mode: use standard Ruby onjects.
|
28
|
-
$lm = N::SafeHash.new
|
29
|
-
$sessions = N::App::SessionManager.new
|
30
|
-
end
|
31
|
-
|
32
|
-
# initialize app
|
33
|
-
initialize_sitemap()
|
34
|
-
initialize_shaders()
|
35
|
-
initialize_events()
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
# = Server
|
41
|
-
#
|
42
|
-
# The Application Server. Handles dynamic requests in a web application.
|
43
|
-
# Dont keepalive (or use a VERY SMALL keepalive). Typically this server
|
44
|
-
# is used along with a standars http server that handles other resources.
|
45
|
-
#
|
46
|
-
class Server < N::Server
|
47
|
-
include N::App::ServerMixin
|
48
|
-
|
49
|
-
def initialize(name = "AppServer")
|
50
|
-
super
|
51
|
-
initialize_app()
|
52
|
-
|
53
|
-
Logger.info "Server listening at #$srv_url"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end; end # module
|