nitro 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/AUTHORS +3 -0
  2. data/ChangeLog +83 -0
  3. data/LICENCE +8 -8
  4. data/README +5 -1
  5. data/RELEASES +9 -0
  6. data/Rakefile +43 -23
  7. data/bin/cluster.rb +15 -12
  8. data/examples/ndb/README +5 -0
  9. data/examples/ndb/run.rb +271 -0
  10. data/examples/simple/README +27 -0
  11. data/examples/simple/app.rb +2 -2
  12. data/examples/simple/conf/config.rb +3 -8
  13. data/examples/simple/conf/debug-config.rb +6 -7
  14. data/examples/simple/conf/live-config.rb +2 -4
  15. data/examples/simple/conf/requires.rb +2 -10
  16. data/examples/simple/ctl +1 -1
  17. data/examples/simple/env.rb +2 -2
  18. data/examples/simple/root/article-form.ss +1 -1
  19. data/examples/simple/root/comments-form.ss +1 -1
  20. data/examples/tiny/README +15 -0
  21. data/examples/tiny/app.rb +2 -2
  22. data/examples/tiny/conf/config.rb +8 -13
  23. data/examples/tiny/conf/requires.rb +2 -8
  24. data/examples/tiny/ctl +2 -17
  25. data/examples/tiny/root/index.sx +1 -1
  26. data/lib/n/app/cluster.rb +15 -12
  27. data/lib/n/app/cookie.rb +10 -9
  28. data/lib/n/app/filters/autologin.rb +5 -4
  29. data/lib/n/app/fragment.rb +13 -10
  30. data/lib/n/app/handlers.rb +29 -22
  31. data/lib/n/app/handlers/code-handler.rb +2 -4
  32. data/lib/n/app/handlers/page-handler.rb +3 -5
  33. data/lib/n/app/request-part.rb +2 -7
  34. data/lib/n/app/request.rb +27 -22
  35. data/lib/n/app/script.rb +4 -15
  36. data/lib/n/app/server.rb +11 -7
  37. data/lib/n/app/session.rb +7 -11
  38. data/lib/n/app/user.rb +10 -11
  39. data/lib/n/app/webrick-servlet.rb +23 -10
  40. data/lib/n/app/webrick.rb +13 -10
  41. data/lib/n/application.rb +13 -6
  42. data/lib/n/config.rb +18 -7
  43. data/lib/n/db.rb +56 -40
  44. data/lib/n/db/connection.rb +18 -22
  45. data/lib/n/db/managed.rb +6 -8
  46. data/lib/n/db/mixins.rb +4 -7
  47. data/lib/n/db/mysql.rb +6 -3
  48. data/lib/n/db/psql.rb +15 -10
  49. data/lib/n/db/tools.rb +5 -9
  50. data/lib/n/db/utils.rb +11 -8
  51. data/lib/n/events.rb +14 -10
  52. data/lib/n/logger.rb +8 -2
  53. data/lib/n/macros.rb +5 -2
  54. data/lib/n/parts.rb +13 -10
  55. data/lib/n/properties.rb +17 -12
  56. data/lib/n/server.rb +3 -2
  57. data/lib/n/server/filter.rb +2 -4
  58. data/lib/n/shaders.rb +11 -13
  59. data/lib/n/sitemap.rb +23 -20
  60. data/lib/n/std.rb +15 -4
  61. data/lib/n/sync/clc.rb +4 -2
  62. data/lib/n/sync/handler.rb +20 -12
  63. data/lib/n/sync/server.rb +24 -18
  64. data/lib/n/ui/date-select.rb +2 -4
  65. data/lib/n/ui/pager.rb +10 -8
  66. data/lib/n/ui/popup.rb +5 -4
  67. data/lib/n/ui/select.rb +3 -4
  68. data/lib/n/ui/tabs.rb +3 -4
  69. data/lib/n/utils/array.rb +6 -14
  70. data/lib/n/utils/cache.rb +3 -7
  71. data/lib/n/utils/gfx.rb +5 -6
  72. data/lib/n/utils/hash.rb +7 -12
  73. data/lib/n/utils/html.rb +8 -4
  74. data/lib/n/utils/http.rb +10 -6
  75. data/lib/n/utils/mail.rb +6 -6
  76. data/lib/n/utils/number.rb +3 -4
  77. data/lib/n/utils/pool.rb +5 -8
  78. data/lib/n/utils/string.rb +12 -10
  79. data/lib/n/utils/template.rb +3 -5
  80. data/lib/n/utils/time.rb +7 -5
  81. data/lib/n/utils/uri.rb +5 -4
  82. data/lib/p/README +1 -0
  83. data/lib/xsl/xforms.xsl +2 -0
  84. data/test/n/app/tc_cookie.rb +34 -0
  85. data/test/n/app/tc_request.rb +70 -0
  86. data/test/n/app/tc_requestpart.rb +28 -0
  87. data/test/n/app/tc_session.rb +34 -0
  88. data/test/n/tc_db.rb +223 -0
  89. data/test/n/tc_db_mysql.rb +241 -0
  90. data/test/n/tc_events.rb +44 -0
  91. data/test/n/tc_properties.rb +68 -0
  92. data/test/n/tc_sitemap.rb +37 -0
  93. data/test/n/ui/tc_pager.rb +52 -0
  94. data/test/n/utils/tc_cache.rb +47 -0
  95. data/test/n/utils/tc_hash.rb +39 -0
  96. data/test/n/utils/tc_html.rb +79 -0
  97. data/test/n/utils/tc_http.rb +18 -0
  98. data/test/n/utils/tc_number.rb +21 -0
  99. data/test/n/utils/tc_strings.rb +149 -0
  100. data/test/n/utils/tc_uri.rb +100 -0
  101. metadata +49 -22
  102. data/doc/css.txt +0 -20
  103. data/doc/ideas.txt +0 -120
  104. data/doc/pg.txt +0 -47
  105. data/doc/svn.txt +0 -82
  106. data/doc/todo.txt +0 -30
  107. data/examples/simple/conf/overrides.rb +0 -9
  108. data/examples/simple/logs/access_log +0 -2
  109. data/examples/simple/logs/apache.log +0 -3
  110. data/examples/simple/logs/app.log +0 -1
  111. data/examples/simple/logs/events.log +0 -1
  112. data/examples/tiny/conf/apache.conf +0 -100
  113. data/examples/tiny/logs/access_log +0 -9
  114. data/examples/tiny/logs/apache.log +0 -9
  115. data/lib/n/db/make-release.sh +0 -26
  116. data/lib/n/tools/README +0 -11
  117. data/lib/xsl/ce.xsl +0 -30
  118. data/lib/xsl/localization.xsl +0 -23
  119. data/test/run.rb +0 -95
@@ -1,14 +1,8 @@
1
- # = Database Managed Objects
2
- #
3
- # Base Mixin for Managed Objects (Entities)
4
- #
5
- # === Design
6
- #
7
1
  # code:
8
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
9
3
  #
10
4
  # (c) 2004 Navel, all rights reserved.
11
- # $Id: managed.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: managed.rb 99 2004-10-22 09:50:28Z gmosx $
12
6
 
13
7
 
14
8
  # Extend the base Module class
@@ -53,6 +47,10 @@ require "n/properties"
53
47
  require "n/utils/array"
54
48
  require "n/utils/time"
55
49
 
50
+ # = Managed
51
+ #
52
+ # Base Mixin for Managed Objects (Entities)
53
+ #
56
54
  # The database interfaces automatically manages classes that
57
55
  # include this interface.
58
56
  #
@@ -1,16 +1,13 @@
1
1
  # = Database Managed Mixins
2
2
  #
3
- # Useful mixins for managed objects.
4
- #
5
- # === Design
6
- #
7
- # All mixins should have at least initialize(*args) to be more chainable?
3
+ # Useful mixins for synthesizing managed objects. All mixins should
4
+ # have at least initialize(*args) to be more chainable?
8
5
  #
9
6
  # code:
10
- # George Moschovitis <gm@navel.gr>
7
+ # * George Moschovitis <gm@navel.gr>
11
8
  #
12
9
  # (c) 2004 Navel, all rights reserved.
13
- # $Id: mixins.rb 71 2004-10-18 10:50:22Z gmosx $
10
+ # $Id: mixins.rb 99 2004-10-22 09:50:28Z gmosx $
14
11
 
15
12
  module N;
16
13
 
@@ -7,11 +7,11 @@
7
7
  # EXPERIMENTAL: NOT WORKING YET
8
8
  #
9
9
  # code:
10
- # George Moschovitis <gm@navel.gr>
11
10
  # Elias Athanasopoulos <elathan@navel.gr>
11
+ # George Moschovitis <gm@navel.gr>
12
12
  #
13
13
  # (c) 2004 Navel, all rights reserved.
14
- # $Id: mysql.rb 71 2004-10-18 10:50:22Z gmosx $
14
+ # $Id: mysql.rb 98 2004-10-22 07:36:20Z gmosx $
15
15
 
16
16
  require "mysql"
17
17
  require "time.rb"
@@ -19,7 +19,10 @@ require "date.rb"
19
19
 
20
20
  module N;
21
21
 
22
- # Backend specific utils
22
+ # = DbUtils
23
+ #
24
+ # Backend specific utils. Extend the base utils
25
+ # collection.
23
26
  #
24
27
  module DbUtils
25
28
 
@@ -1,21 +1,18 @@
1
- # = PostgreSQL backend
2
- #
3
- # Implement the Db backend using the PostgreSQL RDBMS.
4
- # Include the Psql backend to the standard DbConnection
5
- # object to synthesize a PsqlConnection at runtime.
6
- #
7
1
  # code:
8
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
9
3
  #
10
4
  # (c) 2004 Navel, all rights reserved.
11
5
  # $Id$
12
6
 
7
+ require "base64"
13
8
  require "postgres"
14
9
  require "time.rb"
15
10
  require "date.rb"
16
11
 
17
12
  module N;
18
13
 
14
+ # = DbUtils
15
+ #
19
16
  # Backend specific utils
20
17
  #
21
18
  module DbUtils
@@ -74,6 +71,10 @@ module DbUtils
74
71
 
75
72
  # Return an evaluator for reading the property
76
73
  # No need to optimize this, used only to precalculate code.
74
+ #--
75
+ # gmosx: base64 encoding is used because the unencode_bytea
76
+ # method of postgres is not implemented
77
+ #++
77
78
  #
78
79
  def self.read_prop(p, idx)
79
80
  case p.klass.to_s
@@ -88,11 +89,12 @@ module DbUtils
88
89
  when TrueClass.name
89
90
  return "('true' == rows.getvalue(tuple, #{idx}))"
90
91
  when Object.name
91
- return "Marshal.load(N::DbUtils.unescape_bytes(rows.getvalue(tuple, #{idx})))"
92
+ return "Marshal.load(Base64.decode64(rows.getvalue(tuple, #{idx}).gsub(/\\\\012/, '\n')))"
92
93
  when Array.name
93
- return "Marshal.load(N::DbUtils.unescape_bytes(rows.getvalue(tuple, #{idx})))"
94
+ return "Marshal.load(Base64.decode64(rows.getvalue(tuple, #{idx}).gsub(/\\\\012/, '\n')))"
95
+ # return "Marshal.load(N::DbUtils.unescape_bytes(rows.getvalue(tuple, #{idx})))"
94
96
  when Hash.name
95
- return "Marshal.load(N::DbUtils.unescape_bytes(rows.getvalue(tuple, #{idx})))"
97
+ return "Marshal.load(Base64.decode64(rows.getvalue(tuple, #{idx}).gsub(/\\\\012/, '\n')))"
96
98
  else # String
97
99
  return "rows.getvalue(tuple, #{idx})"
98
100
  end
@@ -103,6 +105,9 @@ end
103
105
  #
104
106
  # Implement the Db backend using the PostgreSQL RDBMS.
105
107
  #
108
+ # Include the Psql backend to the standard DbConnection
109
+ # object to synthesize a PsqlConnection at runtime.
110
+ #
106
111
  module PsqlBackend
107
112
 
108
113
  # map between Ruby and SQL types
@@ -1,21 +1,17 @@
1
- # = Database Tools
2
- #
3
- # Useful methods wor working with the Db BAckend
4
- #
5
1
  # code:
6
- # George Moschovitis <gm@navel.gr>
7
- # Elias Athanasopoulos <elathan@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
3
+ # * Elias Athanasopoulos <elathan@navel.gr>
8
4
  #
9
5
  # (c) 2004 Navel, all rights reserved.
10
- # $Id: tools.rb 71 2004-10-18 10:50:22Z gmosx $
6
+ # $Id: tools.rb 99 2004-10-22 09:50:28Z gmosx $
11
7
 
12
8
  module N;
13
9
 
14
10
  require "n/db"
15
11
 
16
- # = DbConnection
12
+ # = DbTools
17
13
  #
18
- # A Connection to the Database.
14
+ # Useful methods wor working with the Db BAckend
19
15
  #
20
16
  module DbTools
21
17
 
@@ -1,15 +1,14 @@
1
- # = Database Utilities
2
- #
3
- # A collection of database utilities.
4
- #
5
1
  # code:
6
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
3
+ # * Elias Athanasopoulos <elathan@navel.gr>
7
4
  #
8
5
  # (c) 2004 Navel, all rights reserved.
9
6
  # $Id$
10
7
 
11
8
  module N;
12
9
 
10
+ require "base64"
11
+
13
12
  require "n/properties"
14
13
  require "n/utils/array"
15
14
  require "n/utils/time"
@@ -39,7 +38,7 @@ module DbUtils
39
38
  # that we can convert back to the original notation if needed.
40
39
  #
41
40
  def self.sql_table(klass)
42
- return "#{klass}".gsub(/::/, "_").downcase
41
+ return "_#{klass}".gsub(/::/, "_").downcase
43
42
  end
44
43
 
45
44
  # Convert a ruby time to an sql timestamp.
@@ -70,6 +69,10 @@ module DbUtils
70
69
  # No need to optimize this, used only to precalculate code.
71
70
  #
72
71
  # FIXME: add extra handling for float.
72
+ #--
73
+ # gmosx: base64 encoding is used because the unencode_bytea
74
+ # method of postgres is not implemented
75
+ #++
73
76
  #
74
77
  def self.write_prop(p)
75
78
  if String == p.klass
@@ -80,7 +83,7 @@ module DbUtils
80
83
  return %|#\{@#{p.symbol} ? "'#\{DbUtils.sql_date(@#{p.symbol})\}'" : 'NULL'\}|
81
84
  elsif Object == p.klass or Array == p.klass or Hash == p.klass
82
85
  #return "'#\{DbUtils.escape_bytes(Marshal.dump(@#{p.symbol}))\}'"
83
- return "'#\{DbUtils.escape_bytes(Marshal.dump(@#{p.symbol}))\}'"
86
+ return "'#\{Base64.encode64(Marshal.dump(@#{p.symbol}))\}'"
84
87
  else
85
88
  # Fixnum, TrueClass
86
89
  return "#\{@#{p.symbol} || 'NULL'\}"
@@ -95,5 +98,5 @@ module DbUtils
95
98
  end
96
99
  end
97
100
 
98
- end # namespace
101
+ end # module
99
102
 
@@ -2,6 +2,18 @@
2
2
  #
3
3
  # A simple events mechanism.
4
4
  #
5
+ # code:
6
+ # George Moschovitis <gm@navel.gr>
7
+ #
8
+ # (c) 2002-2003 Navel, all rights reserved.
9
+ # $Id: events.rb 98 2004-10-22 07:36:20Z gmosx $
10
+
11
+ module N;
12
+
13
+ # = EventManager
14
+ #
15
+ # A simple events mechanism.
16
+ #
5
17
  # === Design:
6
18
  #
7
19
  # As always we try to keep the design simple:
@@ -15,15 +27,6 @@
15
27
  # Add a class of events to allow filtering of certain
16
28
  # events. Perhaps name can be used for this!
17
29
  #
18
- # code: tml
19
- #
20
- # (c) 2002-2003 Navel, all rights reserved.
21
- # $Id: events.rb 71 2004-10-18 10:50:22Z gmosx $
22
-
23
- module N;
24
-
25
- # = EventManager
26
- #
27
30
  # === Example:
28
31
  #
29
32
  # $ev.event("id/user/login", user)
@@ -101,8 +104,9 @@ class EventManager
101
104
  alias_method :fire, :event
102
105
  end
103
106
 
107
+ # = Event
104
108
  #
105
- #
109
+ # Encapsulates an Event
106
110
  #
107
111
  class Event
108
112
  @@manager = EventManager.new()
@@ -3,13 +3,19 @@
3
3
  # A simple wrapper arround the Ruby logger. Mainly for compatibility
4
4
  # purposes.
5
5
  #
6
- # code: tml
6
+ # code:
7
+ # George Moschovitis <gm@navel.gr>
7
8
  #
8
9
  # (c) 2004 Navel, all rights reserved.
9
- # $Id: logger.rb 71 2004-10-18 10:50:22Z gmosx $
10
+ # $Id: logger.rb 98 2004-10-22 07:36:20Z gmosx $
10
11
 
11
12
  require "logger"
12
13
 
14
+ # = Logger
15
+ #
16
+ # A simple wrapper arround the Ruby logger. Mainly for compatibility
17
+ # purposes.
18
+ #
13
19
  class Logger
14
20
  alias_method :devel, :debug
15
21
  alias_method :fine, :debug
@@ -3,10 +3,13 @@
3
3
  # A powerfull macro implementation for Ruby. Allows definition
4
4
  # of new macro.
5
5
  #
6
- # code: gmosx
6
+ # EXPERIMENTAL, not fully working yet
7
+ #
8
+ # code:
9
+ # George Moschovitis <gm@navel.gr>
7
10
  #
8
11
  # (c) 2004 Navel, all rights reserved.
9
- # $Id: macros.rb 71 2004-10-18 10:50:22Z gmosx $
12
+ # $Id: macros.rb 98 2004-10-22 07:36:20Z gmosx $
10
13
 
11
14
  $__macros__ = {}
12
15
  $__required__ = {}
@@ -1,12 +1,8 @@
1
- # = Part
2
- #
3
- # A part encapsulates a service in the Framework.
4
- #
5
1
  # code:
6
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
7
3
  #
8
4
  # (c) 2004 Navel, all rights reserved.
9
- # $Id: parts.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: parts.rb 99 2004-10-22 09:50:28Z gmosx $
10
6
 
11
7
  require "singleton"
12
8
 
@@ -108,12 +104,14 @@ class Part
108
104
  def unistall
109
105
  end
110
106
 
111
- #
107
+ # This method is called when the application
108
+ # is started.
112
109
  #
113
110
  def start
114
111
  end
115
112
 
116
- #
113
+ # This method is called when the application
114
+ # is stopped.
117
115
  #
118
116
  def stop
119
117
  end
@@ -139,7 +137,7 @@ class Part
139
137
  def prepared_statements
140
138
  end
141
139
 
142
- #
140
+ # Dump this part as s String.
143
141
  #
144
142
  def to_s
145
143
  @name
@@ -148,7 +146,12 @@ end
148
146
 
149
147
  end # module
150
148
 
151
- # Namespace for parts.
149
+ # = P
150
+ #
151
+ # This module is used as a namespace that encapsulates
152
+ # the Application Parts defined on top of the engine.
152
153
  #
153
154
  module P
154
155
  end # module
156
+
157
+
@@ -1,5 +1,21 @@
1
1
  # = Properties support
2
2
  #
3
+ # code:
4
+ # George Moschovitis <gm@navel.gr>
5
+ # design:
6
+ # Anastastios Koutoumanos <ak@navel.gr>
7
+ # Elias Karakoulakis <ekarak@ktismata.com>
8
+ #
9
+ # (c) 2004 Navel, all rights reserved.
10
+ # $Id: properties.rb 98 2004-10-22 07:36:20Z gmosx $
11
+
12
+ require "n/utils/array"
13
+ require "n/utils/hash"
14
+
15
+ module N
16
+
17
+ # Property Metadata
18
+ #
3
19
  # Ruby attributes are typeless and generally this is good. Some times
4
20
  # we need extra metadata though, for example in relational mapping, or
5
21
  # web form population.
@@ -12,19 +28,8 @@
12
28
  # TODO:
13
29
  # Perhaps a sync is needed in evals (!!!!)
14
30
  #
15
- # code: gmosx, drak, ekarak
16
- #
17
- # (c) 2004 Navel, all rights reserved.
18
- # $Id: properties.rb 71 2004-10-18 10:50:22Z gmosx $
19
-
20
- require "n/utils/array"
21
- require "n/utils/hash"
22
-
23
- module N
24
-
25
- # Property Metadata
26
- #
27
31
  # === Design:
32
+ #
28
33
  # - add default value in the extra sql
29
34
  #
30
35
  class Property
@@ -2,10 +2,11 @@
2
2
  #
3
3
  # Generic server infrastructure
4
4
  #
5
- # code:: gmosx
5
+ # code:
6
+ # George Moschovitis <gm@navel.gr>
6
7
  #
7
8
  # (c) 2004 Navel, all rights reserved.
8
- # $Id: server.rb 71 2004-10-18 10:50:22Z gmosx $
9
+ # $Id: server.rb 98 2004-10-22 07:36:20Z gmosx $
9
10
 
10
11
  require "n/application"
11
12
 
@@ -1,10 +1,8 @@
1
- # = Server filter
2
- #
3
1
  # code:
4
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
5
3
  #
6
4
  # (c) 20024 Navel, all rights reserved.
7
- # $Id: filter.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: filter.rb 99 2004-10-22 09:50:28Z gmosx $
8
6
 
9
7
  require "socket"
10
8
  require "thread"
@@ -1,3 +1,11 @@
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
3
+ #
4
+ # (c) 2004 Navel, all rights reserved.
5
+ # $Id: shaders.rb 99 2004-10-22 09:50:28Z gmosx $
6
+
7
+ module N;
8
+
1
9
  # = Shader
2
10
  #
3
11
  # The equivalent of a 3d engine shader. Converts the page representation
@@ -32,16 +40,6 @@
32
40
  #
33
41
  # - add monitoring support for xsl's.
34
42
  #
35
- # code:
36
- # George Moschovitis <gm@navel.gr>
37
- #
38
- # (c) 2004 Navel, all rights reserved.
39
- # $Id: shaders.rb 89 2004-10-20 12:55:58Z gmosx $
40
-
41
- module N;
42
-
43
- # = Shader
44
- #
45
43
  # One shader can utilize several xsls to render different pages.
46
44
  # the shader selection may be time consuming but is performed once
47
45
  # when transforming the script, so its essentially for free (and
@@ -99,9 +97,9 @@ end
99
97
 
100
98
  # = NilShader
101
99
  #
102
- # A shader that does absolutely nothing.
103
- #
104
- # === WARNING: not tested.
100
+ # A shader that does absolutely nothing. Typically
101
+ # used when you want to avoid XSLT in simple
102
+ # applications.
105
103
  #
106
104
  class NilShader < Shader
107
105
  def initialize