nitro 0.1.2 → 0.2.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.
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
@@ -2,27 +2,11 @@
2
2
  #
3
3
  # Encapsulates the page structure and additional metadata.
4
4
  #
5
- # === TODO:
6
- #
7
- # move out of the UI namespace.
8
- # include url remapping functionality.
9
- #
10
- # === Design
11
- #
12
- # Unlike the original version, this is presentation agnostic, and
13
- # greatly simplified.
14
- #
15
- # === Todo:
16
- #
17
- # - support strings as titles.
18
- # - add support to read the map from a config file.
19
- # - rename to appmap ?
20
- #
21
5
  # code:
22
6
  # George Moschovitis <gm@navel.gr>
23
7
  #
24
8
  # (c) 2004 Navel, all rights reserved.
25
- # $Id: sitemap.rb 71 2004-10-18 10:50:22Z gmosx $
9
+ # $Id: sitemap.rb 98 2004-10-22 07:36:20Z gmosx $
26
10
 
27
11
  require "n/utils/hash"
28
12
 
@@ -30,11 +14,14 @@ module N
30
14
 
31
15
  # = SitePage
32
16
  #
17
+ # A single page in the page map.
18
+ #
33
19
  class SitePage
34
20
  # the uri for this page
35
21
  attr_accessor :uri
36
22
  # the real uri to this page calculated by the page overloader)
37
23
  attr_accessor :real_uri
24
+ # the realm this page belongs to
38
25
  attr_accessor :realm
39
26
  # the shader for this page, overrided the shader calculated
40
27
  # by the engine
@@ -77,10 +64,26 @@ class SitePage
77
64
  end
78
65
 
79
66
  # = SiteMap
80
- #
67
+ #
68
+ # Encapsulates the page structure and additional metadata.
69
+ #
81
70
  # === TODO:
82
- # Use a second class in the UI namespace for rendering
83
- # related stuff?
71
+ #
72
+ # move out of the UI namespace.
73
+ # include url remapping functionality.
74
+ #
75
+ # === Design
76
+ #
77
+ # Unlike the original version, this is presentation agnostic, and
78
+ # greatly simplified.
79
+ #
80
+ # === Todo:
81
+ #
82
+ # - support strings as titles.
83
+ # - add support to read the map from a config file.
84
+ # - rename to appmap ?
85
+ # - Use a second class in the UI namespace for rendering
86
+ # related stuff?
84
87
  #
85
88
  class SiteMap < N::SafeHash
86
89
 
@@ -1,9 +1,12 @@
1
- # = Navel Software Technology
1
+ # = Nitro standard require
2
2
  #
3
- # code: gmosx, drak, ekarak
3
+ # General utilities. Typically included in all Nitro applications.
4
4
  #
5
- # (c) 2001-2004 Navel, all rights reserved.
6
- # $Id: std.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # code:
6
+ # * George Moschovitis <gm@navel.gr>
7
+ #
8
+ # (c) 2004 Navel, all rights reserved.
9
+ # $Id: std.rb 99 2004-10-22 09:50:28Z gmosx $
7
10
 
8
11
  # we want readable code
9
12
 
@@ -59,6 +62,14 @@ end
59
62
 
60
63
  EMPTY_STRING = ""
61
64
 
65
+ # = N
66
+ #
67
+ # This module is used as a namespace that encapsulates
68
+ # engine objects.
69
+ #
70
+ module N
71
+ end # module
72
+
62
73
  # This the default 72 chars separator, copy paste to use it
63
74
  # in your source file. Btw all lines in your source file should
64
75
  # be less than 72 chars. So you can use this as a ruler if your
@@ -2,10 +2,12 @@
2
2
 
3
3
  # = A Command Line Client (clc) for the Sync Server
4
4
  #
5
- # code: tml, drak
5
+ # code:
6
+ # * Anastasios Koutoumanos <ak@navel.gr>
7
+ # * George Moschovitis <gm@navel.gr>
6
8
  #
7
9
  # (c) 2004 Navel, all rights reserved.
8
- # $Id: clc.rb 71 2004-10-18 10:50:22Z gmosx $
10
+ # $Id: clc.rb 101 2004-10-22 12:35:39Z gmosx $
9
11
 
10
12
  require "logger"
11
13
  require "socket"
@@ -1,14 +1,9 @@
1
- # = Synchronous Handler
2
- #
3
- # === Design:
4
- #
5
- # A handler can act as a multiplexer to implement multiple services
6
- # per server.
7
- #
8
- # code: tml, drak
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
3
+ # * Anastasios Koutoumanos <ak@navel.gr>
9
4
  #
10
5
  # (c) 2004 Navel, all rights reserved.
11
- # $Id: handler.rb 71 2004-10-18 10:50:22Z gmosx $
6
+ # $Id: handler.rb 101 2004-10-22 12:35:39Z gmosx $
12
7
 
13
8
  require "timeout"
14
9
  require "n/server"
@@ -17,9 +12,14 @@ module N; module Sync
17
12
 
18
13
  class HandlerExitException < Exception; end
19
14
 
20
- # = Worker
15
+ # = Handler
16
+ #
17
+ # Sync Server Handler
18
+ #
19
+ # === Design:
21
20
  #
22
- # Override this to create your worker.
21
+ # Override this to create your handler. A handler can
22
+ # act as a multiplexer to implement multiple services per server.
23
23
  #
24
24
  class Handler
25
25
  SEPARATOR = "\000"
@@ -45,11 +45,15 @@ class Handler
45
45
  @server, @socket = server, socket
46
46
  end
47
47
 
48
+ # Called when the handler starts.
49
+ #
48
50
  def start
49
51
  touch!
50
52
  @thread = Thread.new(&method("run").to_proc)
51
53
  end
52
54
 
55
+ # Called when the handler stops.
56
+ #
53
57
  def stop
54
58
  unless STATUS_STOPPED == @status
55
59
  @status = STATUS_STOPPED
@@ -75,6 +79,8 @@ class Handler
75
79
  @thread.raise HandlerExitException.new()
76
80
  end
77
81
 
82
+ # Perform the handler's action.
83
+ #
78
84
  def run
79
85
  @status = STATUS_RUNNING
80
86
 
@@ -207,7 +213,9 @@ class Handler
207
213
 
208
214
  # ------------------------------------------------------------------
209
215
  # Commands
210
-
216
+
217
+ # A sample command
218
+ #
211
219
  def cmd_ping(args)
212
220
  cmd = %{<pong time="#{Time.now}"}
213
221
  cmd += %{ challenge="#{args[:challenge]}"} if args
@@ -1,23 +1,9 @@
1
- # = Syncrhronous Server
2
- #
3
- # === Design:
4
- #
5
- # Should support clustered operation: A cluster of servers is spawned.
6
- # The client connects to one of the servers at random. The client sticks
7
- # to the server. Each server considers the others as clients and
8
- # rebroadcasts all the events.
9
- #
10
- # We keep one service per server for simplicity, if we need multiple
11
- # services we can implement a multiplexer service (handler).
12
- #
13
- # === TODO:
14
- #
15
- # - Investigate if this server can be done with select.
16
- #
17
- # code: gmosx, drak
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
3
+ # * Anastasios Koutoumanos <ak@navel.gr>
18
4
  #
19
5
  # (c) 2004 Navel, all rights reserved.
20
- # $Id: server.rb 71 2004-10-18 10:50:22Z gmosx $
6
+ # $Id: server.rb 101 2004-10-22 12:35:39Z gmosx $
21
7
 
22
8
  require "thread"
23
9
  require "socket"
@@ -41,6 +27,20 @@ module N; module Sync
41
27
  # marker. NO: the XML protocol is not really appropriate, better use
42
28
  # a space optimized delimited ASCII protocol.
43
29
  #
30
+ # === Design:
31
+ #
32
+ # Should support clustered operation: A cluster of servers is spawned.
33
+ # The client connects to one of the servers at random. The client sticks
34
+ # to the server. Each server considers the others as clients and
35
+ # rebroadcasts all the events.
36
+ #
37
+ # We keep one service per server for simplicity, if we need multiple
38
+ # services we can implement a multiplexer service (handler).
39
+ #
40
+ # === TODO:
41
+ #
42
+ # - Investigate if this server can be done with select.
43
+ #
44
44
  class Server < N::Application
45
45
  MONITOR_INTERVAL = 2 * 60
46
46
 
@@ -78,6 +78,8 @@ class Server < N::Application
78
78
  super()
79
79
  end
80
80
 
81
+ # Start the server.
82
+ #
81
83
  def start()
82
84
  # a single tcp server accepts all tcp requests
83
85
  @tcp_server = TCPServer.new(address, port)
@@ -86,10 +88,14 @@ class Server < N::Application
86
88
  run()
87
89
  end
88
90
 
91
+ # Stop the server.
92
+ #
89
93
  def stop()
90
94
  @status = STATUS_STOPED
91
95
  end
92
96
 
97
+ # Run the main loop of the server.
98
+ #
93
99
  def run()
94
100
  @status = STATUS_RUNNING
95
101
  $log.info "Server is running."
@@ -1,7 +1,5 @@
1
- # = Date Select
2
- #
3
1
  # code:
4
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
5
3
  #
6
4
  # (c) 2004 Navel, all rights reserved.
7
5
  # $Id: select.rb 39 2004-09-29 12:40:53Z elathan $
@@ -11,7 +9,7 @@ module N; module UI
11
9
  MONTHS_EN = %w{ - January February March April May June July August September October November December }
12
10
  MONTHS_EL = %w{ - ���������� ����������� ������� �������� ����� ������� ������� ��������� ����������� ��������� ��������� ���������� }
13
11
 
14
- # Date select.
12
+ # Generate a component that allows the user to select a day.
15
13
  #
16
14
  def self.date_select(prefix, day, month, year, yorder = 0, locale = "en")
17
15
  str = ""
@@ -1,19 +1,21 @@
1
- # = Pager
2
- #
3
- # code: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
4
3
  #
5
4
  # (c) 2004 Navel, all rights reserved.
6
- # $Id: pager.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: pager.rb 99 2004-10-22 09:50:28Z gmosx $
7
6
 
8
7
  module N; module UI
9
8
 
9
+ # = Pager
10
+ #
11
+ # Displays a collection of entitities in multiple pages.
12
+ #
10
13
  # === Design:
11
14
  #
12
15
  # The new version is carefully designed for scaleability. It stores
13
- # only the items for one page.
14
- # The name parameter is needed, multiple pagers can coexist in
15
- # a single page. Unlike the v1/v2 pagers this pager leverages the
16
- # SQL LIMIT option to optimize database interaction.
16
+ # only the items for one page. The name parameter is needed, multiple
17
+ # pagers can coexist in a single page. Unlike the v1/v2 pagers this
18
+ # pager leverages the SQL LIMIT option to optimize database interaction.
17
19
  #
18
20
  # The pager does not extend Array (it includes an Array instead) to
19
21
  # avoid a concat() in the initialization step.
@@ -1,14 +1,15 @@
1
- # = Popup
2
- #
3
- # code: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
4
3
  #
5
4
  # (c) 2004 Navel, all rights reserved.
6
- # $Id: popup.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: popup.rb 99 2004-10-22 09:50:28Z gmosx $
7
6
 
8
7
  module N; module UI
9
8
 
10
9
  # = Popup
11
10
  #
11
+ # Display a popup window.
12
+ #
12
13
  class Popup
13
14
 
14
15
  # Emit the needed javascript.
@@ -1,9 +1,8 @@
1
- # = Select
2
- #
3
- # code: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
4
3
  #
5
4
  # (c) 2004 Navel, all rights reserved.
6
- # $Id: select.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: select.rb 99 2004-10-22 09:50:28Z gmosx $
7
6
 
8
7
  module N; module UI
9
8
 
@@ -1,9 +1,8 @@
1
- # = Tabs
2
- #
3
- # code: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
4
3
  #
5
4
  # (c) 2004 Navel, all rights reserved.
6
- # $Id: tabs.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: tabs.rb 101 2004-10-22 12:35:39Z gmosx $
7
6
 
8
7
  module N; module UI
9
8
 
@@ -1,16 +1,8 @@
1
- # = General arrays utilities collection
2
- #
3
- # === Design:
4
- #
5
- # Implement as a module to avoid class polution. You can still Ruby's
6
- # advanced features to include the module in your class.
7
- # Passing the object to act upon allows to check for nil, which isn't
8
- # possible if you use self.
9
- #
10
- # code:: gmosx, ekarak
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
11
3
  #
12
4
  # (c) 2002-2003 Navel, all rights reserved.
13
- # $Id: array.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: array.rb 101 2004-10-22 12:35:39Z gmosx $
14
6
 
15
7
  require "sync"
16
8
 
@@ -22,13 +14,13 @@ module N
22
14
  # because it is re-entrant.
23
15
  # An exclusive lock is needed when writing, a shared lock IS NEEDED
24
16
  # when reading
25
-
17
+ #
26
18
  class SafeArray < Array
27
19
 
28
20
  attr :sync
29
21
 
30
22
  # gmosx: delegator is not used.
31
-
23
+ #
32
24
  def initialize(delegator = nil)
33
25
  @sync = ::Sync.new()
34
26
  end
@@ -87,6 +79,6 @@ class SafeArray < Array
87
79
  }
88
80
  end
89
81
 
90
- end # SafeArray
82
+ end
91
83
 
92
84
  end # module
@@ -1,13 +1,9 @@
1
- # = Cache
2
- #
3
- # Various caching mechanisms.
4
- #
5
1
  # code:
6
- # George Moschovitis <gm@navel.gr>
7
- # Anastasios Koutoumanos <ak@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
3
+ # * Anastasios Koutoumanos <ak@navel.gr>
8
4
  #
9
5
  # (c) 2004 Navel, all rights reserved.
10
- # $Id: cache.rb 71 2004-10-18 10:50:22Z gmosx $
6
+ # $Id: cache.rb 101 2004-10-22 12:35:39Z gmosx $
11
7
 
12
8
  module N;
13
9
 
@@ -1,16 +1,15 @@
1
- # = General graphics utilities collection
2
- #
3
1
  # code:
4
- # George Moschovitis <gm@navel.gr>
5
- # Elias Athanasopoulos <elathan@navel.gr>
6
- # Asteraki <stella@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
- # $Id: gfx.rb 71 2004-10-18 10:50:22Z gmosx $
6
+ # $Id: gfx.rb 101 2004-10-22 12:35:39Z gmosx $
10
7
 
11
8
  module N
12
9
 
13
10
  # = GfxUtils
11
+ #
12
+ # General graphics utilities collection.
14
13
  #
15
14
  # === Design:
16
15
  #
@@ -1,15 +1,8 @@
1
- # = Hash
2
- #
3
- # various hash utilities.
4
- #
5
- # Design:
6
- # uses the delegator pattern to allow for multiple
7
- # implementations!
8
- #
9
- # *code: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
10
3
  #
11
4
  # (c) 2004 Navel, all rights reserved.
12
- # $Id: hash.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: hash.rb 101 2004-10-22 12:35:39Z gmosx $
13
6
 
14
7
  require "sync"
15
8
 
@@ -21,12 +14,14 @@ module N;
21
14
  # because it is re-entrant.
22
15
  # An exclusive lock is needed when writing, a shared lock IS NEEDED
23
16
  # when reading
24
-
17
+ # uses the delegator pattern to allow for multiple
18
+ # implementations!
19
+ #
25
20
  class SafeHash < Hash
26
21
  attr :sync
27
22
 
28
23
  # gmosx: delegator is not used.
29
-
24
+ #
30
25
  def initialize(delegator = nil)
31
26
  @sync = ::Sync.new
32
27
  end