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
@@ -1,3 +1,14 @@
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
3
+ #
4
+ # (c) 2004 Navel, all rights reserved.
5
+ # $Id: fragment.rb 99 2004-10-22 09:50:28Z gmosx $
6
+
7
+ require "n/utils/cache"
8
+ require "n/mixins"
9
+
10
+ module N; module App
11
+
1
12
  # = Fragment
2
13
  #
3
14
  # A Fragment is the output of a rendered script. Additional metadata
@@ -16,16 +27,6 @@
16
27
  # - less memory per server
17
28
  # - can run background cron scripts over the fragments (compression)
18
29
  #
19
- # code:: gmosx
20
- #
21
- # (c) 2004 Navel, all rights reserved.
22
- # $Id: fragment.rb 71 2004-10-18 10:50:22Z gmosx $
23
-
24
- require "n/utils/cache"
25
- require "n/mixins"
26
-
27
- module N; module App
28
-
29
30
  class Fragment
30
31
  include N::Expirable
31
32
  include N::LRUCache::Item
@@ -55,6 +56,8 @@ class Fragment
55
56
  @expires = @lm + ea
56
57
  end
57
58
 
59
+ # Is the fragment expired?
60
+ #
58
61
  def expired?
59
62
  return true if @expires.nil? || (Time.now > @expires)
60
63
  end
@@ -1,24 +1,31 @@
1
- # = Handlers
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
2
3
  #
3
- # code: gmosx
4
- #
5
- # (c) 2002-2003 Navel, all rights reserved.
6
- # $Id: handlers.rb 71 2004-10-18 10:50:22Z gmosx $
4
+ # (c) 2004 Navel, all rights reserved.
5
+ # $Id: handlers.rb 99 2004-10-22 09:50:28Z gmosx $
7
6
 
8
7
  require "n/utils/cache"
9
8
  require "n/server/filter"
10
9
 
11
10
  module N; module App
12
11
 
13
- # = App server handlers handle requests to specific resources.
12
+ # = Handler
13
+ #
14
+ # App server handlers handle requests to specific resources.
15
+ # Handlers are a special kinf of filters so the can be chained
16
+ # in the rendering pipeline.
14
17
  #
15
18
  # === Design:
16
19
  #
17
- # Handlers are NOT singleton classes. This way we can assign one handler
18
- # class to multiple resources, and keep statistics and metrics for
19
- # each resource.
20
+ # Handlers are NOT singleton classes. This way we can assign one
21
+ # handler class to multiple resources, and keep statistics and
22
+ # metrics for each resource.
20
23
  #
21
24
  class Handler < N::ServerFilter
25
+
26
+ # Perform the actual work of the handler
27
+ # Typically calls the next filter in the pipeline afterwards.
28
+ #
22
29
  def process(request)
23
30
  # nop
24
31
 
@@ -26,21 +33,19 @@ class Handler < N::ServerFilter
26
33
  @next_filter.process(request) if @next_filter
27
34
  end
28
35
 
29
- #---------------------------------------------------------------------
30
- # Testing/Metrics support methods
31
-
32
-
33
36
  end # class
34
37
 
35
- # Handler Error.
36
- # raise this if an error happens when handling a request
37
-
38
+ # = Handler Error
39
+ #
40
+ # Raise this if an error happens when handling a request
41
+ #
38
42
  class HandlerError < StandardError; end
39
43
 
40
44
  # = Script Handler
41
45
  #
42
- # Base handler for scripts.
43
-
46
+ # Base handler for scripts. All othere script handlers are extensions
47
+ # from this class.
48
+ #
44
49
  class ScriptHandler < Handler
45
50
 
46
51
  # cache the compiled page scripts to optimize future references.
@@ -93,7 +98,8 @@ class ScriptHandler < Handler
93
98
  return @@compiled_script_cache
94
99
  end
95
100
 
96
- # Log a rendering error
101
+ # Log a rendering error. The accumulated log is available
102
+ # for rendering in the offending page when in Debug mode.
97
103
  #
98
104
  def log_error(request, ex)
99
105
  request.log_error "--------"
@@ -105,9 +111,10 @@ class ScriptHandler < Handler
105
111
 
106
112
  end
107
113
 
108
- # Handler Error.
109
- # raise this if an error happens when handling a request
110
-
114
+ # =ScriptHandlerError
115
+ #
116
+ # Raise this if an error happens when handling a script.
117
+ #
111
118
  class ScriptHandlerError < HandlerError
112
119
  attr_reader :error_line
113
120
 
@@ -1,10 +1,8 @@
1
- # = Code handler (.sx scripts)
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
- # $Id: code-handler.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: code-handler.rb 99 2004-10-22 09:50:28Z gmosx $
8
6
 
9
7
  require "cgi"
10
8
  require "singleton"
@@ -1,11 +1,9 @@
1
- # = XML Page handler (.sx scripts)
2
- #
3
1
  # code:
4
- # George Moschovitis <gm@navel.gr>
5
- # Anastasios Koutoumanos <ak@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
3
+ # * Anastasios Koutoumanos <ak@navel.gr>
6
4
  #
7
5
  # (c) 2004 Navel, all rights reserved.
8
- # $Id: page-handler.rb 89 2004-10-20 12:55:58Z gmosx $
6
+ # $Id: page-handler.rb 99 2004-10-22 09:50:28Z gmosx $
9
7
 
10
8
  require "cgi"
11
9
  require "singleton"
@@ -1,12 +1,8 @@
1
- # = RequestPart
2
- #
3
- # Encapsulates a multipart part.
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: request-part.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: request-part.rb 99 2004-10-22 09:50:28Z gmosx $
10
6
 
11
7
  require "cgi"
12
8
  require "ftools"
@@ -48,7 +44,6 @@ class RequestPart
48
44
  # Hack fixed save for webrick!
49
45
  #
50
46
  def save(prefix, forced_filename = nil, forced_extension = nil)
51
- # ARGH!! local path is used for something else, FIXME!!
52
47
  ::FileUtils.mkdir_p(prefix)
53
48
  save_path = "#{prefix}/#{@filename}"
54
49
  ::File.open(save_path, "wb") {|f| f.write @body }
@@ -1,15 +1,8 @@
1
- # = Request
2
- #
3
- # Will use params with symbols for args. use uppercase for system
4
- # 'args'.
5
- #
6
- # === INVESTIGATE:
7
- # extend request from hash? to make more compatible with irb?
8
- #
9
- # code: gmosx, drak
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
10
3
  #
11
4
  # (c) 2004 Navel, all rights reserved.
12
- # $Id: request.rb 71 2004-10-18 10:50:22Z gmosx $
5
+ # $Id: request.rb 101 2004-10-22 12:35:39Z gmosx $
13
6
 
14
7
  require "cgi"
15
8
  require "ftools"
@@ -108,16 +101,17 @@ end
108
101
 
109
102
  # = Request
110
103
  #
111
- # Encapsulates an http protocol request. Generally clones
112
- # the Apache Request passed by mod_ruby.
113
- #
114
- # === Todo:
104
+ # The context of an http protocol request. Encapsulates both
105
+ # the request and the response context.
106
+ #
107
+ # === Future:
115
108
  #
116
109
  # - USE libapreq!
117
110
  # - Dont use env_table (arghhhh!)
118
111
  # - dont use a separate path and real path
119
112
  # - MEGA: unify request and request (like a socket, io
120
113
  # stream,etc). Evan subclass IO!
114
+ # - extend request from hash? to make more compatible with irb?
121
115
  #
122
116
  # === Design:
123
117
  #
@@ -142,7 +136,8 @@ end
142
136
  # com/caucho/server/http/HttpRequest.java
143
137
  # - use as much of ruby's default cgi/http code as
144
138
  # possible (why reinvent the wheel?)
145
- #
139
+ # Will use params with symbols for args. use uppercase for system
140
+ # 'args'.
146
141
  #
147
142
  class Request
148
143
  # include usefull query parsing code from the standard
@@ -184,9 +179,12 @@ class Request
184
179
  # The query string is parsed to the parameters
185
180
  # hash.
186
181
  attr_accessor :parameters
182
+ # alias for the parameters hash
187
183
  alias_method :query, :parameters
184
+ # alias for the parameters hash
185
+ alias_method :params, :parameters
188
186
 
189
- # the session this request is part-of
187
+ # the session this request is part-of.
190
188
  attr_accessor :session
191
189
 
192
190
  # The parts attached to this request.
@@ -195,7 +193,9 @@ class Request
195
193
  # can easily enumerate parts.
196
194
  attr_accessor :parts
197
195
 
198
- # the level of the request (0 = toplevel)
196
+ # The level of the request (0 = toplevel). When the evaluating
197
+ # the sub-scripts that the top level script includes, the
198
+ # request level is incremented.
199
199
  attr_accessor :level
200
200
 
201
201
  # the remote address for this request
@@ -238,7 +238,7 @@ class Request
238
238
  # the incoming cookies
239
239
  attr_accessor :in_cookies
240
240
 
241
- # request:
241
+ # response:
242
242
 
243
243
  # the outgoing headers
244
244
  attr_accessor :out
@@ -302,6 +302,7 @@ class Request
302
302
  alias_method :parse_cookie_string, :parse_cookies
303
303
 
304
304
  # === Input:
305
+ #
305
306
  # the cookie name
306
307
  #
307
308
  # === Output:
@@ -331,12 +332,14 @@ class Request
331
332
  #-------------------------------------------------------------------------------
332
333
  # Query
333
334
 
335
+ # Parse the query string and populate the parameters hash.
336
+ #
334
337
  def parse_query_string
335
338
  return N::UriUtils.query_string_to_hash(@query_string)
336
339
  end
337
340
 
338
341
  # Return the value of a query parameter
339
-
342
+ #
340
343
  def [](name)
341
344
  return @parameters[name]
342
345
  end
@@ -362,8 +365,9 @@ class Request
362
365
  # Set the value of a query parameter
363
366
  #
364
367
  # === FIXME:
368
+ #
365
369
  # - handle multivalued parameters!
366
-
370
+ #
367
371
  def []=(name, value)
368
372
  @parameters[name] = value
369
373
  end
@@ -537,7 +541,8 @@ class Request
537
541
  # --------------------------------------------------------------------
538
542
  # Debugging helper
539
543
 
540
- #
544
+ # Accumulate errors in a request log. This log can be presented
545
+ # in the offending page when running in debug mode.
541
546
  #
542
547
  def log_error(str)
543
548
  @error_log = [] unless @error_log
@@ -546,7 +551,7 @@ class Request
546
551
  end
547
552
 
548
553
  # ====================================================================
549
- # Request
554
+ # Response
550
555
 
551
556
  # TODO: add status codes, messages
552
557
 
@@ -1,19 +1,8 @@
1
- # = Base class for scripts.
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
2
3
  #
3
- # Typically a handler evaluates a script. The base class describing
4
- # a script is defined here.
5
- # A generalized fragment caching system is also defined.
6
- #
7
- # see handlers/page-handler::PageScript for more information.
8
- #
9
- # TODO:
10
- # - convert all methods to __ to avoid collisions.
11
- #
12
- # code:
13
- # George Moschovitis <gm@navel.gr>
14
- #
15
- # (c) 2003 Navel, all rights reserved.
16
- # $Id: script.rb 71 2004-10-18 10:50:22Z gmosx $
4
+ # (c) 2004 Navel, all rights reserved.
5
+ # $Id: script.rb 99 2004-10-22 09:50:28Z gmosx $
17
6
 
18
7
  require "fileutils"
19
8
 
@@ -1,9 +1,8 @@
1
- # = AppServer
2
- #
3
- # code:: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
4
3
  #
5
4
  # (c) 2004 Navel, all rights reserved.
6
- # $Id: server.rb 89 2004-10-20 12:55:58Z gmosx $
5
+ # $Id: server.rb 106 2004-10-25 11:31:11Z gmosx $
7
6
 
8
7
  require "drb"
9
8
 
@@ -13,16 +12,19 @@ require "n/app/session"
13
12
 
14
13
  module N; module App
15
14
 
16
- # = AppServerMixin
15
+ # = ServerMixin
16
+ #
17
+ # Usefull application server related methods.
17
18
  #
18
19
  module ServerMixin
19
20
 
20
21
  def initialize_app
21
22
  if $drb_state
22
- # Cluster
23
+ # Cluster mode: use distributed Ruby objects.
23
24
  $lm = N::Cluster::Slm.new($drb_lm_server, "druby://:8000")
24
25
  $sessions = DRbObject.new(nil, $drb_sessions_cluster)
25
26
  else
27
+ # NoCluster mode: use standard Ruby onjects.
26
28
  $lm = N::SafeHash.new
27
29
  $sessions = N::App::SessionManager.new
28
30
  end
@@ -35,7 +37,7 @@ module ServerMixin
35
37
 
36
38
  end
37
39
 
38
- # = AppServer
40
+ # = Server
39
41
  #
40
42
  # The Application Server. Handles dynamic requests in a web application.
41
43
  # Dont keepalive (or use a VERY SMALL keepalive). Typically this server
@@ -47,6 +49,8 @@ class Server < N::Server
47
49
  def initialize(name = "AppServer")
48
50
  super
49
51
  initialize_app()
52
+
53
+ $log.info "Server listening at #$srv_url"
50
54
  end
51
55
  end
52
56
 
@@ -1,12 +1,8 @@
1
- # = Session
2
- #
3
- #--
4
1
  # code:
5
- # George Moschovitis <gm@navel.gr>
2
+ # * George Moschovitis <gm@navel.gr>
6
3
  #
7
4
  # (c) 2002-2003 Navel, all rights reserved.
8
- # $Id: session.rb 84 2004-10-19 13:57:01Z gmosx $
9
- #++
5
+ # $Id: session.rb 99 2004-10-22 09:50:28Z gmosx $
10
6
 
11
7
  require "md5"
12
8
 
@@ -17,7 +13,7 @@ module N; module App
17
13
 
18
14
  # = SessionManager
19
15
  #
20
- # This object manages Session Objects. Several utility methods
16
+ # This object manages session objects. Several utility methods
21
17
  # are also provided.
22
18
  #
23
19
  # === WARNING:
@@ -97,7 +93,7 @@ end
97
93
 
98
94
  # = Session
99
95
  #
100
- # This object encapsulates a WebApplication session.
96
+ # This object encapsulates a session.
101
97
  #
102
98
  # === Design:
103
99
  #
@@ -124,7 +120,7 @@ class Session < Hash
124
120
  # the last touch time
125
121
  attr_accessor :touch_time
126
122
 
127
- #
123
+ # Initializs the session.
128
124
  #
129
125
  def initialize(sid, request = nil)
130
126
  super()
@@ -156,7 +152,7 @@ class Session < Hash
156
152
  @user = N::AnonymousUser.instance
157
153
  end
158
154
 
159
- #
155
+ #
160
156
  #
161
157
  def touch
162
158
  @touch_time = Time.now
@@ -207,7 +203,7 @@ class Session < Hash
207
203
 
208
204
  # Initialize sessions garbage collection.
209
205
  #
210
- # === Warning: this is not used yet!
206
+ # WARNING: this is not used yet!
211
207
  #
212
208
  def self.initialize_gc(session_manager, interval)
213
209
  # gmosx, FIXME: store this in a variable.