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,128 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id: nitro.rb 167 2004-11-23 14:03:10Z gmosx $
|
|
4
|
+
|
|
5
|
+
module N
|
|
6
|
+
|
|
7
|
+
# Encapsulates a request. This is an abstract request
|
|
8
|
+
# typically extended by sub-classes.
|
|
9
|
+
|
|
10
|
+
module Request
|
|
11
|
+
|
|
12
|
+
# The request input stream.
|
|
13
|
+
|
|
14
|
+
attr_accessor :in
|
|
15
|
+
|
|
16
|
+
# The request headers collection. Also called
|
|
17
|
+
# the request environment (env).
|
|
18
|
+
|
|
19
|
+
attr_accessor :headers
|
|
20
|
+
alias_method :env, :headers
|
|
21
|
+
alias_method :env=, :headers=
|
|
22
|
+
# for compatibility with cgi.rb
|
|
23
|
+
alias_method :env_table, :headers
|
|
24
|
+
|
|
25
|
+
# The parsed query parameters collection.
|
|
26
|
+
|
|
27
|
+
attr_accessor :params
|
|
28
|
+
alias_method :query, :params
|
|
29
|
+
|
|
30
|
+
# The request cookies.
|
|
31
|
+
|
|
32
|
+
attr_accessor :cookies
|
|
33
|
+
|
|
34
|
+
# The request protocol.
|
|
35
|
+
|
|
36
|
+
def protocol
|
|
37
|
+
443 == port ? 'https://' : 'http://'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Is this an ssl request?
|
|
41
|
+
|
|
42
|
+
def ssl?
|
|
43
|
+
443 == port
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The request uri.
|
|
47
|
+
|
|
48
|
+
def uri
|
|
49
|
+
@headers['REQUEST_URI']
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# The path is the uri without the query string.
|
|
53
|
+
|
|
54
|
+
def path
|
|
55
|
+
uri ? uri.split('?').first : ''
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The request query string.
|
|
59
|
+
|
|
60
|
+
def query_string
|
|
61
|
+
@headers['QUERY_STRING']
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# The request method.
|
|
65
|
+
|
|
66
|
+
def method
|
|
67
|
+
@headers['REQUEST_METHOD'].downcase.intern
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Return the referer. For the initial page in the
|
|
71
|
+
# clickstream there is no referer, set "/" by default.
|
|
72
|
+
|
|
73
|
+
def referer
|
|
74
|
+
return @headers['REFERER'] || '/'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# The remote IP address. REMOTE_ADDR is the standard
|
|
78
|
+
# but will fail if the user is behind a proxy.
|
|
79
|
+
# HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by
|
|
80
|
+
# proxies so check for these before falling back to
|
|
81
|
+
# REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma-delimited
|
|
82
|
+
# list in the case of multiple chained proxies; the first
|
|
83
|
+
# is the originating IP.
|
|
84
|
+
|
|
85
|
+
def remote_ip
|
|
86
|
+
return @headers['HTTP_CLIENT_IP'] if @headers.include?('HTTP_CLIENT_IP')
|
|
87
|
+
|
|
88
|
+
if @headers.include?('HTTP_X_FORWARDED_FOR') then
|
|
89
|
+
remote_ips = @headers['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
|
|
90
|
+
ip =~ /^unknown$|^(10|172\.16|192\.168)\./i
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
return remote_ips.first.strip unless remote_ips.empty?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
return @headers['REMOTE_ADDR']
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# The server port.
|
|
100
|
+
|
|
101
|
+
def port
|
|
102
|
+
@headers['SERVER_PORT'].to_i
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The server host name.
|
|
106
|
+
|
|
107
|
+
def host
|
|
108
|
+
@headers['HTTP_HOST']
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def host_url
|
|
112
|
+
"http://#{host}"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Lookup a query parameter.
|
|
116
|
+
|
|
117
|
+
def [](param)
|
|
118
|
+
@params[param]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Set a query parameter.
|
|
122
|
+
|
|
123
|
+
def []=(param, value)
|
|
124
|
+
@params[param] = value
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id: nitro.rb 167 2004-11-23 14:03:10Z gmosx $
|
|
4
|
+
|
|
5
|
+
module N
|
|
6
|
+
|
|
7
|
+
# HTTP Response.
|
|
8
|
+
|
|
9
|
+
module Response
|
|
10
|
+
|
|
11
|
+
# The Response status.
|
|
12
|
+
|
|
13
|
+
attr_accessor :status
|
|
14
|
+
|
|
15
|
+
# The Response headers.
|
|
16
|
+
|
|
17
|
+
attr_accessor :response_headers
|
|
18
|
+
|
|
19
|
+
# The Response cookies.
|
|
20
|
+
|
|
21
|
+
attr_accessor :response_cookies
|
|
22
|
+
|
|
23
|
+
def content_type=(ctype)
|
|
24
|
+
@response_headers['Content-Type'] = ctype
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Add a cookie to the response. Better use this
|
|
28
|
+
# method to avoid precreating the cookies array
|
|
29
|
+
# for every request.
|
|
30
|
+
|
|
31
|
+
def add_cookie(cookie)
|
|
32
|
+
(@response_cookies ||= []) << cookie
|
|
33
|
+
end
|
|
34
|
+
alias_method :send_cookie, :add_cookie
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
data/lib/nitro/scaffold.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
# code:
|
|
2
1
|
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# $Id: scaffold.rb 175 2004-11-26 16:11:27Z gmosx $
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id: scaffold.rb 248 2005-01-31 13:38:34Z gmosx $
|
|
6
4
|
|
|
7
5
|
require 'glue/inflector'
|
|
8
6
|
|
|
@@ -10,18 +8,19 @@ module N
|
|
|
10
8
|
|
|
11
9
|
module Scaffolding
|
|
12
10
|
|
|
13
|
-
# Ruby is sometimes VERY surprising, the following trick is
|
|
14
|
-
# to include singleton methods in other classes.
|
|
15
|
-
|
|
11
|
+
# Ruby is sometimes VERY surprising, the following trick is
|
|
12
|
+
# needed to include singleton methods in other classes.
|
|
13
|
+
|
|
16
14
|
def self.append_features(base)
|
|
17
15
|
super
|
|
18
16
|
base.extend(SingletonMethods)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
module SingletonMethods
|
|
20
|
+
|
|
22
21
|
# Enchant the caller with a number of default methods.
|
|
23
22
|
# Override the automatically generated methods as needed.
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
def scaffold(klass, options = {})
|
|
26
25
|
|
|
27
26
|
oid = options[:oid] || 'oid'
|
|
@@ -54,19 +53,20 @@ module Scaffolding
|
|
|
54
53
|
module_eval <<-"end_eval", __FILE__, __LINE__
|
|
55
54
|
|
|
56
55
|
# TODO: add pager support here!
|
|
56
|
+
|
|
57
57
|
def list#{suffix}
|
|
58
58
|
@#{list_name} = #{klass}.all('ORDER BY oid')
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def view#{suffix}
|
|
62
|
-
@#{name} = #{klass}[@
|
|
62
|
+
@#{name} = #{klass}[@context['#{oid}']]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def save#{suffix}
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def del#{suffix}
|
|
69
|
-
#{klass}.delete(@
|
|
69
|
+
#{klass}.delete(@context['#{oid}'])
|
|
70
70
|
end
|
|
71
71
|
alias_method :delete#{suffix}, :del#{suffix}
|
|
72
72
|
|
|
@@ -77,4 +77,4 @@ module Scaffolding
|
|
|
77
77
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
3
|
+
# $Id$
|
|
4
|
+
|
|
5
|
+
require 'md5'
|
|
6
|
+
require 'webrick'
|
|
7
|
+
|
|
8
|
+
require 'glue/attribute'
|
|
9
|
+
|
|
10
|
+
require 'nitro/cookie'
|
|
11
|
+
|
|
12
|
+
module N
|
|
13
|
+
|
|
14
|
+
# A web application session.
|
|
15
|
+
#
|
|
16
|
+
# State is a neccessary evil but session variables should
|
|
17
|
+
# be avoided as much as possible. Session state is typically
|
|
18
|
+
# distributed to many servers so avoid storing complete
|
|
19
|
+
# objects in session variables, only store oids and small
|
|
20
|
+
# integer/strings.
|
|
21
|
+
#
|
|
22
|
+
# The session should be persistable to survive server
|
|
23
|
+
# shutdowns.
|
|
24
|
+
|
|
25
|
+
class Session < Hash
|
|
26
|
+
|
|
27
|
+
# Session id salt.
|
|
28
|
+
|
|
29
|
+
cattr_accessor :session_id_salt, 'SALT'
|
|
30
|
+
|
|
31
|
+
# The name of the cookie that stores the session id.
|
|
32
|
+
|
|
33
|
+
cattr_accessor :cookie_name, 'nsid'
|
|
34
|
+
|
|
35
|
+
# The sessions
|
|
36
|
+
|
|
37
|
+
cattr_accessor :manager; @@manager = {}
|
|
38
|
+
|
|
39
|
+
# The unique id of this session.
|
|
40
|
+
|
|
41
|
+
attr_reader :session_id
|
|
42
|
+
|
|
43
|
+
def self.lookup(context)
|
|
44
|
+
if cookie = context.cookies[Session.cookie_name]
|
|
45
|
+
session = context.sessions[cookie]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
unless session
|
|
49
|
+
session = Session.new(context)
|
|
50
|
+
context.add_cookie(Cookie.new(Session.cookie_name, session.session_id))
|
|
51
|
+
context.sessions[session.session_id] = session
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return session
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Create the session for the given context.
|
|
58
|
+
|
|
59
|
+
def initialize(context = nil)
|
|
60
|
+
@session_id = create_id
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
protected
|
|
64
|
+
|
|
65
|
+
# Calculates a unique id.
|
|
66
|
+
#
|
|
67
|
+
# The session id must be unique, a monotonically
|
|
68
|
+
# increasing function like time is appropriate. Random
|
|
69
|
+
# may produce equal ids? add a prefix (SALT) to stop
|
|
70
|
+
# hackers from creating session_ids.
|
|
71
|
+
|
|
72
|
+
def create_id
|
|
73
|
+
now = Time.now
|
|
74
|
+
md5 = Digest::MD5.new
|
|
75
|
+
md5.update(now.to_s)
|
|
76
|
+
md5.update(now.usec.to_s)
|
|
77
|
+
md5.update(rand(0).to_s)
|
|
78
|
+
md5.update(Session.session_id_salt)
|
|
79
|
+
md5.hexdigest
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
1
|
+
#--
|
|
2
|
+
# George Moschovitis <gm@navel.gr>
|
|
3
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
|
4
|
+
# $Id: shaders.rb 202 2005-01-17 10:44:13Z gmosx $
|
|
5
|
+
#++
|
|
6
6
|
|
|
7
7
|
module N
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
# transformation-pipeline that tansforms the .xhtml files to actual
|
|
13
|
-
# ruby code ready for evaluation (compilation) by the engine.
|
|
9
|
+
# A shader defines a transformation-pipeline that tansforms
|
|
10
|
+
# the .xhtml files to actual ruby code ready for evaluation
|
|
11
|
+
# (compilation) by the engine.
|
|
14
12
|
#
|
|
15
13
|
# Shaders are equivalend to the render-pipeline filters, ie they
|
|
16
14
|
# share their folded-filter design.
|
|
17
15
|
#--
|
|
18
16
|
# TODO: pipeline stage mixin to be reused in filters too.
|
|
19
17
|
#++
|
|
20
|
-
|
|
18
|
+
|
|
21
19
|
class Shader
|
|
20
|
+
|
|
22
21
|
# the next stage in the Shader pipeline.
|
|
22
|
+
|
|
23
23
|
attr :next_stage
|
|
24
24
|
|
|
25
25
|
def initialize(next_stage = nil)
|
|
@@ -29,20 +29,20 @@ class Shader
|
|
|
29
29
|
# Process the text and optionally update the hash.
|
|
30
30
|
# The hash is a short, unique representation of the input text,
|
|
31
31
|
# typically used as a caching key.
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
def process(hash, text)
|
|
34
34
|
process_next(hash, text)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
# Set the next stage of the pipeline.
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
def << (next_stage = nil)
|
|
40
40
|
@next_stage = next_stage
|
|
41
41
|
return self
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# Process the next stage of the pipeline.
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
def process_next(hash, text)
|
|
47
47
|
if @next_stage
|
|
48
48
|
return @next_stage.process(hash, text)
|
|
@@ -52,12 +52,10 @@ class Shader
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
# = RubyShader
|
|
56
|
-
#
|
|
57
55
|
# Convert the xhtml script to actual Ruby code, ready to be
|
|
58
56
|
# evaluated.
|
|
59
|
-
|
|
60
|
-
class RubyShader <
|
|
57
|
+
|
|
58
|
+
class RubyShader < Shader
|
|
61
59
|
|
|
62
60
|
# Convert the xhtml script to actual Ruby code, ready to be
|
|
63
61
|
# evaluated.
|
|
@@ -66,19 +64,19 @@ class RubyShader < N::Shader
|
|
|
66
64
|
# Investigate:
|
|
67
65
|
# perhaps xl:href should be used to be XLink compatible?
|
|
68
66
|
#++
|
|
69
|
-
|
|
67
|
+
|
|
70
68
|
def process(hash, text)
|
|
71
69
|
# strip the xml header! (interracts with the following gsub!)
|
|
72
70
|
text.gsub!(/<\?xml.*\?>/, "")
|
|
73
71
|
|
|
74
|
-
#
|
|
72
|
+
# Statically include sub script files.
|
|
75
73
|
# The target file is included at compile time.
|
|
76
74
|
#
|
|
77
75
|
# gmosx: must be xformed before the <?r pi.
|
|
78
76
|
#
|
|
79
77
|
# Example:
|
|
80
78
|
# <?include xl:href="root/myfile.sx" ?>
|
|
81
|
-
|
|
79
|
+
|
|
82
80
|
text.gsub!(/<\?include href="(.*?)"(.*)\?>/) { |match|
|
|
83
81
|
# gmosx: xmm match matches the whole string.
|
|
84
82
|
# match = overload_path($1)
|
|
@@ -87,23 +85,41 @@ class RubyShader < N::Shader
|
|
|
87
85
|
|
|
88
86
|
# xform include instructions <include href="xxx" />
|
|
89
87
|
# must be transformed before the processinc instructions.
|
|
88
|
+
# Useful to include fragments cached on disk
|
|
89
|
+
#
|
|
90
|
+
# gmosx, FIXME: NOT TESTED! test and add caching.
|
|
91
|
+
# add load_statically_included fixes.
|
|
92
|
+
|
|
90
93
|
text.gsub!(/<include href="(.*?)"(.*)(.?)\/>/) { |match|
|
|
94
|
+
"<?r File.read( '\#\{@dispatcher.root\}/#$1' ?>"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# xform render/inject instructions <render href="xxx" />
|
|
98
|
+
# must be transformed before the processinc instructions.
|
|
99
|
+
|
|
100
|
+
text.gsub!(/<inject href="(.*?)"(.*)(.?)\/>/) { |match|
|
|
101
|
+
"<?r render '/#$1' ?>"
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
text.gsub!(/<render href="(.*?)"(.*)(.?)\/>/) { |match|
|
|
91
105
|
"<?r render '/#$1' ?>"
|
|
92
106
|
}
|
|
93
107
|
|
|
94
108
|
# remove <root> elements. typically removed by xslt but lets
|
|
95
109
|
# play it safe.
|
|
110
|
+
|
|
96
111
|
text.gsub!(/<(\/)?root>/, '')
|
|
97
112
|
|
|
98
113
|
# runtime ruby code.
|
|
99
114
|
|
|
100
115
|
# xform the processing instructions, use <?r as
|
|
101
116
|
# a marker.
|
|
117
|
+
|
|
102
118
|
text.gsub!(/\?>/, "\n@out << %^")
|
|
103
119
|
text.gsub!(/<\?r(\s?)/, "^\n")
|
|
104
120
|
|
|
105
121
|
# xform alternative code tags (very useful in xsl stylesheets)
|
|
106
|
-
|
|
122
|
+
|
|
107
123
|
text.gsub!(/<\/ruby>/, "\n@out << %^")
|
|
108
124
|
text.gsub!(/<ruby>/, "^\n")
|
|
109
125
|
|
|
@@ -120,7 +136,7 @@ class RubyShader < N::Shader
|
|
|
120
136
|
end
|
|
121
137
|
|
|
122
138
|
# Loads and statically includes a file.
|
|
123
|
-
|
|
139
|
+
|
|
124
140
|
def load_statically_included(filename)
|
|
125
141
|
Logger.debug "Statically including '#{filename}'" if $DBG
|
|
126
142
|
|
|
@@ -134,20 +150,26 @@ class RubyShader < N::Shader
|
|
|
134
150
|
|
|
135
151
|
end
|
|
136
152
|
|
|
137
|
-
# = XSLTShader
|
|
138
|
-
#
|
|
139
153
|
# Apply an XSL transformation to the script code.
|
|
140
154
|
# There is no need to keep post xsl. I can reuse the same xsl
|
|
141
155
|
# by calling transform again.
|
|
142
|
-
|
|
143
|
-
class XSLTShader <
|
|
156
|
+
|
|
157
|
+
class XSLTShader < Shader
|
|
158
|
+
|
|
144
159
|
# The name
|
|
160
|
+
|
|
145
161
|
attr :name
|
|
162
|
+
|
|
146
163
|
# The xslt filename.
|
|
164
|
+
|
|
147
165
|
attr :xsl_filename
|
|
166
|
+
|
|
148
167
|
# The xslt transformer.
|
|
168
|
+
|
|
149
169
|
attr :xslt
|
|
170
|
+
|
|
150
171
|
# Last modified time of the xslt.
|
|
172
|
+
|
|
151
173
|
attr :mtime
|
|
152
174
|
|
|
153
175
|
def initialize(xsl_filename, next_stage = nil)
|
|
@@ -161,8 +183,8 @@ class XSLTShader < N::Shader
|
|
|
161
183
|
@next_stage = next_stage
|
|
162
184
|
end
|
|
163
185
|
|
|
164
|
-
# Transform the given text
|
|
165
|
-
|
|
186
|
+
# Transform the given text.
|
|
187
|
+
|
|
166
188
|
def process(hash, text)
|
|
167
189
|
parse_xsl()
|
|
168
190
|
@xslt.xml = text
|
|
@@ -174,7 +196,7 @@ class XSLTShader < N::Shader
|
|
|
174
196
|
private
|
|
175
197
|
|
|
176
198
|
# Parse the xsl.
|
|
177
|
-
|
|
199
|
+
|
|
178
200
|
def parse_xsl
|
|
179
201
|
Logger.debug "Parsing xsl '#{@xsl_filename}'" if $DBG
|
|
180
202
|
@mtime = File.mtime(@xsl_filename)
|
|
@@ -183,14 +205,12 @@ class XSLTShader < N::Shader
|
|
|
183
205
|
|
|
184
206
|
end
|
|
185
207
|
|
|
186
|
-
# = CompressShader
|
|
187
|
-
#
|
|
188
208
|
# Compress the inline xhtml. Does not touch the ruby code.
|
|
189
|
-
|
|
190
|
-
class CompressShader <
|
|
209
|
+
|
|
210
|
+
class CompressShader < Shader
|
|
191
211
|
|
|
192
212
|
# Compress the inline xhtml. Does not touch the ruby code.
|
|
193
|
-
|
|
213
|
+
|
|
194
214
|
def process(hash, text)
|
|
195
215
|
text.gsub!(/\@out \<\< \%\^(.*?)\^/m) do |match|
|
|
196
216
|
c = $1.gsub(/^(\s*)/m, '').squeeze(" \t").tr("\n", '').tr("\t", ' ')
|
|
@@ -202,5 +222,5 @@ class CompressShader < N::Shader
|
|
|
202
222
|
|
|
203
223
|
end
|
|
204
224
|
|
|
205
|
-
end
|
|
225
|
+
end
|
|
206
226
|
|