nitro 0.8.0 → 0.9.3
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/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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# George Moschovitis <gm@navel.gr>
|
|
3
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
4
|
+
# $Id$
|
|
5
|
+
#++
|
|
6
|
+
|
|
7
|
+
require 'webrick'
|
|
8
|
+
|
|
9
|
+
require 'nitro/context'
|
|
10
|
+
require 'nitro/dispatcher'
|
|
11
|
+
|
|
12
|
+
module WEBrick
|
|
13
|
+
|
|
14
|
+
class HTTPResponse
|
|
15
|
+
def header=(header)
|
|
16
|
+
@header = header
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cookies=(cookies)
|
|
20
|
+
@cookies = cookies
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module N
|
|
27
|
+
|
|
28
|
+
# Helper methods for the WebrickAdaptor.
|
|
29
|
+
|
|
30
|
+
class Webrick
|
|
31
|
+
|
|
32
|
+
class << self
|
|
33
|
+
attr_accessor :server
|
|
34
|
+
|
|
35
|
+
def start(conf)
|
|
36
|
+
# patch for OSX
|
|
37
|
+
|
|
38
|
+
Socket.do_not_reverse_lookup = true
|
|
39
|
+
|
|
40
|
+
# if RUBY_PLATFORM =~ /mswin32/
|
|
41
|
+
# accesslog = WEBrick::BasicLog::new('/dev/null')
|
|
42
|
+
# referer = WEBrick::BasicLog::new('/dev/null')
|
|
43
|
+
|
|
44
|
+
accesslog = WEBrick::BasicLog::new('log/access.log')
|
|
45
|
+
referer = WEBrick::BasicLog::new('log/referer.log')
|
|
46
|
+
|
|
47
|
+
@server = WEBrick::HTTPServer.new(
|
|
48
|
+
:BindAddress => conf.host,
|
|
49
|
+
:Port => conf.port,
|
|
50
|
+
:DocumentRoot => conf.dispatcher.root,
|
|
51
|
+
:AccessLog => [
|
|
52
|
+
[accesslog, WEBrick::AccessLog::COMMON_LOG_FORMAT],
|
|
53
|
+
[referer, WEBrick::AccessLog::REFERER_LOG_FORMAT]
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
trap('INT') { @server.shutdown }
|
|
58
|
+
|
|
59
|
+
@server.mount('/', WebrickAdaptor, conf)
|
|
60
|
+
@server.start
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# A Webrick Adaptor for Nitro.
|
|
67
|
+
|
|
68
|
+
class WebrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
|
|
69
|
+
|
|
70
|
+
def initialize(server, conf)
|
|
71
|
+
@conf = conf
|
|
72
|
+
|
|
73
|
+
# Handles static resources. Useful when running
|
|
74
|
+
# a stand-alone webrick server.
|
|
75
|
+
|
|
76
|
+
@file_handler = WEBrick::HTTPServlet::FileHandler.new(
|
|
77
|
+
server,
|
|
78
|
+
conf.dispatcher.root, conf.webrick_options || {})
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def handle(req, res)
|
|
82
|
+
path = req.request_uri.path
|
|
83
|
+
|
|
84
|
+
if path =~ /\./
|
|
85
|
+
@file_handler.do_GET(req, res)
|
|
86
|
+
else
|
|
87
|
+
context = Context.new(@conf)
|
|
88
|
+
|
|
89
|
+
context.params = req.query
|
|
90
|
+
context.headers = {}
|
|
91
|
+
req.header.each { |h, v| context.headers[h.upcase] = v.first }
|
|
92
|
+
context.headers.update(req.meta_vars)
|
|
93
|
+
context.cookies = {}
|
|
94
|
+
req.cookies.each { |c| context.cookies[c.name] = c.value }
|
|
95
|
+
|
|
96
|
+
context.render(path)
|
|
97
|
+
|
|
98
|
+
res.status = context.status
|
|
99
|
+
res.header = context.response_headers || {}
|
|
100
|
+
res.cookies = context.response_cookies || {}
|
|
101
|
+
res.body = context.out
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
alias do_GET handle
|
|
106
|
+
alias do_POST handle
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id$
|
|
4
|
+
|
|
5
|
+
require 'glue/attribute'
|
|
6
|
+
|
|
7
|
+
require 'nitro/shaders'
|
|
8
|
+
|
|
9
|
+
module N
|
|
10
|
+
|
|
11
|
+
# The output buffering mixin. Provides php-style output
|
|
12
|
+
# buffering functionality.
|
|
13
|
+
|
|
14
|
+
module OutputBuffering
|
|
15
|
+
# Output buffers stack, used for php-style nested output
|
|
16
|
+
# buffering.
|
|
17
|
+
|
|
18
|
+
attr :out_buffers
|
|
19
|
+
|
|
20
|
+
# Start (push) a new output buffer.
|
|
21
|
+
|
|
22
|
+
def ob_start
|
|
23
|
+
@out_buffers ||= []
|
|
24
|
+
@out_buffers.push(@out)
|
|
25
|
+
@out = ''
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# End (pop) the current output buffer.
|
|
29
|
+
|
|
30
|
+
def ob_end
|
|
31
|
+
@out = @out_buffers.pop
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# End (pop) the current output buffer and write to the parent.
|
|
35
|
+
|
|
36
|
+
def ob_write_end
|
|
37
|
+
nested_buffer = @out
|
|
38
|
+
@out = @out_buffers.pop
|
|
39
|
+
@out << nested_buffer
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
data/lib/nitro/builders/form.rb
CHANGED
data/lib/nitro/builders/rss.rb
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
# code:
|
|
2
1
|
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id: cluster.rb 234 2005-01-27 13:01:40Z gmosx $
|
|
4
|
+
|
|
5
|
+
# WARNING: This is old code, not updated to work in the
|
|
6
|
+
# latest nitro release. Will be fixed ASAP.
|
|
6
7
|
|
|
7
|
-
$:.unshift
|
|
8
|
+
$:.unshift 'lib'
|
|
8
9
|
|
|
9
|
-
require
|
|
10
|
-
require
|
|
10
|
+
require 'drb'
|
|
11
|
+
require 'monitor'
|
|
11
12
|
|
|
12
|
-
require
|
|
13
|
-
require
|
|
14
|
-
require
|
|
15
|
-
require
|
|
13
|
+
require 'nitro/application'
|
|
14
|
+
require 'nitro/server'
|
|
15
|
+
require 'glue/cache'
|
|
16
|
+
require 'nitro/server/session'
|
|
16
17
|
|
|
17
18
|
module N
|
|
18
19
|
|
|
19
|
-
# = Cluster
|
|
20
|
-
#
|
|
21
20
|
# A Cluster manages the state of a collection of servers. The cluster
|
|
22
21
|
# synchronizes the servers and distributes the state. An older version
|
|
23
22
|
# used a polling system, ie: the servers polled the cluster to
|
|
@@ -25,25 +24,25 @@ module N
|
|
|
25
24
|
# state is changed a delta is pushed to the clients.
|
|
26
25
|
#
|
|
27
26
|
# TODO: use Sync instead of Monitor
|
|
28
|
-
|
|
27
|
+
|
|
29
28
|
class Cluster < N::Application
|
|
30
29
|
|
|
31
|
-
# = CHash ClusterHash
|
|
32
|
-
#
|
|
33
30
|
# The CHash 'endpoint' resides in the Cluster server
|
|
34
|
-
|
|
31
|
+
|
|
35
32
|
class CHash < Hash
|
|
36
33
|
attr :mon
|
|
37
34
|
|
|
38
35
|
# drbobject for this hash (local)
|
|
36
|
+
|
|
39
37
|
attr_accessor :ldrb
|
|
40
38
|
|
|
41
39
|
# the cluster, use a cluster to implement a set
|
|
42
40
|
# (one server per drb_uri)
|
|
41
|
+
|
|
43
42
|
attr_accessor :cluster
|
|
44
43
|
|
|
45
44
|
#
|
|
46
|
-
|
|
45
|
+
|
|
47
46
|
def initialize(ldrb_uri = "druby://:8000")
|
|
48
47
|
@mon = Monitor.new
|
|
49
48
|
@ldrb = DRb.start_service(ldrb_uri, self)
|
|
@@ -51,7 +50,7 @@ class Cluster < N::Application
|
|
|
51
50
|
end
|
|
52
51
|
|
|
53
52
|
#
|
|
54
|
-
|
|
53
|
+
|
|
55
54
|
def join(sdrb_uri)
|
|
56
55
|
@mon.synchronize {
|
|
57
56
|
cluster[sdrb_uri] = DRbObject.new(nil, sdrb_uri)
|
|
@@ -61,7 +60,7 @@ class Cluster < N::Application
|
|
|
61
60
|
alias_method :old_set, :[]=
|
|
62
61
|
|
|
63
62
|
# Not really usefull
|
|
64
|
-
|
|
63
|
+
|
|
65
64
|
def []=(key, value)
|
|
66
65
|
# store the value (useful on server restarts)
|
|
67
66
|
@mon.synchronize {
|
|
@@ -110,10 +109,8 @@ class Cluster < N::Application
|
|
|
110
109
|
|
|
111
110
|
end
|
|
112
111
|
|
|
113
|
-
# = SHash ServerHash
|
|
114
|
-
#
|
|
115
112
|
# The SHash 'endpoint' resides in the App server
|
|
116
|
-
|
|
113
|
+
|
|
117
114
|
class SHash < Hash
|
|
118
115
|
attr :mon
|
|
119
116
|
|
|
@@ -125,7 +122,7 @@ class Cluster < N::Application
|
|
|
125
122
|
|
|
126
123
|
# ldrb = local drb uri
|
|
127
124
|
# cdrb = cluster drb uri
|
|
128
|
-
|
|
125
|
+
|
|
129
126
|
def initialize(ldrb_uri = "druby://:9000", cdrb_uri = "druby://:8000")
|
|
130
127
|
@mon = Monitor.new
|
|
131
128
|
@ldrb_uri = ldrb_uri
|
|
@@ -171,8 +168,8 @@ class Cluster < N::Application
|
|
|
171
168
|
|
|
172
169
|
end
|
|
173
170
|
|
|
174
|
-
#
|
|
175
|
-
|
|
171
|
+
# Cluster Last Modified Hash
|
|
172
|
+
|
|
176
173
|
class Clm < CHash
|
|
177
174
|
def [](key)
|
|
178
175
|
@mon.synchronize {
|
|
@@ -187,7 +184,7 @@ class Cluster < N::Application
|
|
|
187
184
|
end
|
|
188
185
|
|
|
189
186
|
# = Slm Server Last Modified Hash
|
|
190
|
-
|
|
187
|
+
|
|
191
188
|
class Slm < SHash
|
|
192
189
|
def set!(key, lm = nil)
|
|
193
190
|
lm = Time.now.to_i unless lm
|
|
@@ -213,10 +210,9 @@ class Cluster < N::Application
|
|
|
213
210
|
|
|
214
211
|
end
|
|
215
212
|
|
|
216
|
-
end
|
|
213
|
+
end
|
|
217
214
|
|
|
218
215
|
if $0 == __FILE__
|
|
219
|
-
require
|
|
220
|
-
|
|
216
|
+
require 'logger'
|
|
221
217
|
N::Cluster.new.exec()
|
|
222
218
|
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id$
|
|
4
|
+
|
|
5
|
+
require 'nitro/request'
|
|
6
|
+
require 'nitro/response'
|
|
7
|
+
require 'nitro/render'
|
|
8
|
+
require 'nitro/session'
|
|
9
|
+
|
|
10
|
+
module N
|
|
11
|
+
|
|
12
|
+
# Encapsulates an HTTP processing cycle context.
|
|
13
|
+
# Integrates the Request and the Response.
|
|
14
|
+
|
|
15
|
+
class Context
|
|
16
|
+
include Request
|
|
17
|
+
include Response
|
|
18
|
+
include Render
|
|
19
|
+
|
|
20
|
+
# The configuration parameters.
|
|
21
|
+
|
|
22
|
+
attr_accessor :conf
|
|
23
|
+
|
|
24
|
+
# The session contains variables that stay alive
|
|
25
|
+
# for the full user session. Session variables
|
|
26
|
+
# should be generally avoided.
|
|
27
|
+
|
|
28
|
+
attr_reader :session
|
|
29
|
+
|
|
30
|
+
# The dispatcher.
|
|
31
|
+
|
|
32
|
+
attr_accessor :dispatcher
|
|
33
|
+
|
|
34
|
+
# The sessions.
|
|
35
|
+
|
|
36
|
+
attr_accessor :sessions
|
|
37
|
+
|
|
38
|
+
def initialize(conf)
|
|
39
|
+
@conf = conf
|
|
40
|
+
@dispatcher = @conf.dispatcher
|
|
41
|
+
@context = self
|
|
42
|
+
@sessions = Session.manager
|
|
43
|
+
|
|
44
|
+
# gmosx, FIXME: try to avoid creating this hash!
|
|
45
|
+
@response_headers = {}
|
|
46
|
+
@out = ''
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Lazy lookup of the session to avoid costly cookie
|
|
50
|
+
# lookup when not needed.
|
|
51
|
+
|
|
52
|
+
def session
|
|
53
|
+
return @session if @session
|
|
54
|
+
return @session = Session.lookup(self)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Populate an object from request parameters.
|
|
58
|
+
# This is a truly dangerous method.
|
|
59
|
+
|
|
60
|
+
EXCLUDED_PARAMETERS = %w{ oid name }
|
|
61
|
+
|
|
62
|
+
def fill(obj, name = nil)
|
|
63
|
+
# if an object is passed create an instance.
|
|
64
|
+
obj = obj.new if obj.is_a?(Class)
|
|
65
|
+
|
|
66
|
+
@params.each do |param, val|
|
|
67
|
+
begin
|
|
68
|
+
# gmosx: DO NOT escape by default !!!
|
|
69
|
+
if not EXCLUDED_PARAMETERS.include?(param)
|
|
70
|
+
obj.send("__force_#{param}", val)
|
|
71
|
+
end
|
|
72
|
+
rescue NameError
|
|
73
|
+
next
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
return obj
|
|
78
|
+
end
|
|
79
|
+
alias_method :populate, :fill
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id$
|
|
4
|
+
|
|
5
|
+
require 'nitro/render'
|
|
6
|
+
require 'nitro/scaffold'
|
|
7
|
+
require 'nitro/filters'
|
|
8
|
+
|
|
9
|
+
module N
|
|
10
|
+
|
|
11
|
+
# The Controller part in the MVC paradigm.
|
|
12
|
+
# A Controller encpsulates a set of actions.
|
|
13
|
+
|
|
14
|
+
class Controller
|
|
15
|
+
include Render
|
|
16
|
+
include Scaffolding
|
|
17
|
+
include Filtering
|
|
18
|
+
|
|
19
|
+
# Use the method_missing hook to compile the actions
|
|
20
|
+
# for this controller.
|
|
21
|
+
|
|
22
|
+
def method_missing(action, *args)
|
|
23
|
+
if Rendering.compile_action(self.class, action, @base)
|
|
24
|
+
# FIXME: temp hack!
|
|
25
|
+
if :partial == Rendering.reload
|
|
26
|
+
ret = send(action, *args)
|
|
27
|
+
self.class.class_eval("remove_method :#{action}") # if $DBG
|
|
28
|
+
return ret
|
|
29
|
+
else
|
|
30
|
+
send(action, *args)
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class << self
|
|
38
|
+
alias __old_inherited inherited
|
|
39
|
+
|
|
40
|
+
def inherited(subclass)
|
|
41
|
+
subclass.class_eval %{
|
|
42
|
+
DEF_FILE = caller.first.split(':').first
|
|
43
|
+
}
|
|
44
|
+
__old_inherited(subclass)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
data/lib/nitro/cookie.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id$
|
|
4
|
+
|
|
5
|
+
module N
|
|
6
|
+
|
|
7
|
+
# Encapsulates a HTTP Cookie.
|
|
8
|
+
|
|
9
|
+
class Cookie
|
|
10
|
+
attr_reader :name
|
|
11
|
+
attr_accessor :value, :version
|
|
12
|
+
attr_accessor :domain, :path, :secure
|
|
13
|
+
attr_accessor :comment, :max_age
|
|
14
|
+
|
|
15
|
+
def initialize(name, value)
|
|
16
|
+
@name = name
|
|
17
|
+
@value = value
|
|
18
|
+
@version = 0 # Netscape Cookie
|
|
19
|
+
@domain = @path = @secure = @comment = @max_age =
|
|
20
|
+
@expires = @comment_url = @discard = @port = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def expires=(t)
|
|
24
|
+
@expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def expires
|
|
28
|
+
@expires && Time.parse(@expires)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_s
|
|
32
|
+
ret = ""
|
|
33
|
+
ret << @name << "=" << @value
|
|
34
|
+
ret << "; " << "Version=" << @version.to_s if @version > 0
|
|
35
|
+
ret << "; " << "Domain=" << @domain if @domain
|
|
36
|
+
ret << "; " << "Expires=" << @expires if @expires
|
|
37
|
+
ret << "; " << "Max-Age=" << @max_age.to_s if @max_age
|
|
38
|
+
ret << "; " << "Comment=" << @comment if @comment
|
|
39
|
+
ret << "; " << "Path=" << @path if @path
|
|
40
|
+
ret << "; " << "Secure" if @secure
|
|
41
|
+
ret
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|