nitro 0.2.0 → 0.3.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.
- data/ChangeLog +186 -0
- data/README +40 -11
- data/RELEASES +10 -1
- data/Rakefile +5 -4
- data/bin/cluster.rb +3 -3
- data/{etc/new-project.rb → bin/new_app.rb} +1 -1
- data/examples/og/README +4 -0
- data/examples/og/run.rb +254 -0
- data/examples/simple/app.rb +3 -3
- data/examples/simple/conf/config.rb +10 -22
- data/examples/simple/conf/debug-config.rb +6 -32
- data/examples/simple/conf/live-config.rb +3 -23
- data/examples/simple/conf/requires.rb +5 -5
- data/examples/simple/env.rb +3 -4
- data/examples/simple/lib/articles/entities.rb +17 -15
- data/examples/simple/lib/articles/methods.rb +15 -15
- data/examples/simple/lib/articles/part.rb +7 -8
- data/examples/simple/root/comments.si +1 -1
- data/examples/simple/root/index.sx +1 -1
- data/examples/simple/root/view-article.sx +1 -2
- data/examples/tiny/app.rb +3 -3
- data/examples/tiny/conf/config.rb +4 -4
- data/examples/tiny/conf/requires.rb +3 -4
- data/lib/n/config.rb +50 -3
- data/lib/n/logger.rb +14 -2
- data/lib/n/og.rb +381 -0
- data/lib/n/og/backend.rb +252 -0
- data/lib/n/og/backends/mysql.rb +352 -0
- data/lib/n/og/backends/psql.rb +351 -0
- data/lib/n/og/connection.rb +253 -0
- data/lib/n/og/meta.rb +127 -0
- data/lib/n/properties.rb +6 -6
- data/lib/n/server.rb +4 -7
- data/lib/n/server/appserver.rb +58 -0
- data/lib/n/{app → server}/cluster.rb +3 -3
- data/lib/n/{app → server}/cookie.rb +3 -3
- data/lib/n/server/dispatcher.rb +55 -0
- data/lib/n/server/{filter.rb → filters.rb} +1 -1
- data/lib/n/{app → server}/filters/autologin.rb +5 -5
- data/lib/n/{app → server}/fragment.rb +3 -3
- data/lib/n/{app → server}/handlers.rb +4 -4
- data/lib/n/{app → server}/handlers/code-handler.rb +6 -6
- data/lib/n/{app → server}/handlers/page-handler.rb +9 -7
- data/lib/n/{app → server}/request.rb +8 -8
- data/lib/n/{app/request-part.rb → server/requestpart.rb} +4 -4
- data/lib/n/{app → server}/script.rb +5 -5
- data/lib/n/{app → server}/server.rb +1 -1
- data/lib/n/{app → server}/session.rb +5 -5
- data/lib/n/{app → server}/user.rb +1 -1
- data/lib/n/{app/webrick-servlet.rb → server/webrick.rb} +77 -20
- data/lib/n/shaders.rb +3 -2
- data/lib/n/std.rb +5 -32
- data/test/n/{app → server}/tc_cookie.rb +2 -2
- data/test/n/server/tc_filters.rb +38 -0
- data/test/n/{app → server}/tc_request.rb +6 -6
- data/test/n/{app → server}/tc_requestpart.rb +3 -3
- data/test/n/{app → server}/tc_session.rb +2 -2
- data/test/n/tc_og.rb +178 -0
- data/test/n/ui/tc_pager.rb +3 -3
- metadata +41 -65
- data/examples/ndb/README +0 -5
- data/examples/ndb/run.rb +0 -271
- data/lib/n/app/webrick.rb +0 -73
- data/lib/n/db.rb +0 -233
- data/lib/n/db/README +0 -232
- data/lib/n/db/connection.rb +0 -365
- data/lib/n/db/managed.rb +0 -233
- data/lib/n/db/mixins.rb +0 -279
- data/lib/n/db/mysql.rb +0 -345
- data/lib/n/db/psql.rb +0 -383
- data/lib/n/db/tools.rb +0 -106
- data/lib/n/db/utils.rb +0 -102
- data/lib/n/server/PLAYBACK.txt +0 -8
- data/lib/n/server/RESEARCH.txt +0 -13
- data/test/n/tc_db.rb +0 -223
- data/test/n/tc_db_mysql.rb +0 -241
@@ -3,7 +3,7 @@
|
|
3
3
|
# * Anastasios Koutoumanos <ak@navel.gr>
|
4
4
|
#
|
5
5
|
# (c) 2004 Navel, all rights reserved.
|
6
|
-
# $Id: page-handler.rb
|
6
|
+
# $Id: page-handler.rb 112 2004-10-27 10:59:55Z gmosx $
|
7
7
|
|
8
8
|
require "cgi"
|
9
9
|
require "singleton"
|
@@ -11,11 +11,11 @@ require "sync"
|
|
11
11
|
|
12
12
|
require "n/utils/cache"
|
13
13
|
require "n/utils/uri"
|
14
|
-
require "n/
|
15
|
-
require "n/
|
16
|
-
require "n/
|
14
|
+
require "n/server/script"
|
15
|
+
require "n/server/fragment"
|
16
|
+
require "n/server/handlers"
|
17
17
|
|
18
|
-
module N
|
18
|
+
module N
|
19
19
|
|
20
20
|
# = PageHandler
|
21
21
|
#
|
@@ -277,9 +277,11 @@ class PageHandler < ScriptHandler
|
|
277
277
|
# FIXME: perhaps the xslt could strip this?
|
278
278
|
pagecode.gsub!(/<\?xml.*\?>/, "")
|
279
279
|
|
280
|
-
# xform the processing instructions
|
280
|
+
# xform the processing instructions, use <?ruby, <?rb, <?r as
|
281
|
+
# a marker.
|
281
282
|
pagecode.gsub!(/\?>/, "\n__out << %{")
|
282
283
|
pagecode.gsub!(/<\?ruby /, "}\n")
|
284
|
+
pagecode.gsub!(/<\?ruby /, "}\n")
|
283
285
|
pagecode.gsub!(/<\?r /, "}\n")
|
284
286
|
|
285
287
|
# tml, TODO: resolve static injects! scan injects and update the metadata
|
@@ -607,4 +609,4 @@ class PageScript < Script
|
|
607
609
|
|
608
610
|
end # PageScript
|
609
611
|
|
610
|
-
end
|
612
|
+
end # module
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
3
|
#
|
4
4
|
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: request.rb
|
5
|
+
# $Id: request.rb 124 2004-11-01 12:34:17Z gmosx $
|
6
6
|
|
7
7
|
require "cgi"
|
8
8
|
require "ftools"
|
@@ -10,10 +10,10 @@ require "ftools"
|
|
10
10
|
require "n/utils/string"
|
11
11
|
require "n/utils/uri"
|
12
12
|
require "n/utils/http"
|
13
|
-
require "n/
|
14
|
-
require "n/
|
13
|
+
require "n/server/cookie"
|
14
|
+
require "n/server/requestpart"
|
15
15
|
|
16
|
-
module N
|
16
|
+
module N
|
17
17
|
|
18
18
|
# = RequestUtils
|
19
19
|
#
|
@@ -56,7 +56,7 @@ module RequestUtils
|
|
56
56
|
#
|
57
57
|
def get_entity(oid_param, klass = nil)
|
58
58
|
if oid = self[oid_param]
|
59
|
-
obj = $
|
59
|
+
obj = $og.load(oid, klass)
|
60
60
|
|
61
61
|
if klass
|
62
62
|
if obj.is_a?(klass)
|
@@ -80,7 +80,7 @@ module RequestUtils
|
|
80
80
|
#
|
81
81
|
def get_entity_by_name(name_param, klass)
|
82
82
|
if name = self[name_param]
|
83
|
-
obj = $
|
83
|
+
obj = $og.load_by_name(name, klass)
|
84
84
|
|
85
85
|
if klass
|
86
86
|
if obj.is_a?(klass)
|
@@ -323,7 +323,7 @@ class Request
|
|
323
323
|
# time to the past (epoch).
|
324
324
|
#
|
325
325
|
def del_cookie(name)
|
326
|
-
cookie = N::
|
326
|
+
cookie = N::Cookie.new(name, "nil")
|
327
327
|
cookie.path = "/"
|
328
328
|
cookie.expires = Time.at(0)
|
329
329
|
@out_cookies[name] = cookie
|
@@ -655,4 +655,4 @@ class Request
|
|
655
655
|
|
656
656
|
end
|
657
657
|
|
658
|
-
end
|
658
|
+
end # module
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
3
|
#
|
4
4
|
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id:
|
5
|
+
# $Id: requestpart.rb 112 2004-10-27 10:59:55Z gmosx $
|
6
6
|
|
7
7
|
require "cgi"
|
8
8
|
require "ftools"
|
@@ -10,9 +10,9 @@ require "ftools"
|
|
10
10
|
require "n/utils/string"
|
11
11
|
require "n/utils/uri"
|
12
12
|
require "n/utils/http"
|
13
|
-
require "n/
|
13
|
+
require "n/server/cookie"
|
14
14
|
|
15
|
-
module N
|
15
|
+
module N
|
16
16
|
|
17
17
|
# RequestPart
|
18
18
|
#
|
@@ -51,4 +51,4 @@ class RequestPart
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
end
|
54
|
+
end # module
|
@@ -2,12 +2,12 @@
|
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
3
|
#
|
4
4
|
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: script.rb
|
5
|
+
# $Id: script.rb 112 2004-10-27 10:59:55Z gmosx $
|
6
6
|
|
7
7
|
require "fileutils"
|
8
8
|
|
9
9
|
require "n/utils/cache"
|
10
|
-
require "n/
|
10
|
+
require "n/server/fragment"
|
11
11
|
|
12
12
|
module N
|
13
13
|
|
@@ -20,7 +20,7 @@ class ScriptExitException < Exception; end
|
|
20
20
|
|
21
21
|
end # module
|
22
22
|
|
23
|
-
module N
|
23
|
+
module N
|
24
24
|
|
25
25
|
# = Script
|
26
26
|
#
|
@@ -382,6 +382,6 @@ class Script
|
|
382
382
|
}
|
383
383
|
end
|
384
384
|
|
385
|
-
end
|
385
|
+
end
|
386
386
|
|
387
|
-
end
|
387
|
+
end # module
|
@@ -2,14 +2,14 @@
|
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
3
|
#
|
4
4
|
# (c) 2002-2003 Navel, all rights reserved.
|
5
|
-
# $Id: session.rb
|
5
|
+
# $Id: session.rb 124 2004-11-01 12:34:17Z gmosx $
|
6
6
|
|
7
7
|
require "md5"
|
8
8
|
|
9
9
|
require "n/utils/hash"
|
10
|
-
require "n/
|
10
|
+
require "n/server/user"
|
11
11
|
|
12
|
-
module N
|
12
|
+
module N
|
13
13
|
|
14
14
|
# = SessionManager
|
15
15
|
#
|
@@ -182,7 +182,7 @@ class Session < Hash
|
|
182
182
|
# === Warning: the current version only refreshes the "USER" entity.
|
183
183
|
#
|
184
184
|
def refresh!
|
185
|
-
@user = $
|
185
|
+
@user = $og.load(@user.oid, @user.class) if @user
|
186
186
|
end
|
187
187
|
|
188
188
|
# Calculates a unique id.
|
@@ -217,4 +217,4 @@ class Session < Hash
|
|
217
217
|
|
218
218
|
end
|
219
219
|
|
220
|
-
end
|
220
|
+
end # module
|
@@ -1,19 +1,23 @@
|
|
1
1
|
# code:
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
|
+
# * Elias Athanasopoulos <elathan@navel.gr>
|
3
4
|
#
|
4
5
|
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: webrick
|
6
|
+
# $Id: webrick.rb 118 2004-11-01 10:13:42Z gmosx $
|
6
7
|
|
7
8
|
require "drb"
|
9
|
+
require "cgi"
|
8
10
|
require "singleton"
|
9
11
|
require "webrick"
|
10
12
|
|
11
13
|
require "n/logger"
|
14
|
+
require "n/application"
|
12
15
|
require "n/utils/cache"
|
13
|
-
require "n/
|
14
|
-
require "n/
|
15
|
-
require "n/
|
16
|
-
require "n/
|
16
|
+
require "n/server/request"
|
17
|
+
require "n/server/request"
|
18
|
+
require "n/server/handlers"
|
19
|
+
require "n/server/session"
|
20
|
+
require "n/server/appserver"
|
17
21
|
|
18
22
|
# Override WEBrick to suit our needs.
|
19
23
|
#
|
@@ -49,7 +53,61 @@ module WEBrick
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
|
-
module N
|
56
|
+
module N
|
57
|
+
|
58
|
+
# = Webrick AppServer
|
59
|
+
#
|
60
|
+
# The Application Server. Handles dynamic requests in a web application.
|
61
|
+
# Dont keepalive (or use a VERY SMALL keepalive). Typically this server
|
62
|
+
# is used along with a standard http server that handles other resources.
|
63
|
+
#
|
64
|
+
# Used temporarily unitl we build our own app server.
|
65
|
+
#
|
66
|
+
class Webrick < N::AppServer
|
67
|
+
include WEBrick
|
68
|
+
|
69
|
+
# the integrated webrock server.
|
70
|
+
attr_accessor :webrick
|
71
|
+
|
72
|
+
def initialize(name = "WebrickServer")
|
73
|
+
super
|
74
|
+
end
|
75
|
+
|
76
|
+
# Start the application server.
|
77
|
+
#
|
78
|
+
def start
|
79
|
+
accesslog = WEBrick::BasicLog::new("/dev/null")
|
80
|
+
referer = WEBrick::BasicLog::new("/dev/null")
|
81
|
+
|
82
|
+
@webrick = HTTPServer.new(
|
83
|
+
:BindAddress => $appsrv_address,
|
84
|
+
:Port => $appsrv_port,
|
85
|
+
:DocumentRoot => $root_dir,
|
86
|
+
# gmosx, FIXME: this shit still logs!!
|
87
|
+
:Logger => Log.new(nil, WEBrick::Log::WARN),
|
88
|
+
# elathan: amateur...
|
89
|
+
:AccessLog => [
|
90
|
+
[accesslog, AccessLog::COMMON_LOG_FORMAT],
|
91
|
+
[referer, AccessLog::REFERER_LOG_FORMAT]
|
92
|
+
]
|
93
|
+
)
|
94
|
+
|
95
|
+
@webrick.mount("/", N::WebrickServlet)
|
96
|
+
|
97
|
+
trap("INT") {
|
98
|
+
@webrick.shutdown()
|
99
|
+
}
|
100
|
+
|
101
|
+
@webrick.start()
|
102
|
+
end
|
103
|
+
|
104
|
+
# Stop the application server.
|
105
|
+
#
|
106
|
+
def stop
|
107
|
+
@webrick.stop
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
53
111
|
|
54
112
|
# = WebrickServlet
|
55
113
|
#
|
@@ -75,6 +133,7 @@ class WebrickServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
75
133
|
end
|
76
134
|
|
77
135
|
begin
|
136
|
+
$og.get_connection if $og
|
78
137
|
fragment, script = handler.process(request)
|
79
138
|
|
80
139
|
if fragment
|
@@ -117,6 +176,8 @@ class WebrickServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
117
176
|
}
|
118
177
|
request.out_buffer = body
|
119
178
|
end
|
179
|
+
ensure
|
180
|
+
$og.put_connection if $og
|
120
181
|
end
|
121
182
|
|
122
183
|
# gmosx: optimize me, do something more clever!!!
|
@@ -128,12 +189,8 @@ class WebrickServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
128
189
|
wres.body = request.out_buffer
|
129
190
|
end
|
130
191
|
|
131
|
-
|
132
|
-
|
133
|
-
def do_POST(wreq, wres)
|
134
|
-
do_GET(wreq, wres)
|
135
|
-
end
|
136
|
-
|
192
|
+
alias :do_POST :do_GET
|
193
|
+
|
137
194
|
#-------------------------------------------------------------------------------
|
138
195
|
|
139
196
|
private
|
@@ -143,7 +200,7 @@ class WebrickServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
143
200
|
#
|
144
201
|
def create_request(wreq)
|
145
202
|
# FIXME: use a resource pool!
|
146
|
-
request = N::
|
203
|
+
request = N::Request.new
|
147
204
|
|
148
205
|
request.uri = wreq.unparsed_uri
|
149
206
|
request.translated_uri = wreq.path_info
|
@@ -168,7 +225,7 @@ class WebrickServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
168
225
|
|
169
226
|
wreq.query.each { |k, v|
|
170
227
|
if v.filename
|
171
|
-
request.parts[k] = N::
|
228
|
+
request.parts[k] = N::RequestPart.new(v.filename, v)
|
172
229
|
else
|
173
230
|
request.parameters[k] = v
|
174
231
|
end
|
@@ -204,23 +261,23 @@ class WebrickServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
204
261
|
# gmosx: i have to fix the get_cookie method to return a
|
205
262
|
# full cookie object.
|
206
263
|
|
207
|
-
if session_id = request.get_cookie(N::
|
264
|
+
if session_id = request.get_cookie(N::Session::COOKIE_NAME)
|
208
265
|
session = $sessions[session_id]
|
209
266
|
$log.debug "Stale session cookie: #{session_id}" unless session
|
210
267
|
# FIXME: remove cookie if stale!
|
211
268
|
else
|
212
|
-
session_id = N::
|
213
|
-
cookie = N::
|
214
|
-
request.out_cookies[N::
|
269
|
+
session_id = N::Session.calculate_id()
|
270
|
+
cookie = N::Cookie.new(N::Session::COOKIE_NAME, session_id)
|
271
|
+
request.out_cookies[N::Session::COOKIE_NAME] = cookie
|
215
272
|
end
|
216
273
|
|
217
274
|
# session not found and must be created
|
218
275
|
unless session
|
219
|
-
session = N::
|
276
|
+
session = N::Session.new(session_id)
|
220
277
|
end
|
221
278
|
|
222
279
|
return session
|
223
280
|
end
|
224
281
|
end
|
225
282
|
|
226
|
-
end
|
283
|
+
end # module
|
data/lib/n/shaders.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
3
|
#
|
4
4
|
# (c) 2004 Navel, all rights reserved.
|
5
|
-
# $Id: shaders.rb
|
5
|
+
# $Id: shaders.rb 109 2004-10-27 09:12:45Z gmosx $
|
6
6
|
|
7
7
|
module N;
|
8
8
|
|
@@ -103,7 +103,8 @@ end
|
|
103
103
|
#
|
104
104
|
class NilShader < Shader
|
105
105
|
def initialize
|
106
|
-
|
106
|
+
# gmosx: to get better display.
|
107
|
+
@name = nil
|
107
108
|
@mtime = Time.at(0)
|
108
109
|
end
|
109
110
|
|
data/lib/n/std.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# * George Moschovitis <gm@navel.gr>
|
7
7
|
#
|
8
8
|
# (c) 2004 Navel, all rights reserved.
|
9
|
-
# $Id: std.rb
|
9
|
+
# $Id: std.rb 123 2004-11-01 11:55:11Z gmosx $
|
10
10
|
|
11
11
|
# we want readable code
|
12
12
|
|
@@ -14,34 +14,23 @@ require "English"
|
|
14
14
|
require "pp"
|
15
15
|
|
16
16
|
class NilClass
|
17
|
-
# to_i, to_s are handled by default.
|
18
|
-
|
19
|
-
def to_i
|
20
|
-
return nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_f
|
24
|
-
return 0.0
|
25
|
-
end
|
26
|
-
|
27
17
|
# quite usefull for error tolerant apps.
|
28
|
-
# a bit dangerous
|
18
|
+
# a bit dangerous? Will have to rethink this.
|
29
19
|
#
|
30
20
|
def empty?
|
31
21
|
return true
|
32
22
|
end
|
33
23
|
end
|
34
24
|
|
35
|
-
#
|
36
|
-
#
|
37
25
|
class Class
|
26
|
+
#--
|
27
|
+
# gmosx: is this really needed?
|
28
|
+
#++
|
38
29
|
def to_i()
|
39
30
|
return self.hash()
|
40
31
|
end
|
41
32
|
end
|
42
33
|
|
43
|
-
#
|
44
|
-
#
|
45
34
|
module Kernel
|
46
35
|
# pretty prints an exception/error object
|
47
36
|
# usefull for helpfull debug messages
|
@@ -62,19 +51,3 @@ end
|
|
62
51
|
|
63
52
|
EMPTY_STRING = ""
|
64
53
|
|
65
|
-
# = N
|
66
|
-
#
|
67
|
-
# This module is used as a namespace that encapsulates
|
68
|
-
# engine objects.
|
69
|
-
#
|
70
|
-
module N
|
71
|
-
end # module
|
72
|
-
|
73
|
-
# This the default 72 chars separator, copy paste to use it
|
74
|
-
# in your source file. Btw all lines in your source file should
|
75
|
-
# be less than 72 chars. So you can use this as a ruler if your
|
76
|
-
# editor does not support it.
|
77
|
-
|
78
|
-
#-----------------------------------------------------------------------
|
79
|
-
|
80
|
-
|