nitro 0.9.5 → 0.10.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 (104) hide show
  1. data/ChangeLog +260 -0
  2. data/INSTALL +60 -0
  3. data/LICENSE +1 -0
  4. data/README +19 -20
  5. data/RELEASES +48 -0
  6. data/Rakefile +102 -92
  7. data/benchmark/og/bench.rb +74 -0
  8. data/benchmark/og/sqlite-no-prepare.1.txt +13 -0
  9. data/benchmark/og/sqlite-no-prepare.2.txt +13 -0
  10. data/benchmark/og/sqlite-prepare.1.txt +13 -0
  11. data/benchmark/og/sqlite-prepare.2.txt +13 -0
  12. data/bin/cluster +1 -1
  13. data/bin/nitro +3 -0
  14. data/bin/proto/conf/app.conf.rb +2 -10
  15. data/examples/README.windows +9 -0
  16. data/examples/blog/README +16 -4
  17. data/examples/blog/lib/blog.rb +3 -3
  18. data/examples/blog/lib/blog/controller.rb +7 -9
  19. data/examples/blog/root/fcgi.rb +2 -4
  20. data/examples/blog/root/style.xsl +4 -6
  21. data/examples/blog/run.rb +41 -0
  22. data/examples/flash/run.rb +9 -0
  23. data/examples/no_xsl_blog/README +0 -1
  24. data/examples/no_xsl_blog/conf/app.conf.rb +6 -13
  25. data/examples/no_xsl_blog/lib/blog.rb +2 -2
  26. data/examples/no_xsl_blog/lib/blog/controller.rb +6 -6
  27. data/examples/no_xsl_blog/root/fcgi.rb +2 -4
  28. data/examples/no_xsl_blog/run.rb +38 -0
  29. data/examples/og/mock_example.rb +0 -2
  30. data/examples/og/mysql_to_psql.rb +0 -2
  31. data/examples/og/run.rb +23 -22
  32. data/examples/tiny/root/fcgi.rb +2 -4
  33. data/examples/tiny/root/index.xhtml +21 -5
  34. data/examples/tiny/root/upload.xhtml +23 -0
  35. data/examples/tiny/run.rb +9 -0
  36. data/examples/wee_style/{wee.rb → run.rb} +13 -13
  37. data/install.rb +44 -0
  38. data/lib/glue/array.rb +6 -10
  39. data/lib/glue/attribute.rb +0 -3
  40. data/lib/glue/cache.rb +1 -1
  41. data/lib/glue/inflector.rb +5 -5
  42. data/lib/glue/mixins.rb +3 -12
  43. data/lib/glue/number.rb +1 -1
  44. data/lib/glue/object.rb +7 -1
  45. data/lib/glue/property.rb +32 -22
  46. data/lib/glue/string.rb +13 -75
  47. data/lib/glue/time.rb +2 -2
  48. data/lib/glue/validation.rb +7 -11
  49. data/lib/nitro.rb +16 -1
  50. data/lib/nitro/{adaptors → adapters}/cgi.rb +101 -20
  51. data/lib/nitro/{adaptors → adapters}/fastcgi.rb +3 -2
  52. data/lib/nitro/{adaptors → adapters}/webrick.rb +4 -4
  53. data/lib/nitro/builders/rss.rb +1 -1
  54. data/lib/nitro/builders/xml.rb +8 -10
  55. data/lib/nitro/cluster.rb +1 -1
  56. data/lib/nitro/conf.rb +34 -0
  57. data/lib/nitro/controller.rb +8 -9
  58. data/lib/nitro/dispatcher.rb +38 -11
  59. data/lib/nitro/filters.rb +1 -1
  60. data/lib/nitro/markup.rb +14 -1
  61. data/lib/nitro/render.rb +7 -10
  62. data/lib/nitro/runner.rb +232 -0
  63. data/lib/nitro/ui/pager.rb +2 -6
  64. data/lib/nitro/uri.rb +7 -11
  65. data/lib/og.rb +27 -261
  66. data/lib/og/adapter.rb +352 -0
  67. data/lib/og/adapters/mysql.rb +304 -0
  68. data/lib/og/adapters/psql.rb +286 -0
  69. data/lib/og/adapters/sqlite.rb +262 -0
  70. data/lib/og/backend.rb +1 -1
  71. data/lib/og/connection.rb +123 -87
  72. data/lib/og/database.rb +268 -0
  73. data/lib/og/meta.rb +23 -22
  74. data/lib/og/mock.rb +2 -3
  75. data/lib/xsl/base.xsl +1 -55
  76. data/test/glue/tc_property.rb +2 -0
  77. data/test/glue/tc_property_type_checking.rb +32 -0
  78. data/test/glue/tc_strings.rb +2 -2
  79. data/test/glue/tc_validation.rb +2 -0
  80. data/test/nitro/adapters/raw_post1.bin +0 -0
  81. data/test/nitro/{adaptors → adapters}/tc_cgi.rb +11 -2
  82. data/test/nitro/{adaptors → adapters}/tc_webrick.rb +3 -3
  83. data/test/nitro/builders/tc_xml.rb +14 -5
  84. data/test/nitro/tc_dispatcher.rb +3 -3
  85. data/test/nitro/tc_uri.rb +2 -4
  86. data/test/og/tc_lifecycle.rb +22 -25
  87. data/test/og/tc_sqlite.rb +87 -0
  88. data/test/tc_og.rb +61 -42
  89. metadata +67 -33
  90. data/examples/blog/conf/app.conf.rb +0 -52
  91. data/examples/blog/ctl +0 -4
  92. data/examples/flash/conf/app.conf.rb +0 -21
  93. data/examples/flash/ctl +0 -4
  94. data/examples/no_xsl_blog/conf/apache.conf +0 -0
  95. data/examples/no_xsl_blog/ctl +0 -4
  96. data/examples/tiny/conf/app.conf.rb +0 -17
  97. data/examples/tiny/ctl +0 -4
  98. data/lib/glue/macro.rb +0 -56
  99. data/lib/nitro/adaptors/runner.rb +0 -123
  100. data/lib/nitro/version.rb +0 -15
  101. data/lib/og/backends/mysql.rb +0 -370
  102. data/lib/og/backends/psql.rb +0 -386
  103. data/lib/og/backends/sqlite.rb +0 -383
  104. data/lib/og/version.rb +0 -9
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: blog.rb 223 2005-01-26 17:07:40Z gmosx $
3
+ # $Id: blog.rb 259 2005-02-15 08:54:54Z gmosx $
4
4
 
5
5
  # A simple blog to demonstrate the power of Nitro.
6
6
 
@@ -16,5 +16,5 @@ class Blog
16
16
 
17
17
  end
18
18
 
19
- require 'blog/model'
20
- require 'blog/controller'
19
+ require 'lib/blog/model'
20
+ require 'lib/blog/controller'
@@ -6,26 +6,26 @@ require 'nitro/controller'
6
6
  require 'nitro/builders/rss'
7
7
  require 'nitro/ui/pager'
8
8
 
9
- require 'blog/model'
9
+ require 'lib/blog/model'
10
10
 
11
11
  # The controller of the Blog part.
12
12
 
13
13
  class BlogController < N::Controller
14
14
 
15
15
  before_filter :get_errors
16
- # after_filter :cache
16
+ after_filter :cache
17
17
 
18
18
  scaffold BlogEntry, :name => 'entry', :index => true
19
19
  scaffold Comment
20
20
 
21
21
  def list_entry
22
- @pager = UI::Pager.new('entries', context, 3)
22
+ @pager = UI::Pager.new('entries', request, 3)
23
23
  @entries = BlogEntry.all("ORDER BY oid DESC #{@pager.sql_limit}")
24
24
  @pager.set(BlogEntry.count)
25
25
  end
26
26
 
27
27
  def new_entry
28
- entry = context.fill(BlogEntry.new)
28
+ entry = request.fill(BlogEntry.new)
29
29
  entry.author = session[:username]
30
30
 
31
31
  unless entry.valid?
@@ -43,7 +43,7 @@ class BlogController < N::Controller
43
43
  end
44
44
 
45
45
  def new_comment
46
- comment = context.fill(Comment.new)
46
+ comment = request.fill(Comment.new)
47
47
 
48
48
  unless comment.valid?
49
49
  session[:errors] = comment.errors
@@ -60,7 +60,7 @@ class BlogController < N::Controller
60
60
  end
61
61
 
62
62
  def login
63
- if password = context['password']
63
+ if password = request['password']
64
64
  if password == Blog.password
65
65
  session[:owner] = true
66
66
  session[:username] = Blog.username
@@ -91,9 +91,7 @@ private
91
91
  # Just an example.
92
92
 
93
93
  def cache
94
- # Call the automatically configured logger.
95
-
96
- Logger.info "cache (after filter example)"
94
+ Logger.info 'cache (after filter example)'
97
95
  end
98
96
 
99
97
  end
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.join(File.dirname(__FILE__), '..', 'conf', 'app.conf.rb')
4
- require 'nitro/adaptors/fastcgi'
5
-
6
- N::FastCGI.start($conf)
3
+ ENV['NITRO_INVOKE'] = 'fcgi_proc'
4
+ require File.join(File.dirname(__FILE__), '..', 'run.rb')
@@ -3,11 +3,9 @@
3
3
  <!--
4
4
  A Simple Shader
5
5
 
6
- code:
7
6
  * George Moschovitis <gm@navel.gr>
8
-
9
- (c) 2004 Navel, all rights reserved.
10
- $Id: style.xsl 225 2005-01-27 12:35:07Z gmosx $
7
+ (c) 2004-2005 Navel, all rights reserved.
8
+ $Id: style.xsl 259 2005-02-15 08:54:54Z gmosx $
11
9
  -->
12
10
 
13
11
  <!DOCTYPE shader
@@ -88,8 +86,8 @@ $Id: style.xsl 225 2005-01-27 12:35:07Z gmosx $
88
86
  <div class="block side">
89
87
  <h2>About</h2>
90
88
  This is a simple blog powered by <a href="http://www.navel.gr/nitro">
91
- Nitro</a> Web Engine. Have a look at the source code and enjoy
92
- the power of Ruby.
89
+ Nitro</a> Web Engine. Have a look at the source code and enjoy the
90
+ power of Ruby.
93
91
  <ruby>unless session[:owner]</ruby>
94
92
  <p><a href="login">Login</a> as owner.</p>
95
93
  <ruby>else</ruby>
@@ -0,0 +1,41 @@
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id: run.rb 260 2005-02-15 08:58:04Z gmosx $
4
+
5
+ Dir.chdir File.dirname(__FILE__)
6
+
7
+ require 'nitro'; include N
8
+ require 'og'
9
+
10
+ require 'lib/blog'
11
+
12
+ runner = Runner.new.setup
13
+
14
+ db = Og::Database.new(
15
+ # :address => 'localhost',
16
+ # :adapter => 'mysql',
17
+ :adapter => 'psql',
18
+ # :adapter => 'sqlite',
19
+ :database => 'blog',
20
+ :user => 'postgres',
21
+ :password => 'navelrulez',
22
+ :connection_count => 3
23
+ )
24
+
25
+ dispatcher = Dispatcher.new(BlogController, :xml => 'text/xml')
26
+
27
+ Rendering.shader = XSLTShader.new("#{dispatcher.root}/style.xsl",
28
+ RubyShader.new(
29
+ CompressShader.new
30
+ )
31
+ )
32
+
33
+ conf = Conf.new(
34
+ :name => 'Nitro Blog',
35
+ :host => 'localhost',
36
+ :port => 8069,
37
+ :dispatcher => dispatcher,
38
+ :db => db
39
+ )
40
+
41
+ runner.run(conf)
@@ -0,0 +1,9 @@
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id: run.rb 260 2005-02-15 08:58:04Z gmosx $
4
+
5
+ Dir.chdir File.dirname(__FILE__)
6
+
7
+ require 'nitro'
8
+
9
+ N::Runner.run(:host => 'localhost', :port => 8069)
@@ -18,4 +18,3 @@ To see the example browse http://127.0.0.1:8069
18
18
  This example seems to have some problems when running
19
19
  with Internet Explorer 6. For the moment, please
20
20
  try running it with Firefox and/or Mozilla.
21
-
@@ -16,34 +16,27 @@ require 'blog'
16
16
  include N
17
17
 
18
18
  og = Og::Database.new(
19
- :address => 'localhost',
19
+ # :address => 'localhost',
20
20
  :backend => 'mysql',
21
+ # :backend => 'psql',
21
22
  :database => 'blog',
22
23
  :user => 'root',
23
24
  :password => 'navelrulez',
25
+ # :user => 'postgres',
26
+ # :password => 'navelrulez',
24
27
  :connection_count => 3
25
28
  )
26
29
 
27
- =begin
28
- og = Og::Database.new(
29
- :address => 'localhost',
30
- :backend => 'psql',
31
- :database => 'blog',
32
- :user => 'postgres',
33
- :password => 'navelrulez',
34
- :connection_count => 3
35
- )
36
- =end
37
-
38
30
  controllers = {
39
31
  :index => BlogController
32
+ # mount more controllers if you need.
40
33
  }
41
34
 
42
35
  apis = {
43
36
  :xml => 'text/xml'
44
37
  }
45
38
 
46
- dispatcher = Dispatcher.new(controllers, apis)
39
+ dispatcher = Dispatcher.new(BlogController, :xml => 'text/xml')
47
40
 
48
41
  $conf = {
49
42
  :name => 'Blog sans XSLT',
@@ -16,5 +16,5 @@ class Blog
16
16
 
17
17
  end
18
18
 
19
- require 'blog/model'
20
- require 'blog/controller'
19
+ require 'lib/blog/model'
20
+ require 'lib/blog/controller'
@@ -6,8 +6,8 @@ require 'nitro/controller'
6
6
  require 'nitro/builders/rss'
7
7
  require 'nitro/ui/pager'
8
8
 
9
- require 'blog/model'
10
- require 'blog/template'
9
+ require 'lib/blog/model'
10
+ require 'lib/blog/template'
11
11
 
12
12
  # The controller of the Blog part.
13
13
 
@@ -21,13 +21,13 @@ class BlogController < N::Controller
21
21
  scaffold Comment
22
22
 
23
23
  def list_entry
24
- @pager = UI::Pager.new('entries', context, 3)
24
+ @pager = UI::Pager.new('entries', request, 3)
25
25
  @entries = BlogEntry.all("ORDER BY oid DESC #{@pager.sql_limit}")
26
26
  @pager.set(BlogEntry.count)
27
27
  end
28
28
 
29
29
  def new_entry
30
- entry = context.fill(BlogEntry.new)
30
+ entry = request.fill(BlogEntry.new)
31
31
  entry.author = session[:username]
32
32
 
33
33
  unless entry.valid?
@@ -45,7 +45,7 @@ class BlogController < N::Controller
45
45
  end
46
46
 
47
47
  def new_comment
48
- comment = context.fill(Comment.new)
48
+ comment = request.fill(Comment.new)
49
49
 
50
50
  unless comment.valid?
51
51
  session[:errors] = comment.errors
@@ -62,7 +62,7 @@ class BlogController < N::Controller
62
62
  end
63
63
 
64
64
  def login
65
- if password = context['password']
65
+ if password = request['password']
66
66
  if password == Blog.password
67
67
  session[:owner] = true
68
68
  session[:username] = Blog.username
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.join(File.dirname(__FILE__), '..', 'conf', 'app.conf.rb')
4
- require 'nitro/adaptors/fastcgi'
5
-
6
- N::FastCGI.start($conf)
3
+ ARGV << '--fcgi-proc'
4
+ require File.join(File.dirname(__FILE__), '..', 'run.rb')
@@ -0,0 +1,38 @@
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id: run.rb 260 2005-02-15 08:58:04Z gmosx $
4
+
5
+ Dir.chdir File.dirname(__FILE__)
6
+
7
+ require 'nitro'; include N
8
+ require 'og'
9
+
10
+ require 'lib/blog'
11
+
12
+ runner = Runner.new.setup
13
+
14
+ db = Og::Database.new(
15
+ # :address => 'localhost',
16
+ :adapter => 'mysql',
17
+ # :backend => 'psql',
18
+ :database => 'blog',
19
+ :user => 'root',
20
+ :password => 'navelrulez',
21
+ # :user => 'postgres',
22
+ # :password => 'navelrulez',
23
+ :connection_count => 3
24
+ )
25
+
26
+ dispatcher = Dispatcher.new(BlogController, :xml => 'text/xml')
27
+
28
+ Rendering.shader = RubyShader.new(CompressShader.new)
29
+
30
+ conf = Conf.new(
31
+ :name => 'Blog sans XSLT',
32
+ :host => 'localhost',
33
+ :port => 8069,
34
+ :dispatcher => dispatcher,
35
+ :db => db
36
+ )
37
+
38
+ runner.run(conf)
@@ -7,8 +7,6 @@
7
7
  # (c) 2004-2005 Navel, all rights reserved.
8
8
  # $Id: run.rb 185 2004-12-10 13:29:09Z gmosx $
9
9
 
10
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
11
-
12
10
  require 'rubygems'
13
11
  require 'flexmock'
14
12
  require 'og'
@@ -14,8 +14,6 @@
14
14
  raise 'WARNING, this example does not work yet, for the moment ' +
15
15
  'just have a look at the source code.'
16
16
 
17
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
18
-
19
17
  require 'og'
20
18
 
21
19
  # An example managed object.
data/examples/og/run.rb CHANGED
@@ -1,22 +1,17 @@
1
- # = Og Example
2
- #
3
1
  # A simple example to demonstrate the Og library.
4
2
  #
5
- # code:
6
3
  # * George Moschovitis <gm@navel.gr>
7
- #
8
4
  # (c) 2004 Navel, all rights reserved.
9
- # $Id: run.rb 202 2005-01-17 10:44:13Z gmosx $
10
-
11
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
5
+ # $Id: run.rb 256 2005-02-11 16:22:33Z gmosx $
12
6
 
13
7
  require 'og'
14
8
 
15
9
  # Full debug information.
10
+
16
11
  $DBG = true
17
12
 
18
- # = A child class
19
- #
13
+ # A child class.
14
+
20
15
  class Comment
21
16
  prop_accessor :body, String
22
17
 
@@ -55,8 +50,8 @@ class User
55
50
  end
56
51
 
57
52
 
58
- # = A parent class
59
- #
53
+ # A parent class.
54
+
60
55
  class Article
61
56
  prop_accessor :title, String
62
57
  prop_accessor :body, String
@@ -95,8 +90,8 @@ class Article
95
90
  end
96
91
  end
97
92
 
98
- # = A parent class
99
- #
93
+ # A parent class.
94
+
100
95
  class Category
101
96
  prop_accessor :title, String
102
97
  prop_accessor :body, String
@@ -110,20 +105,20 @@ class Category
110
105
  end
111
106
 
112
107
 
113
- # = Article comment
114
- #
108
+ # Article comment.
109
+
115
110
  class ArticleComment < Comment
116
111
  belongs_to :article, Article
117
112
  end
118
113
 
119
- # = User comment
120
- #
114
+ # User comment.
115
+
121
116
  class UserComment < Comment
122
117
  belongs_to :author, User
123
118
  end
124
119
 
125
- # = Another child class
126
- #
120
+ # Another child class.
121
+
127
122
  class Part
128
123
  prop_accessor :name, String
129
124
  belongs_to :article, Article
@@ -139,14 +134,20 @@ end
139
134
 
140
135
  # Og configuration.
141
136
  config = {
142
- :address => "localhost",
143
137
  :database => "test",
144
- :backend => "psql",
138
+ :adapter => "sqlite",
139
+ :connection_count => 2
140
+ }
141
+ =begin
142
+ config = {
143
+ # :address => "localhost",
144
+ :database => "test",
145
+ :adapter => "psql",
145
146
  :user => "postgres",
146
147
  :password => "navelrulez",
147
148
  :connection_count => 1
148
149
  }
149
- =begin
150
+
150
151
  config = {
151
152
  :address => "localhost",
152
153
  :database => "test",
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.join(File.dirname(__FILE__), '..', 'conf', 'app.conf.rb')
4
- require 'nitro/adaptors/fastcgi'
5
-
6
- N::FastCGI.start($conf)
3
+ ARGV << '--fcgi-proc'
4
+ require File.join(File.dirname(__FILE__), '..', 'run.rb')
@@ -5,7 +5,7 @@
5
5
  <?r
6
6
  # the code that populates the template comes here
7
7
 
8
- unless name = context['name']
8
+ unless name = request['name']
9
9
  name = 'World'
10
10
  end
11
11
 
@@ -20,10 +20,7 @@
20
20
  </p>
21
21
 
22
22
 
23
- <strong>Hello #{name}</strong>
24
- <!--
25
- <p>#{context.headers.collect { |h| "#{h}<br/>" }}</p>
26
- -->
23
+ <strong>#{Rendering.reload} Hello #{name}</strong>
27
24
  <p>
28
25
  <form id="my_form">
29
26
  <strong>Enter your name:</strong>
@@ -39,4 +36,23 @@
39
36
 
40
37
  <render href="include" />
41
38
 
39
+ <!--
40
+ <p>#{context.headers.collect { |h| "#{h}<br/>" }}</p>
41
+ <p>
42
+ <h3>Upload a picture</h3>
43
+
44
+ <form action="upload" method="post" enctype="multipart/form-data">
45
+ <p>
46
+ <b>Title:<b><br />
47
+ <input type="text" name="title" />
48
+ </p>
49
+ <p>
50
+ <b>File:<b><br />
51
+ <input type="file" name="file" />
52
+ </p>
53
+ <input type="submit" value="Upload" />
54
+ </form>
55
+ </p>
56
+ -->
57
+
42
58
  </html>