nitro 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/CHANGELOG +752 -543
  2. data/INSTALL +38 -38
  3. data/README +264 -225
  4. data/Rakefile +48 -49
  5. data/bin/nitro +3 -3
  6. data/bin/nitrogen +6 -6
  7. data/doc/AUTHORS +10 -10
  8. data/doc/CHANGELOG.1 +1939 -1939
  9. data/doc/CHANGELOG.2 +954 -954
  10. data/doc/LICENSE +3 -3
  11. data/doc/MIGRATION +28 -0
  12. data/doc/RELEASES +814 -643
  13. data/doc/config.txt +5 -5
  14. data/install.rb +7 -17
  15. data/lib/nitro.rb +38 -9
  16. data/lib/nitro/adapter/cgi.rb +311 -312
  17. data/lib/nitro/adapter/fastcgi.rb +18 -25
  18. data/lib/nitro/adapter/webrick.rb +128 -137
  19. data/lib/nitro/adapter/wee.rb +51 -0
  20. data/lib/nitro/caching.rb +20 -20
  21. data/lib/nitro/caching/actions.rb +43 -43
  22. data/lib/nitro/caching/fragments.rb +46 -46
  23. data/lib/nitro/caching/invalidation.rb +11 -11
  24. data/lib/nitro/caching/output.rb +65 -65
  25. data/lib/nitro/caching/stores.rb +67 -67
  26. data/lib/nitro/compiler.rb +262 -0
  27. data/lib/nitro/compiler/elements.rb +0 -0
  28. data/lib/nitro/compiler/errors.rb +65 -0
  29. data/lib/nitro/compiler/localization.rb +25 -0
  30. data/lib/nitro/compiler/markup.rb +19 -0
  31. data/lib/nitro/compiler/shaders.rb +206 -0
  32. data/lib/nitro/compiler/squeeze.rb +20 -0
  33. data/lib/nitro/compiler/xslt.rb +61 -0
  34. data/lib/nitro/context.rb +87 -88
  35. data/lib/nitro/controller.rb +151 -158
  36. data/lib/nitro/cookie.rb +34 -34
  37. data/lib/nitro/dispatcher.rb +195 -186
  38. data/lib/nitro/element.rb +132 -126
  39. data/lib/nitro/element/java_script.rb +6 -6
  40. data/lib/nitro/flash.rb +66 -66
  41. data/lib/nitro/mail.rb +192 -192
  42. data/lib/nitro/mixin/buffer.rb +66 -0
  43. data/lib/nitro/mixin/debug.rb +16 -16
  44. data/lib/nitro/mixin/form.rb +88 -0
  45. data/lib/nitro/mixin/helper.rb +2 -2
  46. data/lib/nitro/mixin/javascript.rb +108 -108
  47. data/lib/nitro/mixin/markup.rb +144 -0
  48. data/lib/nitro/mixin/pager.rb +202 -202
  49. data/lib/nitro/mixin/rss.rb +67 -0
  50. data/lib/nitro/mixin/table.rb +63 -0
  51. data/lib/nitro/mixin/xhtml.rb +75 -0
  52. data/lib/nitro/mixin/xml.rb +124 -0
  53. data/lib/nitro/render.rb +183 -359
  54. data/lib/nitro/request.rb +140 -140
  55. data/lib/nitro/response.rb +27 -27
  56. data/lib/nitro/routing.rb +21 -21
  57. data/lib/nitro/scaffold.rb +124 -118
  58. data/lib/nitro/server.rb +117 -80
  59. data/lib/nitro/server/runner.rb +341 -0
  60. data/lib/nitro/service.rb +12 -12
  61. data/lib/nitro/service/xmlrpc.rb +22 -22
  62. data/lib/nitro/session.rb +122 -120
  63. data/lib/nitro/session/drb.rb +9 -9
  64. data/lib/nitro/session/drbserver.rb +34 -34
  65. data/lib/nitro/template.rb +171 -155
  66. data/lib/nitro/testing/assertions.rb +90 -90
  67. data/lib/nitro/testing/context.rb +16 -16
  68. data/lib/nitro/testing/testcase.rb +34 -34
  69. data/proto/conf/lhttpd.conf +9 -9
  70. data/proto/public/error.xhtml +75 -75
  71. data/proto/public/index.xhtml +18 -18
  72. data/proto/public/js/behaviour.js +65 -65
  73. data/proto/public/js/controls.js +1 -1
  74. data/proto/public/js/prototype.js +3 -3
  75. data/proto/public/settings.xhtml +61 -61
  76. data/proto/run.rb +1 -5
  77. data/test/nitro/adapter/raw_post1.bin +0 -0
  78. data/test/nitro/adapter/tc_cgi.rb +57 -57
  79. data/test/nitro/adapter/tc_webrick.rb +4 -4
  80. data/test/nitro/mixin/tc_pager.rb +25 -25
  81. data/test/nitro/mixin/tc_rss.rb +24 -0
  82. data/test/nitro/mixin/tc_table.rb +31 -0
  83. data/test/nitro/mixin/tc_xhtml.rb +13 -0
  84. data/test/nitro/tc_caching.rb +10 -10
  85. data/test/nitro/tc_context.rb +8 -8
  86. data/test/nitro/tc_controller.rb +48 -48
  87. data/test/nitro/tc_cookie.rb +6 -6
  88. data/test/nitro/tc_dispatcher.rb +64 -64
  89. data/test/nitro/tc_element.rb +27 -27
  90. data/test/nitro/tc_flash.rb +31 -31
  91. data/test/nitro/tc_mail.rb +63 -63
  92. data/test/nitro/tc_server.rb +26 -26
  93. data/test/nitro/tc_session.rb +9 -9
  94. data/test/nitro/tc_template.rb +19 -19
  95. data/test/public/blog/list.xhtml +1 -1
  96. metadata +31 -37
  97. data/lib/nitro/buffering.rb +0 -45
  98. data/lib/nitro/builder/form.rb +0 -104
  99. data/lib/nitro/builder/rss.rb +0 -104
  100. data/lib/nitro/builder/table.rb +0 -80
  101. data/lib/nitro/builder/xhtml.rb +0 -132
  102. data/lib/nitro/builder/xml.rb +0 -131
  103. data/lib/nitro/conf.rb +0 -36
  104. data/lib/nitro/environment.rb +0 -21
  105. data/lib/nitro/errors.rb +0 -69
  106. data/lib/nitro/localization.rb +0 -153
  107. data/lib/nitro/markup.rb +0 -147
  108. data/lib/nitro/output.rb +0 -24
  109. data/lib/nitro/runner.rb +0 -348
  110. data/lib/nitro/shaders.rb +0 -206
  111. data/test/nitro/builder/tc_rss.rb +0 -23
  112. data/test/nitro/builder/tc_table.rb +0 -30
  113. data/test/nitro/builder/tc_xhtml.rb +0 -39
  114. data/test/nitro/builder/tc_xml.rb +0 -56
  115. data/test/nitro/tc_localization.rb +0 -49
data/lib/nitro/server.rb CHANGED
@@ -1,89 +1,126 @@
1
1
  require 'glue/autoreload'
2
- require 'nitro/adapter/webrick'
2
+
3
+ require 'nitro/server/runner'
3
4
 
4
5
  module Nitro
5
6
 
6
7
  class Server
7
8
 
8
- # :nodoc: all
9
- # A Helper class used for CherryPy-style publishing.
10
-
11
- class Mounter
12
- def initialize(parent, base = '')
13
- @parent, @base = parent, base
14
- end
15
-
16
- def method_missing(sym, *args)
17
- sym = sym.to_s
18
- if sym =~ /=$/
19
- @parent.map["#@base/#{sym.gsub(/=/, '')}"] = args.first
20
- else
21
- Mounter.new(@parent, "#@base/#{sym}")
22
- end
23
- end
24
- end
25
-
26
- # The server listening address.
27
- #--
28
- # 0.0.0.0 may be a better default?
29
- #++
30
-
31
- setting :address, :default => '127.0.0.1', :doc => 'The server listening address'
32
-
33
- # The server listening port.
34
-
35
- setting :port, :default => 9999, :doc => 'The server listening port'
36
-
37
- # The map.
38
-
39
- setting :map, :default => { '/' => SimpleController }, :doc => 'The server map'
40
-
41
- # The name of the application.
42
-
43
- attr_accessor :name
44
-
45
- # The sitemap. Defines how controller objects are published.
46
-
47
- attr_accessor :map
48
-
49
- def initialize(name = 'Nitro')
50
- @name = name
51
- @map = self.class.map.dup
52
- end
53
-
54
- # Start the server.
55
-
56
- def start(controller = nil)
57
- self.map['/'] = controller if controller
58
-
59
- $DBG = true
60
- autoreload(3)
61
- Rendering.reload = :full
62
-
63
- dispatcher = Dispatcher.new
64
- dispatcher.publish(self.map)
65
- conf = {
66
- :dispatcher => dispatcher
67
- }
68
-
69
- Webrick.start(Conf.new(conf))
70
- end
71
-
72
- def root=(controller)
73
- @map['/'] = controller
74
- end
75
-
76
- def root
77
- Mounter.new(self)
78
- end
79
-
80
- # Helper method.
81
-
82
- def self.run(controller = nil)
83
- server = Server.new
84
- server.start(controller)
85
- end
86
-
9
+ # The server listening address.
10
+ #--
11
+ # 0.0.0.0 may be a better default?
12
+ #++
13
+
14
+ setting :address, :default => '127.0.0.1', :doc => 'The server listening address'
15
+
16
+ # The server listening port.
17
+
18
+ setting :port, :default => 9999, :doc => 'The server listening port'
19
+
20
+ # The map.
21
+
22
+ setting :map, :default => { '/' => SimpleController }, :doc => 'The server map'
23
+
24
+ # The public files root directory.
25
+
26
+ setting :public_root, :default => 'public', :doc => 'The public files root directory'
27
+
28
+ # The access log, can be a path to a file or an IO object.
29
+
30
+ setting :access_log, :default => nil, :doc => 'The access log'
31
+
32
+ # The name of the application.
33
+
34
+ attr_accessor :name
35
+
36
+ # The sitemap. Defines how controller objects are published.
37
+
38
+ attr_accessor :map
39
+
40
+ # The public files root directory.
41
+
42
+ attr_accessor :public_root
43
+
44
+ # The server listening address.
45
+
46
+ attr_accessor :address
47
+
48
+ # The server listening port.
49
+
50
+ attr_accessor :port
51
+
52
+ # The dispatcher
53
+
54
+ attr_accessor :dispatcher
55
+
56
+ # Additional server options. Useful to pass options to
57
+ # Webrick for example.
58
+
59
+ attr_accessor :options
60
+
61
+ def initialize(name = 'Nitro', options = {})
62
+ @name = name
63
+ @map = self.class.map.dup
64
+ @address, @port = self.class.address, self.class.port
65
+ @public_root = self.class.public_root
66
+ @access_log = self.class.access_log
67
+ @options = options
68
+ end
69
+
70
+ # Return the dispatcher.
71
+
72
+ def dispatcher
73
+ unless @dispatcher
74
+ @dispatcher = Dispatcher.new(self.map)
75
+ end
76
+ @dispatcher
77
+ end
78
+
79
+ # Start the server.
80
+
81
+ def start(controller = nil)
82
+ @map['/'] = controller if controller
83
+ @dispatcher = Dispatcher.new(@map)
84
+ end
85
+
86
+ def root=(controller)
87
+ @map['/'] = controller
88
+ end
89
+
90
+ def root
91
+ Mounter.new(self)
92
+ end
93
+
94
+ # Helper method.
95
+
96
+ def self.run(controller = nil)
97
+ runner = Runner.new
98
+ runner.setup_options
99
+ runner.setup_mode
100
+ runner.daemonize if runner.daemon
101
+ server = Server.new
102
+ server.start(controller)
103
+ runner.invoke(server)
104
+ end
105
+
106
+ # A Helper class used for CherryPy-style publishing.
107
+
108
+ class Mounter # :nodoc: all
109
+ def initialize(parent, base = '')
110
+ @parent, @base = parent, base
111
+ end
112
+
113
+ def method_missing(sym, *args)
114
+ sym = sym.to_s
115
+ if sym =~ /=$/
116
+ @parent.map["#@base/#{sym.gsub(/=/, '')}"] = args.first
117
+ else
118
+ Mounter.new(@parent, "#@base/#{sym}")
119
+ end
120
+ end
121
+ end
122
+
123
+
87
124
  end
88
125
 
89
126
  end
@@ -0,0 +1,341 @@
1
+ require 'optparse'
2
+
3
+ require 'glue/misc'
4
+ require 'glue/configuration'
5
+
6
+ module Nitro
7
+
8
+ # The Runner is a helper class that encapsulates a web
9
+ # application and is responsible for launching the
10
+ # application in different modes.
11
+ #
12
+ # The runner provides default parsing of command line
13
+ # and environment parameters.
14
+ #
15
+ # The default execution modes are:
16
+ #
17
+ # :debug, :stage, :live
18
+ #
19
+ # You can implement your own, custom version of the Runner
20
+ # to run your custom web applications.
21
+
22
+ class Runner
23
+
24
+ # ...
25
+
26
+ setting :adapter, :default => :webrick, :doc => 'The web adapter'
27
+
28
+ # Execution mode = (:debug, :stage, :live)
29
+ #
30
+ # [:debug]
31
+ # useful when debugging, extra debug information
32
+ # is emmited, actions, templates and shaders are
33
+ # reloaded, etc. The execution speed of the application
34
+ # is impaired.
35
+ #
36
+ # [:stage]
37
+ # test the application with live parameters
38
+ # (typically on a staging server).
39
+ #
40
+ # [:live]
41
+ # use the parameters for the live (production)
42
+ # server. Optimized for speed.
43
+ #
44
+ # The default mode is :debug
45
+
46
+ attr_accessor :mode
47
+
48
+ # :start, :stop, :restart
49
+
50
+ attr_accessor :action
51
+
52
+ # The server used to run this web application.
53
+ # :webrick, :nitro, :lhttp, :apache, :mod_apache
54
+ #
55
+ # At the moment only :webrick and :lhttp are available.
56
+
57
+ attr_accessor :server
58
+
59
+ # Run as daemon.
60
+
61
+ attr_accessor :daemon
62
+
63
+ # Spidering mode. Acceptable values are :crawl, :render
64
+ # and false.
65
+
66
+ attr_accessor :spider
67
+
68
+ # Parse the command line arguments and the environment
69
+ # parameters to setup the application.
70
+
71
+ def setup_options
72
+ @mode ||= :debug
73
+ @action ||= :start
74
+ @server ||= :webrick
75
+ @daemon = false
76
+ @spider = false
77
+
78
+ # Setup from environment
79
+
80
+ @mode = ENV.fetch('NITRO_MODE', 'debug').to_sym
81
+
82
+ # Setup from command line arguments.
83
+
84
+ parser = OptionParser.new do |opts|
85
+
86
+ opts.banner = 'Usage: run.rb [options]'
87
+ opts.separator ''
88
+ opts.separator 'Specific options:'
89
+
90
+ opts.on('-s', '--start', 'Start application.') do
91
+ @action = :start
92
+ end
93
+
94
+ opts.on('-S', '--stop', 'Stop application.') do
95
+ @action = :stop
96
+ end
97
+
98
+ opts.on('-r', '--restart', 'Restart application.') do
99
+ @action = :restart
100
+ end
101
+
102
+ opts.on('-d', '--daemon', 'Run application as a daemon.') do
103
+ @daemon = true
104
+ end
105
+
106
+ opts.on('-D', '--debug', 'Run application in debug mode.') do
107
+ @mode = :debug
108
+ end
109
+
110
+ opts.on('-T', '--stage', 'Run application in stage mode.') do
111
+ @mode = :stage
112
+ end
113
+
114
+ opts.on('-L', '--live', 'Run application in live mode.') do
115
+ @mode = :live
116
+ end
117
+
118
+ opts.on('-w', '--webrick', 'Use a webrick server [default].') do
119
+ @server = :webrick
120
+ end
121
+
122
+ opts.on('-l', '--lhttpd', 'Use a lighttpd server.') do
123
+ @server = :lhttpd
124
+ Logger.set(Logger.new('log/app.log'))
125
+ end
126
+
127
+ opts.on('-a', '--apache', 'Use an apache server.') do
128
+ @server = :apache
129
+ Logger.set(Logger.new('log/app.log'))
130
+ end
131
+
132
+ opts.on('--apache-cgi', 'Run as CGI (Apache)') do
133
+ @server = :cgi
134
+ Logger.set(Logger.new('log/app.log'))
135
+ end
136
+
137
+ opts.on('-C', '--console', 'Start a console attached to an instance of the application.') do
138
+ if RUBY_PLATFORM =~ /mswin32/
139
+ irb_name = 'irb.bat'
140
+ else
141
+ irb_name = 'irb'
142
+ end
143
+ ENV['NITRO_INVOKE'] = 'irb'
144
+ conf_file = File.basename(caller.last.split(':').first)
145
+ exec "#{irb_name} -r #{conf_file} -r irb/completion --noinspect"
146
+ exit
147
+ end
148
+
149
+ opts.on('--crawl', 'Crawl the application.') do
150
+ @server = :webrick
151
+ @spider = :crawl
152
+ end
153
+
154
+ opts.on('--render', 'Crawl the application and render all pages as static html files.') do
155
+ @server = :webrick
156
+ @spider = :render
157
+ end
158
+
159
+ opts.on_tail('-v', '--version', 'Show version.') do
160
+ puts "Nitro #{Nitro::Version}"
161
+ exit
162
+ end
163
+
164
+ opts.on_tail('-h', '--help', 'Show this message.') do
165
+ puts opts
166
+ exit
167
+ end
168
+
169
+ end
170
+
171
+ parser.parse!(ARGV)
172
+
173
+ return self
174
+ end
175
+
176
+ # Setup the declared execution mode,
177
+ # using the passed configuration parameters.
178
+
179
+ def setup_mode
180
+ case @mode
181
+ when :debug
182
+ setup_debug
183
+
184
+ when :stage
185
+ setup_stage
186
+
187
+ when :live
188
+ setup_live
189
+ end
190
+ end
191
+
192
+ # Setup in debug mode.
193
+
194
+ def setup_debug
195
+ $DBG = true
196
+ Compiler.reload = true
197
+ require 'glue/autoreload'
198
+ autoreload(3)
199
+ Caching.caching_enabled = false
200
+
201
+ load_external_configuration(:debug)
202
+ end
203
+
204
+ def setup_stage
205
+ $DBG = false
206
+ Compiler.reload = true
207
+ Logger.set(Logger.new('log/app.log'))
208
+
209
+ load_external_configuration(:stage)
210
+ end
211
+
212
+ def setup_live
213
+ $DBG = false
214
+ Compiler.reload = false
215
+ Logger.set(Logger.new('log/app.log'))
216
+
217
+ load_external_configuration(:live)
218
+ load_external_configuration(:production)
219
+ end
220
+ alias_method :setup_production, :setup_live
221
+
222
+ # ...
223
+
224
+ def invoke(server)
225
+ if 'fcgi_proc' == ENV['NITRO_INVOKE']
226
+ require 'nitro/adapter/fastcgi'
227
+ FastCGI.start(server)
228
+
229
+ elsif 'cgi_proc' == ENV['NITRO_INVOKE']
230
+ require 'nitro/adapter/cgi'
231
+ Cgi.start(server)
232
+
233
+ elsif 'irb' == ENV['NITRO_INVOKE']
234
+ $server = server
235
+
236
+ else
237
+ invoke_server(server)
238
+ end
239
+ end
240
+
241
+ # ...
242
+
243
+ def invoke_server(server)
244
+ spider_thread = nil
245
+
246
+ case @action
247
+ when :start
248
+
249
+ case @spider
250
+ when :render
251
+ spider_thread = Thread.new do
252
+ sleep(6)
253
+ `wget -k -m -p #{server.address}:#{server.port} -directory-prefix=rendered`
254
+ end
255
+ when :crawl
256
+ spider_thread = Thread.new do
257
+ sleep(6)
258
+ `wget -m --spider #{server.host}:#{server.port}`
259
+ end
260
+ end
261
+
262
+ @server ||= Runner.adapter
263
+
264
+ puts "\n==> Listening at #{server.address}:#{server.port}. (#{@mode} mode)\n\n"
265
+
266
+ case @server
267
+ when :webrick
268
+ require 'nitro/adapter/webrick'
269
+ Webrick.start(server)
270
+
271
+ when :lhttpd
272
+ require 'nitro/adapter/fastcgi'
273
+ `lighttpd -f conf/lhttpd.conf`
274
+
275
+ when :apache
276
+ require 'nitro/adapter/fastcgi'
277
+ `apachectl -d #{Dir.pwd} -f conf/apache.conf -k start`
278
+
279
+ when :cgi
280
+ require 'nitro/adapter/cgi'
281
+ end
282
+
283
+ when :stop
284
+
285
+ case @server
286
+ when :webrick
287
+
288
+ when :lhttpd
289
+
290
+ when :apache
291
+ `apachectl -d #{Dir.pwd} -f conf/apache.conf -k stop`
292
+ end
293
+
294
+ end
295
+ end
296
+
297
+ # :section: Utilities
298
+
299
+ # Run this proccess as a daemon (UNIX only).
300
+
301
+ def daemonize
302
+ require 'daemons/daemonize'
303
+ pwd = Dir.pwd
304
+ Daemonize.daemonize(File.join(pwd, 'log/app.log'))
305
+ # Restore the original pwd (daemonize sets the
306
+ # pwd to '/').
307
+ Dir.chdir(pwd)
308
+ # Set the logger to a file (daemonize closes the
309
+ # std streams).
310
+ Logger.set(Logger.new('log/app.log'))
311
+ end
312
+
313
+ # Attempt to load external configuration in Ruby or
314
+ # YAML format. The files:
315
+ #
316
+ # * conf/mode.rb
317
+ # * conf/mode.yaml
318
+ #
319
+ # are considered.
320
+
321
+ def load_external_configuration(mode = :debug)
322
+ begin
323
+ # gmosx: Workaround for an RDoc bug.
324
+ # require "conf/#{mode}.rb"
325
+ eval %|require 'conf/#{mode}.rb'|
326
+ rescue Object
327
+ end
328
+
329
+ # Try to configure from a yaml file.
330
+ begin
331
+ Configuration.load "conf/#{mode}.yml"
332
+ rescue Object => ex
333
+ end
334
+ end
335
+
336
+ end
337
+
338
+ end
339
+
340
+ # * George Moschovitis <gm@navel.gr>
341
+ # * James Britt <james_b@neurogami.com>