nitro 0.1.2

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.
Files changed (119) hide show
  1. data/AUTHORS +8 -0
  2. data/ChangeLog +1546 -0
  3. data/LICENCE +32 -0
  4. data/README +278 -0
  5. data/RELEASES +7 -0
  6. data/Rakefile +79 -0
  7. data/bin/cluster.rb +219 -0
  8. data/doc/architecture.txt +28 -0
  9. data/doc/bugs.txt +7 -0
  10. data/doc/css.txt +20 -0
  11. data/doc/ideas.txt +120 -0
  12. data/doc/pg.txt +47 -0
  13. data/doc/svn.txt +82 -0
  14. data/doc/todo.txt +30 -0
  15. data/etc/new-project.rb +18 -0
  16. data/examples/simple/README +15 -0
  17. data/examples/simple/app.rb +31 -0
  18. data/examples/simple/conf/apache.conf +100 -0
  19. data/examples/simple/conf/config.rb +89 -0
  20. data/examples/simple/conf/debug-config.rb +53 -0
  21. data/examples/simple/conf/live-config.rb +48 -0
  22. data/examples/simple/conf/overrides.rb +9 -0
  23. data/examples/simple/conf/requires.rb +51 -0
  24. data/examples/simple/ctl +32 -0
  25. data/examples/simple/env.rb +33 -0
  26. data/examples/simple/install.rb +12 -0
  27. data/examples/simple/lib/articles/entities.rb +35 -0
  28. data/examples/simple/lib/articles/lc-en.rb +36 -0
  29. data/examples/simple/lib/articles/methods.rb +55 -0
  30. data/examples/simple/lib/articles/part.rb +58 -0
  31. data/examples/simple/logs/access_log +2 -0
  32. data/examples/simple/logs/apache.log +3 -0
  33. data/examples/simple/logs/app.log +1 -0
  34. data/examples/simple/logs/events.log +1 -0
  35. data/examples/simple/root/add-article.sx +15 -0
  36. data/examples/simple/root/article-form.ss +20 -0
  37. data/examples/simple/root/comments-form.ss +16 -0
  38. data/examples/simple/root/comments.si +30 -0
  39. data/examples/simple/root/index.sx +44 -0
  40. data/examples/simple/root/shader/shader.xsl +100 -0
  41. data/examples/simple/root/shader/style.css +9 -0
  42. data/examples/simple/root/view-article.sx +30 -0
  43. data/examples/tiny/app.rb +30 -0
  44. data/examples/tiny/conf/apache.conf +100 -0
  45. data/examples/tiny/conf/config.rb +67 -0
  46. data/examples/tiny/conf/requires.rb +40 -0
  47. data/examples/tiny/ctl +31 -0
  48. data/examples/tiny/logs/access_log +9 -0
  49. data/examples/tiny/logs/apache.log +9 -0
  50. data/examples/tiny/root/index.sx +35 -0
  51. data/lib/n/app/cluster.rb +219 -0
  52. data/lib/n/app/cookie.rb +86 -0
  53. data/lib/n/app/filters/autologin.rb +50 -0
  54. data/lib/n/app/fragment.rb +67 -0
  55. data/lib/n/app/handlers.rb +120 -0
  56. data/lib/n/app/handlers/code-handler.rb +184 -0
  57. data/lib/n/app/handlers/page-handler.rb +612 -0
  58. data/lib/n/app/request-part.rb +59 -0
  59. data/lib/n/app/request.rb +653 -0
  60. data/lib/n/app/script.rb +398 -0
  61. data/lib/n/app/server.rb +53 -0
  62. data/lib/n/app/session.rb +224 -0
  63. data/lib/n/app/user.rb +47 -0
  64. data/lib/n/app/webrick-servlet.rb +213 -0
  65. data/lib/n/app/webrick.rb +70 -0
  66. data/lib/n/application.rb +187 -0
  67. data/lib/n/config.rb +31 -0
  68. data/lib/n/db.rb +217 -0
  69. data/lib/n/db/README +232 -0
  70. data/lib/n/db/connection.rb +369 -0
  71. data/lib/n/db/make-release.sh +26 -0
  72. data/lib/n/db/managed.rb +235 -0
  73. data/lib/n/db/mixins.rb +282 -0
  74. data/lib/n/db/mysql.rb +342 -0
  75. data/lib/n/db/psql.rb +378 -0
  76. data/lib/n/db/tools.rb +110 -0
  77. data/lib/n/db/utils.rb +99 -0
  78. data/lib/n/events.rb +118 -0
  79. data/lib/n/l10n.rb +22 -0
  80. data/lib/n/logger.rb +33 -0
  81. data/lib/n/macros.rb +53 -0
  82. data/lib/n/mixins.rb +46 -0
  83. data/lib/n/parts.rb +154 -0
  84. data/lib/n/properties.rb +194 -0
  85. data/lib/n/server.rb +61 -0
  86. data/lib/n/server/PLAYBACK.txt +8 -0
  87. data/lib/n/server/RESEARCH.txt +13 -0
  88. data/lib/n/server/filter.rb +77 -0
  89. data/lib/n/shaders.rb +167 -0
  90. data/lib/n/sitemap.rb +188 -0
  91. data/lib/n/std.rb +69 -0
  92. data/lib/n/sync/clc.rb +108 -0
  93. data/lib/n/sync/handler.rb +221 -0
  94. data/lib/n/sync/server.rb +170 -0
  95. data/lib/n/tools/README +11 -0
  96. data/lib/n/ui/date-select.rb +74 -0
  97. data/lib/n/ui/pager.rb +187 -0
  98. data/lib/n/ui/popup.rb +45 -0
  99. data/lib/n/ui/select.rb +41 -0
  100. data/lib/n/ui/tabs.rb +34 -0
  101. data/lib/n/utils/array.rb +92 -0
  102. data/lib/n/utils/cache.rb +144 -0
  103. data/lib/n/utils/gfx.rb +108 -0
  104. data/lib/n/utils/hash.rb +148 -0
  105. data/lib/n/utils/html.rb +147 -0
  106. data/lib/n/utils/http.rb +98 -0
  107. data/lib/n/utils/mail.rb +28 -0
  108. data/lib/n/utils/number.rb +31 -0
  109. data/lib/n/utils/pool.rb +66 -0
  110. data/lib/n/utils/string.rb +297 -0
  111. data/lib/n/utils/template.rb +38 -0
  112. data/lib/n/utils/time.rb +91 -0
  113. data/lib/n/utils/uri.rb +193 -0
  114. data/lib/xsl/base.xsl +205 -0
  115. data/lib/xsl/ce.xsl +30 -0
  116. data/lib/xsl/localization.xsl +23 -0
  117. data/lib/xsl/xforms.xsl +26 -0
  118. data/test/run.rb +95 -0
  119. metadata +187 -0
@@ -0,0 +1,58 @@
1
+ # = Simple Articles part.
2
+ #
3
+ #--
4
+ # code:
5
+ # George Moschovitis <gm@navel.gr>
6
+ #
7
+ # (c) 2004 Navel, all rights reserved.
8
+ # $Id: part.rb 87 2004-10-19 17:27:45Z gmosx $
9
+ #++
10
+
11
+ require "articles/lc-en"
12
+ require "articles/entities"
13
+ require "articles/methods"
14
+
15
+ module P
16
+
17
+ class Articles < N::Part
18
+ extend P::ArticlesMethods
19
+
20
+ #
21
+ #
22
+ def initialize
23
+ @name = "articles"
24
+ @title = "Articles"
25
+ @body = "Simple articles management"
26
+ @version = "$Id: part.rb 87 2004-10-19 17:27:45Z gmosx $"
27
+ @path = ""
28
+ super
29
+ end
30
+
31
+ # Updates the sitemap by attaching site specific nodes.
32
+ #
33
+ def sitemap
34
+ n1 = N::SitePage.new "#@path/index.sx", "Articles"
35
+ n2 = N::SitePage.new "#@path/add-article.sx", "Add", n1
36
+ n2 = N::SitePage.new "#@path/view-article.sx", "View", n1
37
+ end
38
+
39
+ #
40
+ #
41
+ def rewrites
42
+ $rewrites["articles"] = {
43
+ /\/articles\/(.*?)\/index.sx/ => '/view-article.sx?oid=\1'
44
+ }
45
+ end
46
+
47
+ #
48
+ #
49
+ def roles
50
+ $roles.concat %w{articles.moderator}
51
+ end
52
+
53
+ end
54
+
55
+ end # module
56
+
57
+ a = P::Articles.instance
58
+
@@ -0,0 +1,2 @@
1
+ 127.0.0.1 - - [20/Oct/2004:16:50:41 +0300] "GET /index.sx HTTP/1.1" 200 1605
2
+ 127.0.0.1 - - [20/Oct/2004:16:50:42 +0300] "GET /favicon.ico HTTP/1.1" 404 209
@@ -0,0 +1,3 @@
1
+ [Wed Oct 20 16:50:36 2004] [warn] pid file /tmp/simple-apache.pid overwritten -- Unclean shutdown of previous Apache run?
2
+ [Wed Oct 20 16:50:36 2004] [notice] Apache/2.0.50 (Fedora) configured -- resuming normal operations
3
+ [Wed Oct 20 16:50:42 2004] [error] [client 127.0.0.1] File does not exist: /navel/nitro/examples/simple/root/favicon.ico
@@ -0,0 +1 @@
1
+ # Logfile created on Wed Oct 20 16:50:36 EEST 2004 by logger.rb/1.5.2.4
@@ -0,0 +1 @@
1
+ # Logfile created on Wed Oct 20 16:50:36 EEST 2004 by logger.rb/1.5.2.4
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <root
4
+ xmlns:x="http://www.navel.gr/xml/shader.xsd"
5
+ xmlns:xl="http://www.w3.org/1999/xlink">
6
+
7
+
8
+ <x:page>
9
+
10
+ <!-- include the form at compile time -->
11
+ <?include xl:href="article-form.ss" ?>
12
+
13
+ </x:page>
14
+
15
+ </root>
@@ -0,0 +1,20 @@
1
+ <?r
2
+ # methods:
3
+ P::Articles.add_article(request)
4
+ ?>
5
+
6
+ <form id="add_article" method="post" action="#{request.uri}">
7
+ <input type="hidden" name="add_article" value="*" />
8
+
9
+ <p>
10
+ <label for="title">|:title|</label><br />
11
+ <input type="text" name="title" style="width: 250px" />
12
+ </p>
13
+ <p>
14
+ <label for="body">|:body|</label><br />
15
+ <textarea name="body" style="width: 90%; height: 100px">#{}</textarea>
16
+ </p>
17
+
18
+ <input type="submit" value="|:store|" />
19
+ </form>
20
+
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <!-- the <?xml declaration is optional, but lets be strict. -->
4
+
5
+ <form id="comments_form" method="post" action="#{request.uri}">
6
+ <input type="hidden" name="add_comment_pid" value="#{request[:comments_parent].oid}" />
7
+ <input type="hidden" name="oid" value="#{request[:comments_parent].oid}" />
8
+
9
+ <p>
10
+ <!-- the |:...| construct is a localization macro. -->
11
+ <label for="body">|:body|</label><br />
12
+ <textarea name="body" style="width: 90%; height: 100px">#{}</textarea>
13
+ </p>
14
+
15
+ <input type="submit" value="|:store|" />
16
+ </form>
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <!-- the <?xml declaration is optional, but lets be strict. -->
4
+
5
+ <p>
6
+
7
+ <?r
8
+ # methods:
9
+ P::Articles.add_comment(request)
10
+ P::Articles.del_comment(request)
11
+
12
+ parent = request[:comments_parent]
13
+ comments = $db.children(parent, N::Comment)
14
+ ?>
15
+
16
+ <?r if comments ?>
17
+ <ul>
18
+ <?r for comment in comments ?>
19
+ <li>
20
+ <b>#{N::TimeUtils.date_time(comment.create_time)}:</b> #{comment.body}
21
+ [<a href="@?del_comment_oid=#{comment.oid}">del</a>]
22
+ </li>
23
+ <?r end ?>
24
+ </ul>
25
+ <?r end ?>
26
+
27
+ <!-- include at compile time (static include) -->
28
+ <?include xl:href="comments-form.ss" ?>
29
+
30
+ </p>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ A very simple page.
5
+ All comments are removed from the output.
6
+ This page uses XSLT because it is the prefered styling method
7
+ for Nitro applications. XSLT is used in a very trivial way in
8
+ this example. If you dont need the extra capabilities
9
+ of XSLT use a NilShader for your app.
10
+ -->
11
+
12
+ <root
13
+ xmlns:x="http://www.navel.gr/xml/shader.xsd"
14
+ xmlns:xl="http://www.w3.org/1999/xlink">
15
+
16
+ <?r
17
+ # methods:
18
+ P::Articles.del_article(request)
19
+
20
+ articles = $db.get_all(N::Article)
21
+ ?>
22
+
23
+ <!-- x:page is a trivial template, used as an example -->
24
+ <x:page>
25
+
26
+ <?r if articles ?>
27
+ <ul>
28
+ <?r for article in articles ?>
29
+ <li>
30
+ <a href="articles/#{article.oid}">#{article.title}</a>
31
+ <!-- @?... is a macro that creates a postback uri -->
32
+ [<a href="@?del_article_oid=#{article.oid}">del</a>]
33
+ </li>
34
+ <?r end ?>
35
+ </ul>
36
+ <?r end ?>
37
+
38
+ <p>
39
+ <a href="add-article.sx">Add article</a>
40
+ </p>
41
+
42
+ </x:page>
43
+
44
+ </root>
@@ -0,0 +1,100 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ A Simple Shader
5
+
6
+ code:
7
+ George Moschovitis <gm@navel.gr>
8
+
9
+ (c) 2004 Navel, all rights reserved.
10
+ $Id: shader.xsl 89 2004-10-20 12:55:58Z gmosx $
11
+ -->
12
+
13
+ <!DOCTYPE shader
14
+ [
15
+ <!ENTITY nbsp "<![CDATA[&nbsp;]]>">
16
+ <!ENTITY copy "<![CDATA[&copy;]]>">
17
+ <!ENTITY euro "<![CDATA[&euro;]]>">
18
+ <!ENTITY laquo "<![CDATA[&laquo;]]>">
19
+ <!ENTITY raquo "<![CDATA[&raquo;]]>">
20
+ ]>
21
+
22
+ <xsl:stylesheet
23
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24
+ xmlns:xl="http://www.w3.org/1999/xlink"
25
+ xmlns:x="http://www.navel.gr/xml/shader.xsd" version="1.0"
26
+ exclude-result-prefixes="x xl">
27
+
28
+ <xsl:include href="../lib/xsl/base.xsl" />
29
+
30
+ <xsl:output method="xml" indent="no" encoding="iso-8859-1" />
31
+ <xsl:strip-space elements="*" />
32
+
33
+ <!-- application templates -->
34
+
35
+ <xsl:template name="x:head">
36
+ <head>
37
+ <title>Simple #{$sitemap.str_path(request.translated_uri, lc, request[:NAVARGS])}</title>
38
+ <meta name="title" content="Simple" />
39
+ <meta name="description" content="Example" />
40
+ <meta name="keywords" content="nitro, example" />
41
+ <meta name="category" content="example" />
42
+ <meta name="robots" content="index, follow" />
43
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
44
+
45
+ <xsl:apply-templates select="x:block[@id='meta']"/>
46
+
47
+ <base href="#$srv_url/" />
48
+ <link href="/shader/style.css" rel="stylesheet" type="text/css" media="screen" />
49
+
50
+ <xsl:apply-templates select="x:cell[@id='head']"/>
51
+
52
+ <script type="text/javascript">
53
+ <xsl:comment>
54
+ <xsl:if test="x:cell[@id='script']">
55
+ <xsl:apply-templates select="x:cell[@id='script']"/>
56
+ </xsl:if>
57
+ </xsl:comment>
58
+ </script>
59
+
60
+ </head>
61
+ </xsl:template>
62
+
63
+ <xsl:template name="x:header">
64
+ #{$sitemap.linked_path(request.translated_uri, lc, request[:NAVARGS])}
65
+ </xsl:template>
66
+
67
+ <xsl:template name="x:footer">
68
+ <div id="footer">
69
+ powered by <b>Nitro</b>.
70
+ </div>
71
+ </xsl:template>
72
+
73
+ <!--
74
+ can only include x:blocks, all other templates are ignored
75
+ -->
76
+ <xsl:template match="x:page">
77
+ <html>
78
+ <xsl:call-template name="x:head" />
79
+ <body>
80
+ <h1>Simple</h1>
81
+
82
+ <div class="page">
83
+
84
+ <xsl:call-template name="x:header" />
85
+
86
+ <xsl:apply-templates select="x:cell[@id='top']" />
87
+
88
+ <div class="block main">
89
+ <xsl:apply-templates/>
90
+ </div>
91
+
92
+ <xsl:apply-templates select="x:cell[@id='bottom']" />
93
+
94
+ <xsl:call-template name="x:footer" />
95
+ </div>
96
+ </body>
97
+ </html>
98
+ </xsl:template>
99
+
100
+ </xsl:stylesheet>
@@ -0,0 +1,9 @@
1
+ blockquote {
2
+ margin: 0px;
3
+ padding: 10px;
4
+ border: 1px solid red;
5
+ }
6
+
7
+ #footer {
8
+ margin-top: 20px;
9
+ }
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <root
4
+ xmlns:x="http://www.navel.gr/xml/shader.xsd"
5
+ xmlns:xl="http://www.w3.org/1999/xlink">
6
+
7
+ <?r
8
+ oid = request["oid"]
9
+ article = $db.get(oid, N::Article)
10
+ ?>
11
+
12
+ <x:page>
13
+
14
+ <?r if article ?>
15
+ <h4>#{article.title}</h4>
16
+ <i>#{N::TimeUtils.date_time(article.create_time)}</i>
17
+ <p>
18
+ #{article.body}
19
+ </p>
20
+ <?r end ?>
21
+
22
+ <h3>Comments</h3>
23
+
24
+ <!-- include at run time (dynamic include) -->
25
+ <?r request[:comments_parent] = article ?>
26
+ <x:include xl:href="comments.si" />
27
+
28
+ </x:page>
29
+
30
+ </root>
@@ -0,0 +1,30 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ # = Tiny Example
4
+ #
5
+ # A simple Web Application to demonstrate the Engine.
6
+ #
7
+ # code:
8
+ # George Moschovitis <gm@navel.gr>
9
+ #
10
+ # (c) 2004 Navel, all rights reserved.
11
+ # $Id: app.rb 90 2004-10-20 12:56:43Z gmosx $
12
+
13
+ $:.unshift "../lib"
14
+
15
+ # Set this to false to optimize for speed.
16
+ $DBG = true
17
+
18
+ require "tiny/conf/config"
19
+ require "n/app/webrick"
20
+
21
+ module App
22
+
23
+ class Server < N::App::Webrick
24
+ include App::Config
25
+ end
26
+
27
+ end # module
28
+
29
+ $app = App::Server.new.exec()
30
+
@@ -0,0 +1,100 @@
1
+ # Apache proxy configuration
2
+ # code: gmosx, drak, elathan, ekarak
3
+
4
+ # gmosx: FIXME (optimize this!)
5
+ LoadModule access_module /usr/lib/httpd/modules/mod_access.so
6
+ LoadModule log_config_module /usr/lib/httpd/modules/mod_log_config.so
7
+ LoadModule mime_magic_module /usr/lib/httpd/modules/mod_mime_magic.so
8
+ LoadModule expires_module /usr/lib/httpd/modules/mod_expires.so
9
+ LoadModule headers_module /usr/lib/httpd/modules/mod_headers.so
10
+ LoadModule mime_module /usr/lib/httpd/modules/mod_mime.so
11
+ LoadModule status_module /usr/lib/httpd/modules/mod_status.so
12
+ LoadModule autoindex_module /usr/lib/httpd/modules/mod_autoindex.so
13
+ LoadModule vhost_alias_module /usr/lib/httpd/modules/mod_vhost_alias.so
14
+ LoadModule dir_module /usr/lib/httpd/modules/mod_dir.so
15
+ LoadModule alias_module /usr/lib/httpd/modules/mod_alias.so
16
+ LoadModule rewrite_module /usr/lib/httpd/modules/mod_rewrite.so
17
+ LoadModule proxy_module /usr/lib/httpd/modules/mod_proxy.so
18
+ LoadModule proxy_http_module /usr/lib/httpd/modules/mod_proxy_http.so
19
+ LoadModule proxy_connect_module /usr/lib/httpd/modules/mod_proxy_connect.so
20
+ LoadModule cgi_module /usr/lib/httpd/modules/mod_cgi.so
21
+
22
+ Listen 8080
23
+
24
+ User navel
25
+ Group users
26
+
27
+ PidFile /tmp/tiny-apache.pid
28
+ ErrorLog logs/apache.log
29
+ LogLevel warn
30
+
31
+ # used for debuging
32
+ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
33
+ LogFormat "%h %l %u %t \"%r\" %>s %b" common
34
+ CustomLog logs/access_log common
35
+
36
+ Timeout 300
37
+
38
+ # Keepalive
39
+
40
+ KeepAlive On
41
+ MaxKeepAliveRequests 64
42
+ KeepAliveTimeout 5
43
+
44
+ ServerTokens Off
45
+ ServerSignature Off
46
+ ExtendedStatus Off
47
+
48
+ UseCanonicalName Off
49
+ HostnameLookups Off
50
+
51
+ #DirectoryIndex index.sx
52
+
53
+ TypesConfig /etc/mime.types
54
+ DefaultType text/plain
55
+
56
+ MIMEMagicFile /etc/httpd/conf/magic
57
+
58
+ IndexOptions None
59
+
60
+ AddEncoding x-compress Z
61
+ AddEncoding x-gzip gz tgz
62
+ AddType application/x-tar .tgz
63
+ AddType image/x-icon .ico
64
+ AddType text/css .css # gmosx: needed! fixes a bug!
65
+
66
+ AddLanguage en .en
67
+ AddLanguage el .el
68
+
69
+ AddDefaultCharset ISO-8859-7
70
+
71
+ AddCharset ISO-8859-1 .iso8859-1 .latin1
72
+ AddCharset ISO-8859-7 .iso8859-7 .latin7 .grk
73
+ AddCharset UTF-8 .utf8
74
+
75
+ # enable expirations
76
+
77
+ ExpiresActive On
78
+
79
+ # expire GIF images after a month in the client's cache
80
+ ExpiresByType image/gif A2592000
81
+ ExpiresByType image/jpg A2592000
82
+ ExpiresByType image/bmp A2592000
83
+
84
+ ExpiresByType text/css A2592000
85
+ ExpiresByType text/javascript A2592000
86
+
87
+ # prefork MPM
88
+ StartServers 5
89
+ MinSpareServers 1
90
+ MaxSpareServers 7
91
+ MaxClients 50
92
+ MaxRequestsPerChild 10000
93
+
94
+ DocumentRoot "/navel/nitro/examples/tiny/root"
95
+
96
+ RewriteEngine on
97
+
98
+ RewriteRule ^/(.*[sr][bix])$ http://127.0.0.1:9090/$1 [P]
99
+ RewriteRule ^(.*)/$ http://127.0.0.1:9090$1/index.sx [P]
100
+ RewriteRule ^/([^\.]*)$ http://127.0.0.1:9090/$1/index.sx [P]