nitro 0.31.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/bin/nitro +135 -37
  2. data/doc/CHANGELOG.1 +108 -108
  3. data/doc/CHANGELOG.2 +89 -89
  4. data/doc/CHANGELOG.3 +105 -105
  5. data/{CHANGELOG → doc/CHANGELOG.4} +509 -509
  6. data/doc/{AUTHORS → CONTRIBUTORS} +49 -37
  7. data/doc/LIBRARIES +13 -0
  8. data/doc/LICENSE +2 -3
  9. data/doc/MIGRATION +45 -0
  10. data/doc/RELEASES +131 -11
  11. data/doc/TODO +67 -0
  12. data/lib/glue/magick.rb +0 -3
  13. data/lib/glue/sweeper.rb +30 -15
  14. data/lib/glue/thumbnails.rb +0 -2
  15. data/lib/glue/webfile.rb +23 -11
  16. data/lib/nitro.rb +37 -44
  17. data/lib/nitro/adapter/cgi.rb +0 -3
  18. data/lib/nitro/adapter/console.rb +0 -2
  19. data/lib/nitro/adapter/fastcgi.rb +6 -3
  20. data/lib/nitro/adapter/mongrel.rb +97 -58
  21. data/lib/nitro/adapter/script.rb +4 -6
  22. data/lib/nitro/adapter/webrick.rb +33 -87
  23. data/lib/nitro/adapter/webrick/vcr.rb +85 -0
  24. data/lib/nitro/caching.rb +0 -2
  25. data/lib/nitro/caching/actions.rb +0 -2
  26. data/lib/nitro/caching/fragments.rb +0 -2
  27. data/lib/nitro/caching/output.rb +45 -16
  28. data/lib/nitro/caching/proxy.rb +49 -0
  29. data/lib/nitro/cgi.rb +3 -6
  30. data/lib/nitro/cgi/cookie.rb +0 -3
  31. data/lib/nitro/cgi/request.rb +67 -24
  32. data/lib/nitro/cgi/response.rb +0 -2
  33. data/lib/nitro/cgi/{sendfile.rb → send_file.rb} +7 -6
  34. data/lib/nitro/compiler.rb +62 -55
  35. data/lib/nitro/compiler/cleanup.rb +0 -3
  36. data/lib/nitro/compiler/elements.rb +31 -28
  37. data/lib/nitro/compiler/errors.rb +2 -5
  38. data/lib/nitro/compiler/include.rb +10 -8
  39. data/lib/nitro/compiler/layout.rb +0 -2
  40. data/lib/nitro/compiler/localization.rb +0 -2
  41. data/lib/nitro/compiler/markup.rb +14 -6
  42. data/lib/nitro/compiler/morphing.rb +1 -5
  43. data/lib/nitro/compiler/script.rb +2 -4
  44. data/lib/nitro/compiler/squeeze.rb +0 -2
  45. data/lib/nitro/compiler/xslt.rb +0 -2
  46. data/lib/nitro/context.rb +10 -5
  47. data/lib/nitro/control.rb +18 -0
  48. data/lib/nitro/control/attribute.rb +88 -0
  49. data/lib/nitro/control/attribute/checkbox.rb +19 -0
  50. data/lib/nitro/control/attribute/datetime.rb +21 -0
  51. data/lib/nitro/control/attribute/file.rb +20 -0
  52. data/lib/nitro/control/attribute/fixnum.rb +26 -0
  53. data/lib/nitro/control/attribute/float.rb +26 -0
  54. data/lib/nitro/control/attribute/options.rb +38 -0
  55. data/lib/nitro/control/attribute/password.rb +16 -0
  56. data/lib/nitro/control/attribute/text.rb +16 -0
  57. data/lib/nitro/control/attribute/textarea.rb +16 -0
  58. data/lib/nitro/control/none.rb +16 -0
  59. data/lib/nitro/control/relation.rb +53 -0
  60. data/lib/nitro/control/relation/belongs_to.rb +0 -0
  61. data/lib/nitro/control/relation/has_many.rb +97 -0
  62. data/lib/nitro/control/relation/joins_many.rb +0 -0
  63. data/lib/nitro/control/relation/many_to_many.rb +0 -0
  64. data/lib/nitro/control/relation/refers_to.rb +29 -0
  65. data/lib/nitro/controller.rb +7 -296
  66. data/lib/nitro/dispatcher.rb +72 -34
  67. data/lib/nitro/element.rb +36 -10
  68. data/lib/nitro/element/javascript.rb +0 -2
  69. data/lib/nitro/flash.rb +23 -10
  70. data/lib/nitro/global.rb +36 -11
  71. data/lib/nitro/helper.rb +22 -8
  72. data/lib/nitro/helper/benchmark.rb +0 -2
  73. data/lib/nitro/helper/buffer.rb +0 -3
  74. data/lib/nitro/helper/css.rb +12 -0
  75. data/lib/nitro/helper/debug.rb +1 -3
  76. data/lib/nitro/helper/default.rb +1 -0
  77. data/lib/nitro/helper/feed.rb +400 -386
  78. data/lib/nitro/helper/form.rb +246 -116
  79. data/lib/nitro/helper/javascript.rb +28 -2
  80. data/lib/nitro/helper/javascript/morphing.rb +0 -2
  81. data/lib/nitro/helper/javascript/prototype.rb +0 -2
  82. data/lib/nitro/helper/javascript/scriptaculous.rb +0 -1
  83. data/lib/nitro/helper/layout.rb +0 -2
  84. data/lib/nitro/helper/navigation.rb +87 -0
  85. data/lib/nitro/helper/pager.rb +11 -22
  86. data/lib/nitro/helper/table.rb +9 -32
  87. data/lib/nitro/helper/url.rb +104 -0
  88. data/lib/nitro/helper/xhtml.rb +20 -4
  89. data/lib/nitro/helper/xml.rb +0 -2
  90. data/lib/nitro/markup.rb +131 -0
  91. data/lib/nitro/part.rb +52 -7
  92. data/lib/nitro/publishable.rb +328 -0
  93. data/lib/nitro/render.rb +30 -61
  94. data/lib/nitro/router.rb +12 -4
  95. data/lib/nitro/sanitize.rb +48 -0
  96. data/lib/nitro/scaffold.rb +9 -11
  97. data/lib/nitro/scaffold/controller.rb +25 -0
  98. data/lib/nitro/scaffold/model.rb +150 -0
  99. data/lib/nitro/scaffolding.rb +1 -3
  100. data/lib/nitro/server.rb +57 -32
  101. data/lib/nitro/server/drb.rb +16 -2
  102. data/lib/nitro/server/runner.rb +80 -102
  103. data/lib/nitro/service.rb +0 -1
  104. data/lib/nitro/service/xmlrpc.rb +0 -2
  105. data/lib/nitro/session.rb +26 -18
  106. data/lib/nitro/session/drb.rb +2 -16
  107. data/lib/nitro/session/memory.rb +0 -2
  108. data/lib/nitro/template.rb +219 -0
  109. data/lib/nitro/test/assertions.rb +1 -3
  110. data/lib/nitro/test/context.rb +0 -1
  111. data/lib/nitro/test/testcase.rb +0 -1
  112. data/lib/nitro/version.rb +6 -0
  113. data/lib/part/admin.rb +16 -0
  114. data/lib/part/admin/controller.rb +19 -0
  115. data/lib/part/admin/helper.rb +30 -0
  116. data/lib/part/admin/og/controller.rb +114 -0
  117. data/lib/part/admin/og/customize.rb +4 -0
  118. data/lib/part/admin/og/template/index.xhtml +27 -0
  119. data/lib/part/admin/og/template/list.xhtml +38 -0
  120. data/lib/part/admin/og/template/search.xhtml +20 -0
  121. data/lib/part/admin/og/template/update.xhtml +25 -0
  122. data/lib/part/admin/skin.rb +207 -0
  123. data/lib/part/admin/template/denied.xhtml +13 -0
  124. data/lib/part/admin/template/index.xhtml +12 -0
  125. data/lib/part/admin/todo.txt +2 -0
  126. data/proto/public/error.xhtml +4 -2
  127. data/proto/run.rb +0 -2
  128. data/test/glue/tc_webfile.rb +1 -0
  129. data/test/nitro/cgi/tc_request.rb +23 -0
  130. data/test/nitro/helper/tc_feed.rb +0 -3
  131. data/test/nitro/helper/tc_navbar.rb +74 -0
  132. data/test/nitro/helper/tc_table.rb +2 -0
  133. data/test/nitro/tc_cgi.rb +72 -19
  134. data/test/nitro/tc_controller.rb +35 -26
  135. data/test/nitro/tc_controller_aspect.rb +1 -0
  136. data/test/nitro/tc_controller_params.rb +864 -0
  137. data/test/nitro/tc_dispatcher.rb +2 -2
  138. data/test/nitro/tc_element.rb +16 -16
  139. data/test/nitro/tc_flash.rb +3 -3
  140. data/test/nitro/tc_markup.rb +31 -0
  141. data/test/nitro/tc_render.rb +12 -14
  142. data/test/nitro/tc_session.rb +9 -7
  143. data/test/nitro/tc_template.rb +34 -0
  144. metadata +217 -198
  145. data/INSTALL +0 -121
  146. data/ProjectInfo +0 -74
  147. data/README +0 -555
  148. data/doc/apache.txt +0 -9
  149. data/doc/config.txt +0 -28
  150. data/doc/faq.txt +0 -7
  151. data/doc/lhttpd.txt +0 -7
  152. data/lib/nitro/adapter/scgi.rb +0 -239
  153. data/lib/nitro/helper/form/builder.rb +0 -144
  154. data/lib/nitro/helper/form/controls.rb +0 -389
  155. data/lib/nitro/helper/rss.rb +0 -72
  156. data/proto/conf/apache.conf +0 -51
  157. data/proto/public/scaffold/advanced_search.xhtml +0 -30
  158. data/proto/public/scaffold/edit.xhtml +0 -11
  159. data/proto/public/scaffold/form.xhtml +0 -1
  160. data/proto/public/scaffold/index.xhtml +0 -20
  161. data/proto/public/scaffold/list.xhtml +0 -32
  162. data/proto/public/scaffold/new.xhtml +0 -11
  163. data/proto/public/scaffold/search.xhtml +0 -29
  164. data/proto/public/scaffold/view.xhtml +0 -8
  165. data/proto/script/scgi_ctl +0 -221
  166. data/proto/script/scgi_service +0 -128
  167. data/setup.rb +0 -1585
  168. data/src/part/admin.rb +0 -16
  169. data/src/part/admin/controller.rb +0 -81
  170. data/src/part/admin/skin.rb +0 -21
  171. data/src/part/admin/system.css +0 -135
  172. data/src/part/admin/template/denied.xhtml +0 -1
  173. data/src/part/admin/template/index.xhtml +0 -43
  174. data/test/nitro/helper/tc_rss.rb +0 -24
@@ -78,7 +78,7 @@ class Cgi
78
78
 
79
79
  def self.structure_param(params, key, val)
80
80
  if key =~ /(.+)\[(.+)\]$/ or key =~ /([^\.]+)\.(.+)$/
81
- params[$1] ||= Hash.new
81
+ params[$1] ||= Dictionary.new
82
82
  params[$1] = structure_param(params[$1], $2, val)
83
83
  elsif key =~ /(.+)\[\]$/
84
84
  params[$1] ||= Array.new
@@ -94,7 +94,7 @@ class Cgi
94
94
  # in parse_request_params is not done here.
95
95
 
96
96
  def self.parse_query_string(query_string)
97
- params = {}
97
+ params = Dictionary.new
98
98
 
99
99
  # gmosx, THINK: better return nil here?
100
100
  return params if (query_string.nil? or query_string.empty?)
@@ -261,7 +261,7 @@ class Cgi
261
261
  else
262
262
  input.read(content_length)
263
263
  end
264
- if c.nil?
264
+ if c.nil? || c.empty?
265
265
  raise EOFError, "bad content body"
266
266
  end
267
267
  buf.concat(c)
@@ -315,6 +315,3 @@ class Cgi
315
315
  end
316
316
 
317
317
  end
318
-
319
- # * George Moschovitis <gm@navel.gr>
320
- # * Guillaume Pierronnet <guillaume.pierronnet@gmail.com>
@@ -46,6 +46,3 @@ class Cookie
46
46
  end
47
47
 
48
48
  end
49
-
50
- # * George Moschovitis <gm@navel.gr>
51
-
@@ -21,12 +21,13 @@ module Request
21
21
  # The parsed query parameters collection.
22
22
 
23
23
  attr_accessor :params
24
- alias_method :query, :params
25
-
24
+ alias query params
25
+ alias parameters params
26
+
26
27
  # The request cookies.
27
28
 
28
29
  attr_accessor :cookies
29
- alias_method :cookie, :cookies
30
+ alias cookie cookies
30
31
 
31
32
  # The request protocol.
32
33
 
@@ -58,11 +59,11 @@ module Request
58
59
  end
59
60
 
60
61
  # Returns the domain part of a host.
61
- #
62
- # === Examples
63
- #
64
- # www.nitroproject.org: request.domain # => 'nitroproject.org'
65
- # www.nitroproject.co.uk: request.domain(2) # => 'nitroproject.co.uk'
62
+ #
63
+ # === Examples
64
+ #
65
+ # www.nitroproject.org: request.domain # => 'nitroproject.org'
66
+ # www.nitroproject.co.uk: request.domain(2) # => 'nitroproject.co.uk'
66
67
 
67
68
  def domain tld_length = 1
68
69
  host.split('.').last(1 + tld_length).join('.')
@@ -95,6 +96,12 @@ module Request
95
96
  headers['QUERY_STRING']
96
97
  end
97
98
 
99
+ # The parameters the action will be called with
100
+
101
+ def action_params
102
+ headers['ACTION_PARAMS']
103
+ end
104
+
98
105
  # The request method. Alternatively you could use the
99
106
  # request method predicates.
100
107
  #
@@ -168,7 +175,7 @@ module Request
168
175
  not /XMLHttpRequest/i.match(@headers['HTTP_X_REQUESTED_WITH']).nil?
169
176
  end
170
177
  alias xhr? :xml_http_request?
171
- alias ajax? :xml_http_request?
178
+ alias script? :xml_http_request?
172
179
 
173
180
  # Return the referer. For the initial page in the
174
181
  # clickstream there is no referer, set "/" by default.
@@ -197,7 +204,7 @@ module Request
197
204
 
198
205
  if @headers.include?('HTTP_X_FORWARDED_FOR') then
199
206
  remote_ips = @headers['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
200
- ip =~ /^unknown$|^(127|10|172\.16|192\.168)\./i
207
+ ip =~ /^unknown$/i or local_net?(ip)
201
208
  end
202
209
 
203
210
  return remote_ips.first.strip unless remote_ips.empty?
@@ -206,6 +213,30 @@ module Request
206
213
  return @headers['REMOTE_ADDR']
207
214
  end
208
215
 
216
+ # Request is from a local network? (RFC1918 + localhost)
217
+
218
+ def local_net?(ip = remote_ip)
219
+ bip = ip.split('.').map{ |x| x.to_i }.pack('C4').unpack('N')[0]
220
+
221
+ # 127.0.0.1/32 => 2130706433
222
+ # 192.168.0.0/16 => 49320
223
+ # 172.16.0.0/12 => 2753
224
+ # 10.0.0.0/8 => 10
225
+
226
+ { 0 => 2130706433, 16 => 49320, 20 => 2753, 24 => 10}.each do |s,c|
227
+ return true if (bip >> s) == c
228
+ end
229
+
230
+ return false
231
+ end
232
+
233
+ # Request comming from local?
234
+
235
+ def local?(ip = remote_ip)
236
+ # TODO: should check if requesting machine is the one the server is running
237
+ return true if ip == '127.0.0.1'
238
+ end
239
+
209
240
  # The server port.
210
241
 
211
242
  def port
@@ -242,28 +273,36 @@ module Request
242
273
  end
243
274
 
244
275
  # Lookup a query parameter.
245
-
246
- def [] param
276
+ #--
277
+ # TODO: Check if unescape is needed.
278
+ #++
279
+
280
+ def [](param)
247
281
  @params[param]
282
+ =begin
283
+ if par = @params[param] and par.is_a?(String)
284
+ CGI.unescape(par)
285
+ end
286
+ =end
248
287
  end
249
288
 
250
289
  # Set a query parameter.
251
290
 
252
- def []= param, value
291
+ def []=(param, value)
253
292
  @params[param] = value
254
293
  end
255
294
 
256
295
  # Check if a boolean param (checkbox) is true.
257
296
 
258
- def true? param
297
+ def true?(param)
259
298
  @params[param] == 'on'
260
299
  end
261
- alias_method :enabled?, :true?
262
- alias_method :boolean, :true?
300
+ alias enabled? true?
301
+ alias boolean true?
263
302
 
264
303
  # Check if a boolean param (checkbox) is false.
265
304
 
266
- def false? param
305
+ def false?(param)
267
306
  !true?(param)
268
307
  end
269
308
 
@@ -274,15 +313,19 @@ module Request
274
313
  end
275
314
 
276
315
  # Check if a param is available.
277
-
316
+ #--
317
+ # gmosx: use nil test instead of has_key? to be more robust.
318
+ # (nil can be a hash element !)
319
+ #++
320
+
278
321
  def has_key? key
279
- @params.has_key?(key)
322
+ !@params[key].nil?
280
323
  end
281
- alias_method :has_param?, :has_key?
282
- alias_method :param?, :has_key?
324
+ alias has_param? has_key?
325
+ alias param? has_key?
326
+ alias has? has_key?
327
+ alias is? has_key?
328
+
283
329
  end
284
330
 
285
331
  end
286
-
287
- # * George Moschovitis <gm@navel.gr>
288
- # * Guillaume Pierronnet <guillaume.pierronnet@laposte.net>
@@ -49,5 +49,3 @@ module Response
49
49
  end
50
50
 
51
51
  end
52
-
53
- # * George Moschovitis <gm@navel.gr>
@@ -16,20 +16,21 @@ module Render
16
16
  #
17
17
  # === Examples
18
18
  #
19
- # require 'nitro/cgi/sendfile'
19
+ # require 'nitro/cgi/send_file'
20
+ #
20
21
  # class MyController < Nitro:Controller
21
22
  # def download(fname)
22
- # sendfile(fname)
23
+ # send_file(fname)
23
24
  # end
24
25
  # end
25
26
  #
26
27
  # class MyController < Nitro:Controller
27
28
  # def download()
28
- # sendfile('/etc/password', true)
29
+ # send_file('/etc/password', true)
29
30
  # end
30
31
  # end
31
-
32
- def sendfile(fname=nil, fullpath=false)
32
+
33
+ def send_file(fname=nil, fullpath=false)
33
34
  fname = fullpath ? fname : "#{Server.public_root}/#{fname}"
34
35
  f = File.open(fname, "rb")
35
36
  @context.response_headers["Cache-control"] = 'private'
@@ -38,8 +39,8 @@ module Render
38
39
  @context.out = f
39
40
  raise RenderExit
40
41
  end
42
+ alias sendfile send_file
41
43
 
42
44
  end
43
45
 
44
46
  end
45
-
@@ -1,4 +1,4 @@
1
- require 'glue/template'
1
+ require 'nitro/template'
2
2
 
3
3
  require 'nitro/compiler/errors'
4
4
 
@@ -59,7 +59,24 @@ class Compiler
59
59
  # ...
60
60
  # end
61
61
 
62
- setting :transformation_pipeline, :default => [StaticInclude, Morphing, Elements, Markup, ScriptCompiler, Cleanup], :doc => 'The default transformation pipeline'
62
+ setting :transformation_pipeline, :default => [StaticInclude, Morphing, ElementCompiler, MarkupCompiler, ScriptCompiler, Cleanup], :doc => 'The default transformation pipeline'
63
+
64
+
65
+ # This specifies if
66
+ # def my_action(oid, val)
67
+ # should handle both
68
+ # my_action/1/23
69
+ # and
70
+ # my_action?oid=1;val=23
71
+
72
+ setting :mixin_get_parameters, :default => true
73
+
74
+ # Treats
75
+ # def my_action(oid, val)
76
+ # as
77
+ # def my_action(oid = nil, val = nil)
78
+
79
+ setting :non_strict_action_calling, :default => false
63
80
 
64
81
  def initialize(controller = nil)
65
82
  @controller = controller
@@ -75,7 +92,8 @@ class Compiler
75
92
  # hello_world -> template_root/hello_world.xhtml
76
93
  # this__is__my__hello_world -> template_root/this/is/my/hello_world
77
94
 
78
- def template_for_action(action, ext = Glue::Template.extension)
95
+ def template_for_action(action, ext = Template.extension)
96
+ action = action.to_s
79
97
  for template_root in @controller.instance_variable_get(:@template_root)
80
98
  # attempt to find a template of the form
81
99
  # template_root/action.xhtml
@@ -86,7 +104,7 @@ class Compiler
86
104
  # attempt to find a template of the form
87
105
  # template_root/action/index.xhtml
88
106
 
89
- path = "#{template_root}/#{action.gsub(/__/, '/')}/#{Glue::Template.default}.#{ext}".squeeze('/')
107
+ path = "#{template_root}/#{action.gsub(/__/, '/')}/#{Template.default}.#{ext}".squeeze('/')
90
108
  return path if File.exist?(path)
91
109
  end
92
110
  return nil
@@ -174,7 +192,7 @@ class Compiler
174
192
  #
175
193
  # This generated method is called by the dispatcher.
176
194
  #
177
- # === Glue::Template root overloading
195
+ # === Template root overloading
178
196
  #
179
197
  # Nitro provides a nice method of template_root overloading
180
198
  # that allows you to use OOP principles with templates.
@@ -229,47 +247,40 @@ class Compiler
229
247
  params = params.collect { |p| "@#{p} = @context['#{p}']" }
230
248
  code << "#{params.join(';')}"
231
249
  end
232
-
233
- # Try to resolve action parameters. Returns negative
234
- # numbers for arbitrary parameters.
235
- #--
236
- # gmosx: This needs a better implementation. Better means
237
- # cleaner and more optimized code.
238
- #++
239
-
240
- param_count = @controller.instance_method(action.to_sym).arity
241
250
 
242
- if param_count != 0
243
- code << %{
244
- params = []
245
- unless context.query_string.blank?
246
- all_params = context.query_string.split(/[&;]/)
247
- is_hash = all_params.first.index('=')
248
- all_params.each_with_index do |qs, i|
249
- }
250
- # Don't pass more parameters than the action's arity.
251
- if param_count > 0
252
- code << "break unless i < #{param_count};"
251
+ arity = @controller.instance_method(action.to_sym).arity
252
+
253
+ # Call action with given parameters, raises ActionError when the params
254
+ # are wrong.
255
+ # TODO: return 404 or other error code for browser?
256
+
257
+ code << %{
258
+ params = context.action_params || []
259
+
260
+ # Fill not given parameters with nils
261
+
262
+ arity = (#{arity} < -1) ? (#{arity}.abs - 1) : #{arity}
263
+ if Nitro::Compiler.non_strict_action_calling
264
+ arity.times {|i| params[i] ? nil : params[i] = nil }
253
265
  end
254
- code << %{
255
- break if qs.index('=') and not is_hash
256
- params << CGI.unescape(qs.split(/=/).last || "")
257
- end
258
- end
259
-
260
- # Concatenate some extracted parameters.
261
- # params.concat(context.params.values)
262
-
263
- # Fill the array with nils for the missing params.
264
- (#{param_count} - params.size).times { params << nil }
265
-
266
+
267
+ # When arity zero, ignore params
268
+ params.clear if arity == 0
269
+
270
+ if Nitro::Compiler.mixin_get_parameters && params.empty? && arity > 0
271
+ context.params.each_with_index do |(k,v),i|
272
+ break if i > arity
273
+ params << v
274
+ end
275
+ end
276
+
277
+ begin
266
278
  action_return_value = #{action}(*params)
267
- }
268
- else
269
- code << %{
270
- action_return_value = #{action}
271
- }
272
- end
279
+ rescue ArgumentError => e
280
+ raise ActionError, "Wrong parameter count for \#{@action_name}(\#{params.join(', ')})."
281
+ end
282
+ }
283
+
273
284
  code << %{
274
285
  unless :stop == action_return_value
275
286
  }
@@ -285,14 +296,15 @@ class Compiler
285
296
  # better practice to place the output related code in an
286
297
  # external template file.
287
298
 
288
- # Take :view annotation into account.
299
+ # Take :template annotation into account.
289
300
 
290
- view = @controller.ann(action.to_sym).view # FIXME
291
- view = action if view.nil?
301
+ unless template = @controller.ann(action.to_sym)[:template] # FIXME
302
+ template = action
303
+ end
292
304
 
293
305
  # Search the [controller] class and it's ancestors for the template
294
306
 
295
- template_path = template_for_action(view.to_s)
307
+ template_path = template_for_action(template.to_s)
296
308
  if template_path or @controller.instance_methods.include?("#{action}_template")
297
309
  valid = true
298
310
  code << %{
@@ -313,7 +325,7 @@ class Compiler
313
325
 
314
326
  if Render.redirect_on_empty
315
327
  code << %{
316
- redirect_referer if @out.empty?
328
+ redirect_to_referer if @out.empty?
317
329
  }
318
330
  end
319
331
 
@@ -354,12 +366,12 @@ class Compiler
354
366
  # Typically used to precompile css templates.
355
367
 
356
368
  def precompile(filename)
357
- src = File.join(Glue::Template.root, "#{filename}t")
369
+ src = File.join(Template.root, "#{filename}t")
358
370
  dst = File.join(Server.public_root, filename)
359
371
 
360
372
  if (!File.exist?(dst)) or (File.mtime(src) > File.mtime(dst))
361
373
  Logger.info "Compiling template '#{src}' to '#{dst}'."
362
- template = Glue::FileTemplate.new(src)
374
+ template = FileTemplate.new(src)
363
375
  File.open(dst, 'w') do |f|
364
376
  f << template.process
365
377
  end
@@ -371,8 +383,3 @@ class Compiler
371
383
  end
372
384
 
373
385
  end
374
-
375
- # * George Moschovitis <gm@navel.gr>
376
- # * Chris Farmiloe <chris.farmiloe@farmiloe.com>
377
- # * Rob Pitt <rob@motionpath.co.uk>
378
- # * Jonas Pfenniger <zimba.tm@gmail.com>
@@ -11,6 +11,3 @@ module Cleanup
11
11
  end
12
12
 
13
13
  end
14
-
15
- # * George Moschovitis <gm@navel.gr>
16
- # * Chris Farmiloe <chris.farmiloe@farmiloe.com>
@@ -3,7 +3,7 @@ require 'rexml/streamlistener'
3
3
  require 'facet/class/by_name'
4
4
 
5
5
  require 'nitro/element'
6
- require "glue/html"
6
+ require 'glue/html'
7
7
 
8
8
 
9
9
  module Nitro
@@ -62,6 +62,7 @@ class Elements # :nodoc: all
62
62
  def tag_end(name)
63
63
  # check if the name starts with the element prefix, or
64
64
  # is capitalized.
65
+
65
66
  if is_element? name
66
67
  obj, @buffer, @parent = @stack.pop
67
68
  @buffer << obj.render
@@ -71,10 +72,10 @@ class Elements # :nodoc: all
71
72
  end
72
73
 
73
74
 
74
- # Check if a tag is a Nitro::Element. If found, it also tries to
75
- # auto-extend the klass.
76
- #
77
- # returns the Element class if found
75
+ # Check if a tag is a Nitro::Element. If found, it also
76
+ # tries to auto-extend the klass. Returns the Element class
77
+ # if found.
78
+
78
79
  def is_element?(name)
79
80
  # Doesn't support modulized classes
80
81
  # name = name.demodulize
@@ -82,34 +83,42 @@ class Elements # :nodoc: all
82
83
 
83
84
  name = name.gsub(PREFIX_RE,'').camelize if name =~ PREFIX_RE
84
85
 
85
- # First try to use Nitro::Element::xxx then ::xxx
86
+ # Try to use Controller::xxx
87
+ #--
88
+ # gmosx, THINK: this looks a bit dangerous to me!
89
+ #++
86
90
 
87
91
  begin
88
- klass = Class.by_name("Nitro::Element::#{name}")
92
+ #--
93
+ # gmosx, FIXME: Class.by_name also returns top level
94
+ # classes, how can we fix this?
95
+ #++
96
+ klass = Class.by_name("#{@compiler.controller}::#{name}")
89
97
  rescue
98
+ # drink it!
90
99
  end
91
100
 
92
- # Look into the module the controller's module if any
101
+ # Try to use the Controller's :elements annotation
93
102
 
94
- begin
95
- namespace = @compiler.controller.name
96
- if /::/ =~ namespace
97
- namespace = namespace.gsub( /::[a-zA-Z]+$/, "::#{name}" )
98
- klass = Class.by_name(namespace)
103
+ if (!klass) and namespace = @compiler.controller.ann.self[:element_namespace]
104
+ begin
105
+ klass = Class.by_name("#{namespace}::#{name}")
106
+ rescue
107
+ # drink it!
99
108
  end
100
- rescue
101
- end unless klass
102
-
103
- # Look in the root module
109
+ end
104
110
 
111
+ # Try to use Nitro::Element::xxx then ::xxx
112
+
105
113
  begin
106
- klass = Class.by_name(name)
114
+ klass = Class.by_name("Nitro::Element::#{name}")
107
115
  rescue
116
+ # drink it!
108
117
  end unless klass
109
118
 
110
- return false unless klass.kind_of?( Class )
119
+ return false unless klass.kind_of? Class
111
120
 
112
- # Try to auto-extend
121
+ # Try to auto-extend.
113
122
 
114
123
  unless klass.ancestors.include? Nitro::Element
115
124
  if Element.auto_extend
@@ -131,7 +140,7 @@ class Elements # :nodoc: all
131
140
  end
132
141
 
133
142
  def comment(c)
134
- unless Glue::Template.strip_xml_comments
143
+ unless Template.strip_xml_comments
135
144
  @buffer << "<!--#{c}-->"
136
145
  end
137
146
  end
@@ -163,14 +172,8 @@ class Elements # :nodoc: all
163
172
  end
164
173
  end
165
174
 
166
- # An (old) alias.
167
-
168
- unless const_defined? :ElementProcessor
169
- ElementProcessor = Elements
175
+ unless const_defined? :ElementCompiler
170
176
  ElementCompiler = Elements
171
177
  end
172
178
 
173
179
  end
174
-
175
- # * George Moschovitis <gm@navel.gr>
176
- # * Chris Farmiloe <chris.farmiloe@farmiloe.com>