nitro 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/CHANGELOG +218 -0
  2. data/INSTALL +3 -0
  3. data/README +4 -2
  4. data/Rakefile +150 -8
  5. data/benchmark/bench.rb +1 -1
  6. data/doc/AUTHORS +2 -8
  7. data/doc/RELEASES +63 -1
  8. data/examples/ajax/controller.rb +2 -2
  9. data/examples/ajax/public/index.xhtml +3 -1
  10. data/examples/ajax/run.rb +3 -3
  11. data/examples/blog/README +8 -0
  12. data/examples/blog/cache/entriesadmintrue +3 -0
  13. data/examples/blog/run.rb +38 -40
  14. data/examples/blog/src/blog.rb +2 -1
  15. data/examples/blog/src/controller.rb +40 -20
  16. data/examples/blog/src/mailer.rb +2 -2
  17. data/examples/blog/src/models/blog.rb +2 -1
  18. data/examples/blog/src/models/content.rb +4 -33
  19. data/examples/blog/src/views/error.xhtml +1 -1
  20. data/examples/blog/src/xsl/style.xsl +1 -1
  21. data/examples/blog/test/tc_blog.rb +43 -0
  22. data/examples/flash/run.rb +2 -2
  23. data/examples/no_xsl_blog/lib/blog.rb +1 -1
  24. data/examples/no_xsl_blog/lib/blog/controller.rb +26 -17
  25. data/examples/no_xsl_blog/lib/blog/model.rb +3 -3
  26. data/examples/no_xsl_blog/lib/blog/template.rb +1 -1
  27. data/examples/no_xsl_blog/lib/content.rb +3 -7
  28. data/examples/no_xsl_blog/run.rb +34 -34
  29. data/examples/tiny/public/deep/dir/hello.xhtml +2 -0
  30. data/examples/tiny/run.rb +2 -2
  31. data/examples/wee_style/run.rb +5 -3
  32. data/examples/why_wiki/run.rb +5 -3
  33. data/install.rb +1 -1
  34. data/lib/nitro.rb +10 -9
  35. data/lib/nitro/adapters/cgi.rb +27 -2
  36. data/lib/nitro/adapters/fastcgi.rb +6 -2
  37. data/lib/nitro/adapters/webrick.rb +11 -9
  38. data/lib/nitro/buffering.rb +2 -2
  39. data/lib/nitro/builders/atom.rb +78 -0
  40. data/lib/nitro/builders/form.rb +2 -2
  41. data/lib/nitro/builders/rss.rb +4 -4
  42. data/lib/nitro/builders/table.rb +2 -2
  43. data/lib/nitro/builders/xhtml.rb +5 -8
  44. data/lib/nitro/builders/xml.rb +38 -14
  45. data/lib/nitro/caching.rb +2 -2
  46. data/lib/nitro/caching/actions.rb +2 -2
  47. data/lib/nitro/caching/fragments.rb +2 -2
  48. data/lib/nitro/caching/invalidation.rb +2 -28
  49. data/lib/nitro/caching/output.rb +3 -3
  50. data/lib/nitro/caching/stores.rb +4 -4
  51. data/lib/nitro/conf.rb +11 -6
  52. data/lib/nitro/context.rb +2 -2
  53. data/lib/nitro/controller.rb +12 -7
  54. data/lib/nitro/cookie.rb +2 -2
  55. data/lib/nitro/dispatcher.rb +33 -40
  56. data/lib/nitro/environment.rb +1 -1
  57. data/lib/nitro/localization.rb +5 -7
  58. data/lib/nitro/mail.rb +2 -2
  59. data/lib/nitro/markup.rb +5 -5
  60. data/lib/nitro/output.rb +2 -2
  61. data/lib/nitro/part.rb +8 -5
  62. data/lib/nitro/render.rb +46 -45
  63. data/lib/nitro/request.rb +7 -6
  64. data/lib/nitro/response.rb +14 -5
  65. data/lib/nitro/routing.rb +2 -2
  66. data/lib/nitro/runner.rb +57 -17
  67. data/lib/nitro/scaffold.rb +14 -8
  68. data/lib/nitro/session.rb +7 -4
  69. data/lib/nitro/session/drb.rb +2 -2
  70. data/lib/nitro/session/drbserver.rb +2 -2
  71. data/lib/nitro/session/memory.rb +2 -2
  72. data/lib/nitro/shaders.rb +8 -7
  73. data/lib/nitro/simple.rb +4 -1
  74. data/lib/nitro/template.rb +8 -8
  75. data/lib/nitro/testing.rb +6 -0
  76. data/lib/nitro/testing/assertions.rb +102 -0
  77. data/lib/nitro/testing/context.rb +52 -0
  78. data/lib/nitro/testing/testcase.rb +55 -0
  79. data/lib/nitro/ui/pager.rb +3 -3
  80. data/lib/nitro/ui/popup.rb +8 -13
  81. data/lib/nitro/ui/tabs.rb +4 -10
  82. data/lib/nitro/uri.rb +7 -7
  83. data/proto/doc/README +1 -0
  84. data/proto/public/cgi.rb +5 -0
  85. data/proto/run.rb +2 -4
  86. data/test/nitro/adapters/tc_cgi.rb +1 -1
  87. data/test/nitro/adapters/tc_webrick.rb +1 -2
  88. data/test/nitro/builders/tc_atom.rb +26 -0
  89. data/test/nitro/builders/tc_rss.rb +3 -2
  90. data/test/nitro/builders/tc_table.rb +1 -1
  91. data/test/nitro/builders/tc_xhtml.rb +4 -3
  92. data/test/nitro/builders/tc_xml.rb +7 -7
  93. data/test/nitro/tc_context.rb +1 -1
  94. data/test/nitro/tc_controller.rb +5 -3
  95. data/test/nitro/tc_dispatcher.rb +19 -18
  96. data/test/nitro/tc_localization.rb +1 -1
  97. data/test/nitro/tc_mail.rb +1 -1
  98. data/test/nitro/tc_session.rb +1 -1
  99. data/test/nitro/tc_template.rb +1 -1
  100. data/test/nitro/tc_uri.rb +3 -4
  101. data/test/nitro/ui/tc_pager.rb +7 -7
  102. data/test/public/blog/inc1.xhtml +2 -0
  103. data/test/public/blog/inc2.xhtml +1 -0
  104. data/test/public/blog/list.xhtml +3 -0
  105. metadata +180 -203
  106. data/examples/blog/cache/entriesadmin +0 -12
  107. data/lib/nitro/cluster.rb +0 -218
  108. data/lib/nitro/component.rb +0 -15
  109. data/lib/nitro/filters.rb +0 -215
  110. data/lib/nitro/ui/date-select.rb +0 -69
  111. data/test/nitro/tc_filters.rb +0 -111
@@ -1,12 +1,12 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: stores.rb 335 2005-03-31 14:02:02Z gmosx $
3
+ # $Id: stores.rb 9 2005-04-13 00:08:20Z nasis $
4
4
 
5
5
  require 'fileutils'
6
6
 
7
7
  require 'glue/hash'
8
8
 
9
- module N
9
+ module Nitro
10
10
 
11
11
  # Adds support for caching.
12
12
 
@@ -14,13 +14,13 @@ module Caching
14
14
 
15
15
  # Cached fragments are stored in memory.
16
16
 
17
- class MemoryStore < SafeHash
17
+ class MemoryStore < Glue::SafeHash
18
18
 
19
19
  def read(name, options = {})
20
20
  self[name]
21
21
  end
22
22
 
23
- def write(name, content = '', options = {})
23
+ def write(name, content = '', options = {})
24
24
  self[name] = content
25
25
  end
26
26
 
@@ -1,10 +1,12 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: conf.rb 302 2005-03-16 14:31:32Z gmosx $
3
+ # $Id: conf.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'glue/flexob'
6
6
 
7
- module N
7
+ require 'nitro/dispatcher'
8
+
9
+ module Nitro
8
10
 
9
11
  # Configuration.
10
12
 
@@ -18,12 +20,10 @@ class Conf < Flexob
18
20
  # Default configuration parameters.
19
21
 
20
22
  hash = {
21
- :name => 'Nitro Application',
22
- # this is accessible as localhost on windows
23
- :host => '0.0.0.0',
23
+ :name => 'Nitro',
24
+ :host => '0.0.0.0', # this is accessible as localhost on windows.
24
25
  :port => 9999,
25
26
  :dispatcher => Dispatcher.new,
26
-
27
27
  :template_root => 'templates',
28
28
  :public_root => 'public'
29
29
  }
@@ -33,6 +33,11 @@ class Conf < Flexob
33
33
  super(hash)
34
34
  end
35
35
 
36
+ def mount(name, options = {})
37
+ $nitro_mount_options = options
38
+ require_part(name)
39
+ end
40
+
36
41
  end
37
42
 
38
43
  end
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: context.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'nitro/request'
6
6
  require 'nitro/response'
@@ -9,7 +9,7 @@ require 'nitro/session'
9
9
  require 'nitro/output'
10
10
  require 'nitro/adapters/cgi.rb'
11
11
 
12
- module N
12
+ module Nitro
13
13
 
14
14
  # Encapsulates an HTTP processing cycle context.
15
15
  # Integrates the Request and the Response.
@@ -1,13 +1,14 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
- # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
2
+ # (c) 2005 Navel, all rights reserved.
3
+ # $Id: controller.rb 20 2005-04-15 15:18:36Z gmosx $
4
+
5
+ require 'glue/aspects'
4
6
 
5
7
  require 'nitro/render'
6
8
  require 'nitro/scaffold'
7
- require 'nitro/filters'
8
9
  require 'nitro/caching'
9
10
 
10
- module N
11
+ module Nitro
11
12
 
12
13
  # Encapsulates metadata that describe an action
13
14
  # parameter.
@@ -77,8 +78,8 @@ end
77
78
 
78
79
  class Controller
79
80
  include Render
81
+ include Glue::Aspects
80
82
  include Scaffolding
81
- include Filtering
82
83
  include Caching
83
84
 
84
85
  # A hash containing metadata for the action
@@ -113,7 +114,11 @@ class Controller
113
114
 
114
115
  def inherited(child)
115
116
  child.class_eval %{
116
- DEF_FILE = caller[2].to_s.strip.gsub( /:[0-9]+$/ , '')
117
+ if caller[2].to_s.split(':').last =~ /[0-9]+/
118
+ DEF_FILE = caller[2].to_s.strip.gsub( /:[0-9]+$/ , '')
119
+ else
120
+ DEF_FILE = caller[3].to_s.strip.gsub( /:[0-9]+$/ , '')
121
+ end
117
122
 
118
123
  @template_root = 'public'
119
124
 
@@ -143,7 +148,7 @@ class Controller
143
148
  # Some dangerous methods from ancestors are removed.
144
149
 
145
150
  def action_methods
146
- classes = self.ancestors.reject do |a|
151
+ classes = self.ancestors.reject do |a|
147
152
  [Object, Kernel, Render, Controller].include?(a)
148
153
  end
149
154
 
@@ -1,8 +1,8 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: cookie.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
- module N
5
+ module Nitro
6
6
 
7
7
  # Encapsulates a HTTP Cookie.
8
8
 
@@ -1,8 +1,8 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: dispatcher.rb 23 2005-04-16 18:20:00Z gmosx $
4
4
 
5
- module N
5
+ module Nitro
6
6
 
7
7
  require 'nitro/controller'
8
8
  require 'nitro/routing'
@@ -11,6 +11,7 @@ require 'nitro/simple'
11
11
  # The Dispatcher manages a set of controllers.
12
12
 
13
13
  class Dispatcher
14
+
14
15
  include Router
15
16
 
16
17
  # The public root directory. The files in this
@@ -30,10 +31,6 @@ class Dispatcher
30
31
 
31
32
  attr_accessor :controllers
32
33
 
33
- # APIs map.
34
-
35
- attr_accessor :apis
36
-
37
34
  # Create a new Dispatcher.
38
35
  #
39
36
  # Input:
@@ -41,11 +38,8 @@ class Dispatcher
41
38
  # [+controllers+]
42
39
  # Either a hash of controller mappings or a single
43
40
  # controller that gets mapped to :root.
44
- #
45
- # [+apis+]
46
- # A hash of apis supported by the Dispatcher.
47
41
 
48
- def initialize(controllers = nil, apis = nil, routes = nil)
42
+ def initialize(controllers = nil)
49
43
  @public_root = 'public'
50
44
  @template_root = @public_root
51
45
 
@@ -56,8 +50,6 @@ class Dispatcher
56
50
  end
57
51
 
58
52
  mount(controllers)
59
-
60
- @apis = apis || {}
61
53
  end
62
54
 
63
55
  # Process the given hash and mount the
@@ -71,10 +63,10 @@ class Dispatcher
71
63
  #
72
64
  # === Examples
73
65
  #
74
- # dispatcher.mount {
75
- # :root => MainController # mounts /
66
+ # dispatcher.mount(
67
+ # :root => MainController, # mounts /
76
68
  # 'users' => UsersController # mounts /users
77
- # }
69
+ # )
78
70
 
79
71
  def add_controller(controllers)
80
72
  (@controllers ||= {}).update(controllers)
@@ -82,21 +74,6 @@ class Dispatcher
82
74
  end
83
75
  alias_method :mount, :add_controller
84
76
 
85
- # Add a new api to the dispatcher
86
- #
87
- # [+api+]
88
- # API symbol
89
- # [+data+]
90
- # Data for this API [content_type, ..]
91
- #
92
- # === Example
93
- #
94
- # dispatcher.add_api(:xml, 'text/xml')
95
-
96
- def add_api(api, data)
97
- (@apis ||= {})[api] = data
98
- end
99
-
100
77
  # Update the routes. Typically called after a new
101
78
  # Controller is mounted.
102
79
 
@@ -123,15 +100,8 @@ class Dispatcher
123
100
  # The dispatching context.
124
101
 
125
102
  def dispatch(path, context = nil)
126
- api = :xhtml
127
-
128
103
  path = route(path, context)
129
104
 
130
- if @apis
131
- # OPTIMIZE: check only if lookup fails.
132
- @apis.each { |k, v| api = k if path.slice!(/#{k}\//) }
133
- end
134
-
135
105
  parts = path.split('/')
136
106
  parts.shift
137
107
 
@@ -167,23 +137,46 @@ class Dispatcher
167
137
  action = parts.join('__')
168
138
  end
169
139
  end
170
-
171
- content_type = @apis[:api] || 'text/html'
172
140
 
173
- return klass, "__#{api}__#{action}", content_type, base
141
+ return klass, "#{action}_action", base
174
142
  end
175
143
  alias_method :split_path, :dispatch
176
144
 
177
145
  # Get the controller for the given key.
178
146
  # Also handles reloading of controllers.
147
+ #--
148
+ # gmosx, FIXME: this method is a NASTY hack, anyone can
149
+ # help me fix this ?
150
+ #++
179
151
 
180
152
  def controller_class_for(key, context)
181
153
  klass = @controllers[key]
182
154
 
183
155
  if (:full == Rendering.reload) and context and context[:__RELOADED__].nil? and klass
156
+ =begin
157
+ ancestors = [c = klass]
158
+ while (c = c.superclass) != Nitro::Controller
159
+ ancestors.unshift(c)
160
+ end
161
+
162
+ for c in ancestors
163
+ actions = c.public_instance_methods.find_all { |m| m.to_s =~ /(_action$)|(_template$)/ }
164
+ actions += c.action_methods
165
+ actions.each { |m| c.send(:remove_method, m) rescue nil }
166
+ c.advices = []
167
+
168
+ Object.send(:remove_const, c) rescue nil
169
+ load(c::DEF_FILE)
170
+ c = Object.const_get(klass.name.intern)
171
+ end
172
+ =end
173
+ #=begin
184
174
  def_file = klass::DEF_FILE
175
+ # Object.send(:remove_const, klass) rescue nil
176
+ # FIXME: also reload superclasses!
185
177
  Controller.remove_subclasses
186
178
  load(def_file)
179
+ #=end
187
180
  klass = @controllers[key] = Object.const_get(klass.name.intern)
188
181
  context[:__RELOADED__] = true
189
182
  end
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: environment.rb 340 2005-04-04 08:26:58Z gmosx $
3
+ # $Id: environment.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  # Setup up the proposed environment. You are free
6
6
  # to skip this if you dont like it. Just set
@@ -1,13 +1,13 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: l10n.rb 185 2004-12-10 13:29:09Z gmosx $
3
+ # $Id: localization.rb 17 2005-04-14 16:03:40Z gmosx $
4
4
 
5
5
  require 'yaml'
6
6
 
7
- require 'nitro/filters'
7
+ require 'glue/aspects'
8
8
  require 'nitro/shaders'
9
9
 
10
- module N
10
+ module Nitro
11
11
 
12
12
  # Represents a locale.
13
13
  #--
@@ -121,9 +121,9 @@ class Localization
121
121
 
122
122
  end
123
123
 
124
- # Localization filter.
124
+ # Localization Aspect.
125
125
 
126
- module LocalizationFilter
126
+ module LocalizationAspect
127
127
  def localize
128
128
  # @lc = @context.conf.localization[@session[:LOCALE]]
129
129
  @lc = Localization[@context.session[:LOCALE]]
@@ -152,5 +152,3 @@ class LocalizationShader < Shader
152
152
  end
153
153
 
154
154
  end
155
-
156
-
@@ -4,14 +4,14 @@
4
4
  #
5
5
  # * George Moschovitis <gm@navel.gr>
6
6
  # (c) 2004-2005 Navel, all rights reserved.
7
- # $Id: mail.rb 323 2005-03-24 09:43:52Z gmosx $
7
+ # $Id: mail.rb 1 2005-04-11 11:04:30Z gmosx $
8
8
 
9
9
  require 'net/smtp'
10
10
 
11
11
  require 'glue/attribute'
12
12
  require 'nitro/template'
13
13
 
14
- module N
14
+ module Nitro
15
15
 
16
16
  # Encapsulates an email message.
17
17
 
@@ -1,10 +1,10 @@
1
1
  # George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: markup.rb 7 2005-04-12 14:24:10Z gmosx $
4
4
 
5
5
  require 'glue/property'
6
6
 
7
- module N
7
+ module Nitro
8
8
 
9
9
  #--
10
10
  # Override the default PropertyUtils implementation to
@@ -18,13 +18,13 @@ module PropertyUtils
18
18
  s = prop.symbol
19
19
  if markup = prop.meta[:markup]
20
20
  # if true, set to default Markup
21
- markup = N::Markup if true == markup
21
+ markup = Nitro::Markup if true == markup
22
22
 
23
23
  code = %{
24
24
  def #{s}=(val)
25
25
  }
26
26
 
27
- if N::Property.type_checking
27
+ if Property.type_checking
28
28
  code << %{
29
29
  unless String == val.class
30
30
  raise "Invalid type, expected '#{prop.klass}', is '\#\{val.class\}'."
@@ -67,7 +67,7 @@ end
67
67
  #
68
68
  # here comes the #{obj.body} # => prints the expanded version.
69
69
  #
70
- # obj.body = N::Markup.expand(@params['body'])
70
+ # obj.body = Nitro::Markup.expand(@params['body'])
71
71
 
72
72
  module Markup
73
73
  def self.expand_html!(str)
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: output.rb 267 2005-02-28 14:52:41Z gmosx $
3
+ # $Id: output.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'nitro/builders/xml'
6
6
  require 'nitro/builders/xhtml'
@@ -8,7 +8,7 @@ require 'nitro/builders/rss'
8
8
  require 'nitro/builders/form'
9
9
  require 'nitro/builders/table'
10
10
 
11
- module N
11
+ module Nitro
12
12
 
13
13
  # The output buffer string. This buffer integrates
14
14
  # the programmatic rendering support (XhtmlBuilder)
@@ -1,15 +1,15 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
- # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: part.rb 339 2005-04-01 14:02:14Z gmosx $
2
+ # (c) 2005 Navel, all rights reserved.
3
+ # $Id: part.rb 20 2005-04-15 15:18:36Z gmosx $
4
4
 
5
5
  # UNDER CONSTRUCTION, dont use yet!
6
6
 
7
7
  require 'glue/attribute'
8
8
 
9
- module N
9
+ module Nitro
10
10
 
11
11
  class Part
12
- cattr_accessor :parts_root, "/home/gmosx/navel/gen/parts"
12
+ cattr_accessor :parts_root, "/home/gmosx/private/plasma/parts"
13
13
  end
14
14
 
15
15
  end
@@ -17,7 +17,10 @@ end
17
17
  module Kernel
18
18
 
19
19
  def require_part(name)
20
- require "#{N::Part.parts_root}/#{name}/part"
20
+ # gmosx: RDoc complains about this, so lets use an
21
+ # eval, AAAAAAAARGH!
22
+ # require "#{N::Part.parts_root}/#{name}/mount"
23
+ eval %{ require '#{Nitro::Part.parts_root}/#{name}/mount' }
21
24
  end
22
25
 
23
26
  end