nitro 0.24.0 → 0.25.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 (67) hide show
  1. data/CHANGELOG +279 -0
  2. data/ProjectInfo +7 -7
  3. data/doc/AUTHORS +4 -2
  4. data/doc/RELEASES +96 -1
  5. data/lib/nitro.rb +5 -2
  6. data/lib/nitro/adapter/cgi.rb +1 -1
  7. data/lib/nitro/adapter/webrick.rb +7 -5
  8. data/lib/nitro/caching/output.rb +3 -2
  9. data/lib/nitro/cgi/utils.rb +8 -4
  10. data/lib/nitro/compiler.rb +9 -5
  11. data/lib/nitro/compiler/include.rb +42 -0
  12. data/lib/nitro/compiler/markup.rb +1 -1
  13. data/lib/nitro/compiler/morphing.rb +120 -50
  14. data/lib/nitro/compiler/squeeze.rb +2 -2
  15. data/lib/nitro/context.rb +9 -0
  16. data/lib/nitro/controller.rb +8 -4
  17. data/lib/nitro/dispatcher.rb +5 -5
  18. data/lib/nitro/dispatcher/nice.rb +16 -5
  19. data/lib/nitro/element.rb +30 -8
  20. data/lib/nitro/helper.rb +56 -0
  21. data/lib/nitro/{mixin → helper}/benchmark.rb +1 -1
  22. data/lib/nitro/{mixin → helper}/buffer.rb +1 -2
  23. data/lib/nitro/{mixin → helper}/debug.rb +1 -1
  24. data/lib/nitro/{mixin/helper.rb → helper/default.rb} +4 -4
  25. data/lib/nitro/{mixin → helper}/form.rb +3 -3
  26. data/lib/nitro/{mixin → helper}/javascript.rb +17 -1
  27. data/lib/nitro/{mixin → helper}/pager.rb +1 -1
  28. data/lib/nitro/{mixin → helper}/rss.rb +3 -3
  29. data/lib/nitro/{mixin → helper}/table.rb +1 -1
  30. data/lib/nitro/{mixin → helper}/xhtml.rb +2 -2
  31. data/lib/nitro/{mixin → helper}/xml.rb +1 -1
  32. data/lib/nitro/render.rb +16 -8
  33. data/lib/nitro/scaffold.rb +6 -6
  34. data/lib/nitro/server/runner.rb +12 -0
  35. data/lib/nitro/session/drbserver.rb +16 -1
  36. data/proto/public/js/builder.js +97 -0
  37. data/proto/public/js/controls.js +18 -5
  38. data/proto/public/js/dragdrop.js +8 -5
  39. data/proto/public/js/effects.js +185 -4
  40. data/proto/public/js/prototype.js +432 -178
  41. data/proto/public/js/scriptaculous.js +6 -2
  42. data/proto/public/js/slider.js +226 -0
  43. data/proto/public/js/unittest.js +363 -0
  44. data/proto/public/media/nitro.png +0 -0
  45. data/{script → proto/script}/scgi_ctl +0 -0
  46. data/{script → proto/script}/scgi_service +16 -8
  47. data/proto/src/skin.rb +24 -0
  48. data/{lib → src}/part/admin.rb +0 -0
  49. data/src/part/admin/controller.rb +47 -0
  50. data/{lib → src}/part/admin/skin.rb +0 -0
  51. data/src/part/admin/template/denied.xhtml +1 -0
  52. data/{lib → src}/part/admin/template/index.xhtml +0 -0
  53. data/test/nitro/{mixin → helper}/tc_pager.rb +2 -2
  54. data/test/nitro/{mixin → helper}/tc_rss.rb +3 -3
  55. data/test/nitro/{mixin → helper}/tc_table.rb +3 -3
  56. data/test/nitro/{mixin → helper}/tc_xhtml.rb +3 -3
  57. data/test/nitro/tc_caching.rb +4 -1
  58. data/test/nitro/tc_controller.rb +2 -2
  59. data/test/nitro/tc_element.rb +30 -0
  60. data/test/nitro/tc_helper.rb +36 -0
  61. data/test/nitro/tc_render.rb +1 -1
  62. metadata +70 -38
  63. data/lib/nitro/mixin/markup.rb +0 -122
  64. data/lib/part/admin/controller.rb +0 -28
  65. data/proto/README +0 -11
  66. data/proto/doc/README +0 -1
  67. data/proto/scgi.rb +0 -333
@@ -2,7 +2,7 @@ require 'nano/kernel/singleton'
2
2
 
3
3
  require 'nitro/controller'
4
4
  require 'nitro/routing'
5
- require 'nitro/mixin/helper'
5
+ require 'nitro/helper/default'
6
6
 
7
7
  module Nitro
8
8
 
@@ -114,14 +114,14 @@ class Dispatcher
114
114
 
115
115
  # Call this method to automatically include helpers in the
116
116
  # Controllers. For each Controller 'XxxController' the
117
- # default helper 'Helper' and the auto mixin
118
- # 'XxxControllerMixin' (if it exists) are included.
117
+ # default helper 'Helper' and the auto helper
118
+ # 'XxxControllerHelper' (if it exists) are included.
119
119
 
120
120
  def auto_mixin(c)
121
- c.helper(Helper)
121
+ c.helper(Nitro::DefaultHelper)
122
122
 
123
123
  begin
124
- if helper = Module.by_name("#{c}Mixin")
124
+ if helper = Module.by_name("#{c}Helper")
125
125
  c.helper(helper)
126
126
  end
127
127
  rescue NameError
@@ -6,8 +6,11 @@ module Nitro
6
6
 
7
7
  class Dispatcher
8
8
 
9
- # An alternative dispatching algorithm that handles
10
- # implicit nice urls. Subdirectories are not supported.
9
+ # The default dispatching algorithm that handles
10
+ # implicit nice urls. Subdirectories are supported.
11
+ # Action containing '/' separators look for templates
12
+ # in subdirectories. The '/' char is converted to '__'
13
+ # to find the actual action.
11
14
  #
12
15
  # Returns the dispatcher class, the action name and the
13
16
  # base url. For the root path, the base url is nil.
@@ -17,18 +20,26 @@ class Dispatcher
17
20
 
18
21
  parts = path.split('/')
19
22
  parts.shift # get rid of the leading '/'.
20
-
23
+
21
24
  if klass = controller_class_for("/#{parts.first}")
22
25
  base = "/#{parts.shift}"
23
26
  else
24
27
  base = nil
25
28
  klass = controller_class_for(ROOT)
26
29
  end
27
-
30
+ =begin
31
+ if klass.action_methods.include?(parts.first)
32
+ action = parts.shift
33
+ else
34
+ action = 'index'
35
+ end
36
+ p '---', action
37
+ getc
38
+ =end
28
39
  unless action = parts.shift
29
40
  action = 'index'
30
41
  end
31
-
42
+
32
43
  unless parts.empty?
33
44
  context.headers['QUERY_STRING'] = "#{parts.join(';')};#{context.headers['QUERY_STRING']}"
34
45
  end
data/lib/nitro/element.rb CHANGED
@@ -3,7 +3,9 @@ require 'rexml/streamlistener'
3
3
 
4
4
  require 'nano/string/capitalized'
5
5
  require 'nano/string/camelize'
6
+ require 'mega/annotation'
6
7
 
8
+ require 'glue/flexob'
7
9
  require 'glue/configuration'
8
10
 
9
11
  module Nitro
@@ -28,10 +30,14 @@ class Element
28
30
 
29
31
  attr_accessor :_parent
30
32
 
31
- # The childrens of this element.
33
+ # The children of this element.
32
34
 
33
35
  attr_accessor :_children
34
36
 
37
+ # The named children of this element.
38
+
39
+ attr_accessor :_named
40
+
35
41
  # The text of this element.
36
42
 
37
43
  attr_accessor :_text
@@ -42,15 +48,22 @@ class Element
42
48
 
43
49
  def initialize(*args)
44
50
  @_children = []
51
+ @_named = Flexob.new
45
52
  @_text = ''
46
53
  end
47
54
 
48
55
  def open
49
56
  end
50
57
 
51
- def content
52
- # "#{@_text}#{render_children}"
53
- @_text
58
+ # If an optional name parameter is passed renders
59
+ # the content of the named child element.
60
+
61
+ def content(cname = nil)
62
+ if cname
63
+ @_named[cname].content
64
+ else
65
+ @_text
66
+ end
54
67
  end
55
68
 
56
69
  def close
@@ -72,9 +85,18 @@ class Element
72
85
  def add_child(child)
73
86
  child._parent = self
74
87
  @_children << child
88
+ if cname = child.class.ann.self[:name]
89
+ @_named[cname] = child
90
+ end
75
91
  end
76
92
 
77
93
  alias_method :children, :_children
94
+
95
+ class << self
96
+ def name(sym)
97
+ ann self, :name => sym.to_sym
98
+ end
99
+ end
78
100
  end
79
101
 
80
102
  # Processes a page containing elements.
@@ -100,7 +122,7 @@ class ElementProcessor # :nodoc: all
100
122
  # check if the name starts with the element prefix, or
101
123
  # is capitalized.
102
124
  if name =~ PREFIX_RE or name =~ CAPITALIZED_RE
103
- name = name.split(':')[1].camelize if name =~ PREFIX_RE
125
+ name = name.split(':')[1].camelize if name =~ PREFIX_RE
104
126
 
105
127
  obj = Object.const_get(name).new
106
128
 
@@ -108,10 +130,11 @@ class ElementProcessor # :nodoc: all
108
130
  obj.instance_variable_set("@#{k}", v)
109
131
  end
110
132
 
111
- @stack.push [obj, @buffer]
133
+ @stack.push [obj, @buffer, @parent]
112
134
 
113
135
  @buffer = obj._text
114
136
  @parent.add_child(obj) if @parent
137
+
115
138
  @parent = obj
116
139
  else # This is a static element.
117
140
  attrs = []
@@ -131,7 +154,7 @@ class ElementProcessor # :nodoc: all
131
154
  # is capitalized.
132
155
  if name =~ PREFIX_RE or name =~ CAPITALIZED_RE
133
156
  name = name.split(':')[1].camelize if name =~ PREFIX_RE
134
- obj, @buffer = @stack.pop
157
+ obj, @buffer, @parent = @stack.pop
135
158
  @buffer << obj.render
136
159
  else
137
160
  @buffer << "</#{name}>"
@@ -155,7 +178,6 @@ class ElementProcessor # :nodoc: all
155
178
  def transform(source)
156
179
  self.new.transform(source)
157
180
  end
158
-
159
181
  end
160
182
 
161
183
  # Expand the elemens found in source.
@@ -0,0 +1,56 @@
1
+ require 'nano/kernel/constant'
2
+ require 'nano/string/camelize'
3
+
4
+ require 'glue/attribute'
5
+
6
+ module Nitro
7
+
8
+ # Helpers are standard Ruby modules that contain utility
9
+ # methods. By using the special 'helper'
10
+ # macro provided by Helpers, the utility methods are
11
+ # included as private methods.
12
+ #
13
+ # === Examples
14
+ #
15
+ # class MyController < Nitro::Controller
16
+ # helper :xhtml # == include Nitro::XhtmlHelper
17
+ # end
18
+
19
+ module Helpers
20
+
21
+ module Utils
22
+
23
+ #--
24
+ # gmosx: dont name constant to avoid loop.
25
+ #++
26
+
27
+ def self.const(mod)
28
+ return constant(mod)
29
+ rescue NameError => ex
30
+ return nil
31
+ end
32
+ end
33
+
34
+ def self.append_features(base)
35
+ super
36
+ base.module_eval do
37
+ def self.helper(*modules)
38
+ for mod in modules
39
+ unless mod.is_a? Module
40
+ mod = mod.to_s.camelize
41
+ # gmosx: check xxxHelper before xxx.
42
+ mod = Utils.const("#{mod}Helper") || Utils.const("Nitro::#{mod}Helper") || Utils.const(mod)
43
+ end
44
+ symbols = mod.instance_methods.collect { |m| m.to_sym }
45
+ self.send(:include, mod)
46
+ self.send(:private, *symbols)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ # * George Moschovitis <gm@navel.gr>
@@ -2,7 +2,7 @@ require 'benchmark'
2
2
 
3
3
  module Nitro
4
4
 
5
- module BenchmarkMixin
5
+ module BenchmarkHelper
6
6
 
7
7
  def benchmark(message = 'Benchmarking')
8
8
  real = Benchmark.realtime { yield }
@@ -10,13 +10,12 @@ module Nitro
10
10
  # <?r buf = capture do ?>
11
11
  # ...
12
12
  # <?r end ?>
13
- #
14
13
  #--
15
14
  # TODO: use better names but keep the ob_xxx php style methods
16
15
  # as aliases.
17
16
  #++
18
17
 
19
- module BufferMixin
18
+ module BufferHelper
20
19
 
21
20
  private
22
21
 
@@ -2,7 +2,7 @@ module Nitro
2
2
 
3
3
  # A collection of useful debuging methods.
4
4
 
5
- module DebugMixin
5
+ module DebugHelper
6
6
 
7
7
  private
8
8
 
@@ -1,13 +1,13 @@
1
- require 'nitro/mixin/debug'
1
+ require 'nitro/helper/debug'
2
2
 
3
3
  module Nitro
4
4
 
5
- # This mixin is included by default in all Controllers.
5
+ # This helper is included by default in all Controllers.
6
6
  # This is the place to add general purpose utility methods to
7
7
  # be shared accross all Controllers.
8
8
 
9
- module Helper
10
- include DebugMixin
9
+ module DefaultHelper
10
+ include DebugHelper
11
11
  # This is an open module, extend in your application.
12
12
  end
13
13
 
@@ -1,6 +1,6 @@
1
1
  require 'nano/inflect'
2
2
 
3
- require 'nitro/mixin/xhtml'
3
+ require 'nitro/helper/xhtml'
4
4
  require 'og/relation/all'
5
5
 
6
6
  module Nitro
@@ -12,11 +12,11 @@ module Nitro
12
12
  # overrides.
13
13
  #++
14
14
 
15
- module FormMixin
15
+ module FormHelper
16
16
 
17
17
  def self.included(base)
18
18
  super
19
- base.send :include, XhtmlMixin
19
+ base.send :include, XhtmlHelper
20
20
  end
21
21
 
22
22
  private
@@ -9,7 +9,7 @@ module Nitro
9
9
  # * dragdrop.js
10
10
  # * controls.js
11
11
 
12
- module JavascriptMixin
12
+ module JavascriptHelper
13
13
 
14
14
  private
15
15
 
@@ -57,6 +57,21 @@ private
57
57
  alias_method :live, :live_request
58
58
  alias_method :async, :live_request
59
59
 
60
+ # Denotes an element as toggleable.
61
+
62
+ def toggleable(id, options = {})
63
+ __append_script_file__ 'js/prototype.js'
64
+
65
+ behaviour "##{id}", %{
66
+ el.onclick = function() {
67
+ Element.toggle('#{id}');
68
+ return false;
69
+ }
70
+ }
71
+
72
+ return nil
73
+ end
74
+
60
75
  # :section: script.aculo.us dragdrop.js
61
76
 
62
77
  # Make the element dragable.
@@ -197,6 +212,7 @@ private
197
212
  return nil
198
213
  end
199
214
 
215
+ # -----------------------------------------------------------
200
216
  # :section: general javascript helpers.
201
217
 
202
218
  # Include external javascript file.
@@ -231,7 +231,7 @@ end
231
231
 
232
232
  # Pager related helper methods.
233
233
 
234
- module PagerMixin
234
+ module PagerHelper
235
235
 
236
236
  private
237
237
 
@@ -3,7 +3,7 @@ require 'rss/0.9'
3
3
 
4
4
  require 'nano/string/first_char'
5
5
 
6
- require 'nitro/mixin/markup'
6
+ require 'glue/markup'
7
7
 
8
8
  module Nitro
9
9
 
@@ -18,8 +18,8 @@ module Nitro
18
18
  # <?xml-stylesheet href="rss.css" type="text/css"?>
19
19
  #++
20
20
 
21
- module RssMixin
22
- include Nitro::Markup
21
+ module RssHelper
22
+ include Glue::Markup
23
23
 
24
24
  # === Options
25
25
  #
@@ -18,7 +18,7 @@ module Nitro
18
18
  # TODO: sorting, thead/tbody/legend etc, verbose...
19
19
  #++
20
20
 
21
- module TableMixin
21
+ module TableHelper
22
22
 
23
23
  # [+options+]
24
24
  # A hash of options.
@@ -3,7 +3,7 @@ module Nitro
3
3
  # A helper mixin for programmatically building XHTML
4
4
  # blocks.
5
5
 
6
- module XhtmlMixin
6
+ module XhtmlHelper
7
7
 
8
8
  private
9
9
 
@@ -90,7 +90,7 @@ private
90
90
  #{options(:labels_values => (1..31).to_a, :selected => date.day)}
91
91
  </select>&nbsp;
92
92
  <select id="#{name}.month" name="#{name}.month">
93
- #{options(:labels => Date::MONTHNAMES, :values => (1..12).to_a, :selected => (date.month))}
93
+ #{options(:labels => Date::MONTHNAMES[1..12], :values => (1..12).to_a, :selected => (date.month))}
94
94
  </select>&nbsp;
95
95
  <select id="#{name}.year" name="#{name}.year">
96
96
  #{options(:labels_values => ((Time.now.year-10)..(Time.now.year+10)).to_a, :selected => date.year)}
@@ -3,7 +3,7 @@ module Nitro
3
3
  # A helper mixin for programmatically building XML
4
4
  # blocks.
5
5
 
6
- module XmlMixin
6
+ module XmlHelper
7
7
 
8
8
  def method_missing(tag, *args, &block)
9
9
  self.class.module_eval <<-"end_eval", __FILE__, __LINE__
data/lib/nitro/render.rb CHANGED
@@ -10,10 +10,10 @@ require 'glue/template'
10
10
  require 'glue/builder'
11
11
  require 'glue/builder/xml'
12
12
 
13
- require 'nitro/mixin/xhtml'
14
- require 'nitro/mixin/form'
15
- require 'nitro/mixin/table'
16
- require 'nitro/mixin/buffer'
13
+ require 'nitro/helper/xhtml'
14
+ require 'nitro/helper/form'
15
+ require 'nitro/helper/table'
16
+ require 'nitro/helper/buffer'
17
17
 
18
18
  module Nitro
19
19
 
@@ -44,7 +44,7 @@ end
44
44
  #++
45
45
 
46
46
  module Render
47
- include BufferMixin
47
+ include BufferHelper
48
48
 
49
49
  # If true, auto redirect to referer on empty buffer.
50
50
 
@@ -173,6 +173,7 @@ private
173
173
 
174
174
  raise RenderExit
175
175
  end
176
+ alias_method :redirect_to, :redirect
176
177
 
177
178
  # Redirect to the referer.
178
179
 
@@ -181,6 +182,13 @@ private
181
182
  end
182
183
  alias_method :redirect_to_referer, :redirect_referer
183
184
 
185
+ # Redirect to home.
186
+
187
+ def redirect_home(status = 303)
188
+ redirect('/', status)
189
+ end
190
+ alias_method :redirect_to_home, :redirect_home
191
+
184
192
  # Log a rendering error.
185
193
 
186
194
  def log_error(error, path)
@@ -240,9 +248,9 @@ private
240
248
 
241
249
  class Emitter
242
250
  include Singleton
243
- include XhtmlMixin
244
- include FormMixin
245
- include TableMixin
251
+ include XhtmlHelper
252
+ include FormHelper
253
+ include TableHelper
246
254
  end
247
255
 
248
256
  # A helper to access the utilities emitter: