nitro 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/AUTHORS +14 -4
  2. data/ChangeLog +192 -1
  3. data/README +50 -6
  4. data/RELEASES +60 -0
  5. data/Rakefile +1 -1
  6. data/bin/cluster.rb +2 -2
  7. data/bin/new_form.rb +1 -1
  8. data/examples/blog/config.rb +5 -4
  9. data/examples/blog/lib/blog.rb +56 -36
  10. data/examples/blog/root/comments.xhtml +5 -2
  11. data/examples/blog/root/entry_form.xhtml +7 -2
  12. data/examples/blog/root/login.xhtml +1 -1
  13. data/examples/blog/root/style.xsl +7 -0
  14. data/examples/og/mock_example.rb +6 -9
  15. data/examples/og/mysql_to_psql.rb +100 -0
  16. data/examples/og/run.rb +8 -17
  17. data/lib/glue.rb +7 -8
  18. data/lib/glue/array.rb +1 -1
  19. data/lib/glue/attribute.rb +86 -0
  20. data/lib/glue/cache.rb +1 -1
  21. data/lib/glue/hash.rb +1 -1
  22. data/lib/glue/inflector.rb +1 -1
  23. data/lib/glue/logger.rb +118 -18
  24. data/lib/glue/mixins.rb +1 -1
  25. data/lib/glue/number.rb +1 -1
  26. data/lib/glue/pool.rb +1 -1
  27. data/lib/glue/property.rb +48 -31
  28. data/lib/glue/string.rb +1 -1
  29. data/lib/glue/time.rb +2 -2
  30. data/lib/glue/validation.rb +400 -0
  31. data/lib/nitro/application.rb +6 -6
  32. data/lib/nitro/builders/form.rb +5 -5
  33. data/lib/nitro/builders/rss.rb +1 -1
  34. data/lib/nitro/builders/xhtml.rb +119 -0
  35. data/lib/nitro/builders/xml.rb +111 -0
  36. data/lib/nitro/config.rb +6 -6
  37. data/lib/nitro/events.rb +1 -1
  38. data/lib/nitro/html.rb +1 -1
  39. data/lib/nitro/markup.rb +15 -20
  40. data/lib/nitro/scaffold.rb +2 -2
  41. data/lib/nitro/server/appserver.rb +3 -3
  42. data/lib/nitro/server/cluster.rb +2 -2
  43. data/lib/nitro/server/dispatcher.rb +2 -2
  44. data/lib/nitro/server/filters/autologin.rb +1 -1
  45. data/lib/nitro/server/fragment.rb +2 -2
  46. data/lib/nitro/server/handlers.rb +2 -2
  47. data/lib/nitro/server/render.rb +17 -15
  48. data/lib/nitro/server/request.rb +6 -6
  49. data/lib/nitro/server/script.rb +2 -2
  50. data/lib/nitro/server/server.rb +2 -2
  51. data/lib/nitro/server/session.rb +6 -6
  52. data/lib/nitro/server/shaders.rb +2 -2
  53. data/lib/nitro/server/webrick.rb +1 -1
  54. data/lib/nitro/sitemap.rb +2 -2
  55. data/lib/nitro/uri.rb +1 -1
  56. data/lib/nitro/version.rb +7 -5
  57. data/lib/og.rb +95 -129
  58. data/lib/og/backend.rb +47 -46
  59. data/lib/og/backends/mysql.rb +64 -63
  60. data/lib/og/backends/psql.rb +73 -72
  61. data/lib/og/connection.rb +7 -8
  62. data/lib/og/enchant.rb +80 -0
  63. data/lib/og/meta.rb +21 -21
  64. data/lib/og/mock.rb +31 -88
  65. data/lib/og/version.rb +6 -5
  66. data/lib/parts/README +9 -0
  67. data/lib/parts/content.rb +23 -9
  68. data/test/glue/tc_attribute.rb +22 -0
  69. data/test/glue/tc_cache.rb +4 -6
  70. data/test/glue/tc_hash.rb +2 -2
  71. data/test/glue/tc_logger.rb +36 -0
  72. data/test/glue/tc_numbers.rb +2 -2
  73. data/test/glue/tc_property_mixins.rb +35 -4
  74. data/test/glue/tc_strings.rb +32 -32
  75. data/test/glue/tc_validation.rb +186 -0
  76. data/test/nitro/builders/tc_xhtml.rb +38 -0
  77. data/test/nitro/builders/tc_xml.rb +47 -0
  78. data/test/nitro/server/tc_request.rb +2 -2
  79. data/test/nitro/server/tc_session.rb +1 -1
  80. data/test/nitro/tc_sitemap.rb +1 -1
  81. data/test/nitro/ui/tc_pager.rb +1 -10
  82. data/test/tc_og.rb +3 -3
  83. data/vendor/blankslate.rb +53 -0
  84. data/vendor/extensions/_base.rb +153 -0
  85. data/vendor/extensions/_template.rb +36 -0
  86. data/vendor/extensions/all.rb +21 -0
  87. data/vendor/extensions/array.rb +68 -0
  88. data/vendor/extensions/binding.rb +224 -0
  89. data/vendor/extensions/class.rb +50 -0
  90. data/vendor/extensions/continuation.rb +71 -0
  91. data/vendor/extensions/enumerable.rb +250 -0
  92. data/vendor/extensions/hash.rb +23 -0
  93. data/vendor/extensions/io.rb +58 -0
  94. data/vendor/extensions/kernel.rb +42 -0
  95. data/vendor/extensions/module.rb +114 -0
  96. data/vendor/extensions/numeric.rb +230 -0
  97. data/vendor/extensions/object.rb +164 -0
  98. data/vendor/extensions/ostruct.rb +41 -0
  99. data/vendor/extensions/string.rb +316 -0
  100. data/vendor/extensions/symbol.rb +28 -0
  101. metadata +35 -13
  102. data/lib/glue/property.rb.old +0 -307
@@ -6,7 +6,7 @@
6
6
 
7
7
  require "sync"
8
8
 
9
- module G
9
+ module N
10
10
 
11
11
  # == SafeArray
12
12
  #
@@ -0,0 +1,86 @@
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
3
+ #
4
+ # Original code from Rails distribution.
5
+ # http://www.rubyonrails.com
6
+ #
7
+ # $Id$
8
+
9
+ #--
10
+ # Extends the module object with module and instance accessors
11
+ # for class attributes, just like the native attr* accessors for
12
+ # instance attributes. Aliases for classes are also provided.
13
+ #
14
+ # Example:
15
+ #
16
+ # mattr_accessor :my_attr, 'Default value'
17
+ #++
18
+ class Module # :nodoc:
19
+
20
+ def mattr_reader(*params)
21
+ default = if params.last.is_a?(Symbol) then nil else params.pop end
22
+
23
+
24
+ for sym in params
25
+ module_eval <<-"end_eval", __FILE__, __LINE__
26
+
27
+ if not defined?(@@#{sym.id2name})
28
+ @@#{sym.id2name} = #{default.inspect}
29
+ end
30
+
31
+ def self.#{sym.id2name}
32
+ @@#{sym}
33
+ end
34
+
35
+ def #{sym.id2name}
36
+ @@#{sym}
37
+ end
38
+
39
+ def call_#{sym.id2name}
40
+ case @@#{sym.id2name}
41
+ when Symbol then send(@@#{sym})
42
+ when Proc then @@#{sym}.call(self)
43
+ when String then @@#{sym}
44
+ else nil
45
+ end
46
+ end
47
+
48
+ end_eval
49
+ end
50
+ end
51
+ alias_method :cattr_reader, :mattr_reader
52
+
53
+ def mattr_writer(*params)
54
+ default = if params.last.is_a?(Symbol) then nil else params.pop end
55
+
56
+ for sym in params
57
+ module_eval <<-"end_eval", __FILE__, __LINE__
58
+
59
+ if not defined?(@@#{sym.id2name})
60
+ @@#{sym.id2name} = #{default.inspect.inspect}
61
+ end
62
+
63
+ def self.#{sym.id2name}=(obj)
64
+ @@#{sym.id2name} = obj
65
+ end
66
+
67
+ def self.set_#{sym.id2name}(obj)
68
+ @@#{sym.id2name} = obj
69
+ end
70
+
71
+ def #{sym.id2name}=(obj)
72
+ @@#{sym} = obj
73
+ end
74
+
75
+ end_eval
76
+ end
77
+ end
78
+ alias_method :cattr_writer, :cattr_writer
79
+
80
+ def mattr_accessor(*syms)
81
+ mattr_reader(*syms)
82
+ mattr_writer(*syms)
83
+ end
84
+ alias_method :cattr_accessor, :mattr_accessor
85
+
86
+ end
@@ -5,7 +5,7 @@
5
5
  # (c) 2004 Navel, all rights reserved.
6
6
  # $Id: cache.rb 167 2004-11-23 14:03:10Z gmosx $
7
7
 
8
- module G;
8
+ module N;
9
9
 
10
10
  # = LRUCache
11
11
  #
@@ -6,7 +6,7 @@
6
6
 
7
7
  require "sync"
8
8
 
9
- module G;
9
+ module N;
10
10
 
11
11
  # == SafeHash
12
12
  #
@@ -2,7 +2,7 @@
2
2
  # Copyright (c) 2004 David Heinemeier Hansson.
3
3
  #
4
4
 
5
- module G
5
+ module N
6
6
 
7
7
  # The Inflector transforms words from singular to plural, class names to table names, modulized class names to ones without,
8
8
  # and class names to foreign keys.
@@ -1,45 +1,144 @@
1
- # = Logger
2
- #
3
- # A simple wrapper arround the Ruby logger. Mainly for compatibility
4
- # purposes.
5
- #
6
1
  # code:
7
2
  # * George Moschovitis <gm@navel.gr>
8
3
  #
9
4
  # (c) 2004 Navel, all rights reserved.
10
5
  # $Id: logger.rb 161 2004-11-18 10:51:51Z gmosx $
11
6
 
12
- require "logger"
7
+ require 'logger'
13
8
 
14
9
  # = Logger
15
10
  #
16
- # A simple wrapper arround the Ruby logger. Mainly for compatibility
17
- # purposes.
11
+ # A simple wrapper arround the Ruby logger. Mainly for
12
+ # compatibility purposes.
18
13
  #
19
14
  class Logger
20
15
  alias_method :devel, :debug
21
16
  alias_method :fine, :debug
22
17
 
23
- def detach
18
+ # Prints a trace message to DEBUGLOG (at debug level).
19
+ # Useful for emitting the value of variables, etc. Use
20
+ # like this:
21
+ #
22
+ # x = y = 5
23
+ # trace 'x' # -> 'x = 5'
24
+ # trace 'x ** y' # -> 'x ** y = 3125'
25
+ #
26
+ # If you have a more complicated value, like an array of
27
+ # hashes, then you'll probably want to use an alternative
28
+ # output format. For instance:
29
+ #
30
+ # trace 'value', :yaml
31
+ #
32
+ # Valid output format values (the _style_ parameter) are:
33
+ #
34
+ # :p :inspect
35
+ # :pp (pretty-print, using 'pp' library)
36
+ # :s :to_s
37
+ # :y :yaml :to_yaml (using the 'yaml' library')
38
+ #
39
+ # The default is <tt>:p</tt>.
40
+ #
41
+ # CREDITS:
42
+ #
43
+ # This code comes straight from the dev-utils Gem.
44
+ # Author: Gavin Sinclair <gsinclair@soyabean.com.au>
45
+ #
46
+ def trace(expr, style=:p)
47
+ unless expr.respond_to? :to_str
48
+ warn "trace: Can't evaluate the given value: #{caller.first}"
49
+ else
50
+ require 'extensions/binding'
51
+
52
+ Binding.of_caller do |b|
53
+ value = b.eval(expr.to_str)
54
+ formatter = TRACE_STYLES[style] || :inspect
55
+ case formatter
56
+ when :pp then require 'pp'
57
+ when :y, :yaml, :to_yaml then require 'yaml'
58
+ end
59
+ value_s = value.send(formatter)
60
+ message = "#{expr} = #{value_s}"
61
+ lines = message.split(/\n/)
62
+ indent = " "
63
+ debug(lines.shift)
64
+ lines.each do |line|
65
+ debug(indent + line)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ TRACE_STYLES = {} # :nodoc:
71
+ TRACE_STYLES.update( :pp => :pp_s, :s => :to_s, :p => :inspect, :y => :to_yaml,
72
+ :yaml => :to_yaml, :inspect => :inspect, :to_yaml => :to_yaml )
73
+
74
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75
+ # Global logger interface.
76
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77
+
78
+ # Override the logger with your custom version.
79
+ #
80
+ @@global_logger = Logger.new(STDERR)
81
+
82
+ def self.set(logger)
83
+ @@global_logger = logger
84
+ end
85
+
86
+ def self.get
87
+ @@global_logger
24
88
  end
25
89
 
26
- # Used for debuging, remove this in release code.
27
- #
28
- def d(str)
29
- self << "#{str}\n"
90
+ def self.warn(str)
91
+ @@global_logger.warn(str)
30
92
  end
31
93
 
32
- # Inspect an object. Used for debugging, remove this in release
33
- # code.
34
- #
35
- def i(obj)
36
- self << "Inspect #{obj.inspect()}\n"
94
+ def self.info(str)
95
+ @@global_logger.info(str)
96
+ end
97
+
98
+ def self.debug(str)
99
+ @@global_logger.debug(str)
100
+ end
101
+
102
+ def self.error(str)
103
+ @@global_logger.error(str)
37
104
  end
38
105
 
106
+ #--
107
+ # Saddly have to duplicate the code to make
108
+ # Binding.of_caller work.
109
+ #++
110
+ def self.trace(expr, style=:p)
111
+ unless expr.respond_to? :to_str
112
+ warn "trace: Can't evaluate the given value: #{caller.first}"
113
+ else
114
+ require 'extensions/binding'
115
+
116
+ Binding.of_caller do |b|
117
+ value = b.eval(expr.to_str)
118
+ formatter = TRACE_STYLES[style] || :inspect
119
+ case formatter
120
+ when :pp then require 'pp'
121
+ when :y, :yaml, :to_yaml then require 'yaml'
122
+ end
123
+ value_s = value.send(formatter)
124
+ message = "#{expr} = #{value_s}"
125
+ lines = message.split(/\n/)
126
+ indent = " "
127
+ debug(lines.shift)
128
+ lines.each do |line|
129
+ debug(indent + line)
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136
+
39
137
  private
40
138
 
41
139
  # the default Ruby logger has a hardwired silly format.
42
140
  # we use some Ruby magic to fix it!
141
+
43
142
  remove_const "Format"
44
143
 
45
144
  Format = "%5s: %s\n"
@@ -47,5 +146,6 @@ class Logger
47
146
  def format_message(severity, timestamp, msg, progname)
48
147
  Format % [severity, msg]
49
148
  end
149
+
50
150
  end
51
151
 
@@ -9,7 +9,7 @@
9
9
  # (c) 2004 Navel, all rights reserved.
10
10
  # $Id$
11
11
 
12
- module G;
12
+ module N
13
13
 
14
14
  # = Expirable
15
15
  #
@@ -4,7 +4,7 @@
4
4
  # (c) 2004 Navel, all rights reserved.
5
5
  # $Id: number.rb 167 2004-11-23 14:03:10Z gmosx $
6
6
 
7
- module G;
7
+ module N;
8
8
 
9
9
  # = NumberUtils
10
10
  #
@@ -7,7 +7,7 @@
7
7
  require "thread"
8
8
  require "monitor"
9
9
 
10
- module G
10
+ module N
11
11
 
12
12
  # = Pool
13
13
  #
@@ -1,15 +1,13 @@
1
1
  # code:
2
2
  # * George Moschovitis <gm@navel.gr>
3
- # design:
4
- # * Anastastios Koutoumanos <ak@navel.gr>
5
3
  #
6
4
  # (c) 2004 Navel, all rights reserved.
7
5
  # $Id: property.rb 200 2004-12-27 11:24:41Z gmosx $
8
6
 
9
- require "glue/array"
10
- require "glue/hash"
7
+ require 'glue/array'
8
+ require 'glue/hash'
11
9
 
12
- module G
10
+ module N
13
11
 
14
12
  # = Property
15
13
  #
@@ -61,14 +59,17 @@ module PropertyUtils
61
59
  # Add accessors to the properties to the given target
62
60
  # (Module or Class). For simplicity also create the
63
61
  # meta accessors.
62
+ #
63
+ # [+target+]
64
+ # The target class or module
64
65
  #--
65
66
  # gmosx: Perhaps we 'll optimize this in the future.
66
67
  #++
67
- def self.enchant(target)
68
+ def self.enchant(target, force = false)
68
69
  unless target.singleton_methods.include?('__props')
69
70
  target.module_eval <<-"end_eval", __FILE__, __LINE__
70
- @@__meta = G::SafeHash.new
71
- @@__props = G::SafeArray.new
71
+ @@__meta = N::SafeHash.new
72
+ @@__props = N::SafeArray.new
72
73
 
73
74
  def self.__props
74
75
  @@__props
@@ -98,7 +99,8 @@ module PropertyUtils
98
99
 
99
100
  # copy the metadata.
100
101
  src.__meta.each do |k, val|
101
- val.each { |v| dest.meta(k, v) } if val
102
+ dest.__meta[k] = val.dup
103
+ # val.each { |v| dest.meta(k, v) } if val
102
104
  end
103
105
  end
104
106
 
@@ -132,19 +134,19 @@ module PropertyUtils
132
134
 
133
135
  def __force_#{s}(val)
134
136
  self.#{s}=(} + case klass.name
135
- when Fixnum.name
136
- "val.to_i()"
137
- when String.name
138
- "val.to_s()"
139
- when Float.name
140
- "val.to_f()"
141
- when Time.name
142
- "Time.parse(val.to_s())"
143
- when TrueClass.name, FalseClass.name
144
- "val.to_i() > 0"
145
- else
146
- "val"
147
- end + %{)
137
+ when Fixnum.name
138
+ "val.to_i()"
139
+ when String.name
140
+ "val.to_s()"
141
+ when Float.name
142
+ "val.to_f()"
143
+ when Time.name
144
+ "Time.parse(val.to_s())"
145
+ when TrueClass.name, FalseClass.name
146
+ "val.to_i() > 0"
147
+ else
148
+ "val"
149
+ end + %{)
148
150
  end
149
151
  }
150
152
  end
@@ -161,7 +163,13 @@ module PropertyUtils
161
163
  end
162
164
  }
163
165
  end
164
-
166
+
167
+ # Get the property metadata for the given symbol.
168
+ #
169
+ def self.get_prop(klass, sym)
170
+ return klass.__props.find { |p| p.symbol == sym }
171
+ end
172
+
165
173
  end
166
174
 
167
175
  end # module
@@ -182,6 +190,7 @@ class Module
182
190
  # --> creates reader and writer.
183
191
  #
184
192
  def prop(*params)
193
+
185
194
  meta = {}
186
195
  klass = Object
187
196
 
@@ -200,7 +209,7 @@ class Module
200
209
  end
201
210
  end
202
211
 
203
- G::PropertyUtils.enchant(self)
212
+ N::PropertyUtils.enchant(self)
204
213
 
205
214
  if self.is_a?(Class)
206
215
 
@@ -209,8 +218,8 @@ class Module
209
218
  self.module_eval <<-"end_eval", __FILE__, __LINE__
210
219
 
211
220
  def self.inherited(sub)
212
- G::PropertyUtils.enchant(sub)
213
- G::PropertyUtils.copy_props(self, sub)
221
+ N::PropertyUtils.enchant(sub)
222
+ N::PropertyUtils.copy_props(self, sub)
214
223
  # gmosx: We have to define @@__props first to avoid reusing
215
224
  # the hash from the module. super must stay at the end.
216
225
  super
@@ -225,10 +234,15 @@ class Module
225
234
  self.module_eval <<-"end_eval", __FILE__, __LINE__
226
235
 
227
236
  def self.append_features(base)
228
- G::PropertyUtils.enchant(base)
229
- G::PropertyUtils.copy_props(self, base)
237
+ N::PropertyUtils.enchant(base)
238
+ N::PropertyUtils.copy_props(self, base)
230
239
  # gmosx: We have to define @@__props first to avoid reusing
231
240
  # the hash from the module. super must stay at the end.
241
+
242
+ unless base.included_modules.include?(N::Validation)
243
+ base.module_eval %{ include N::Validation }
244
+ end if defined?(N::Validation)
245
+
232
246
  super
233
247
  end
234
248
 
@@ -236,7 +250,7 @@ class Module
236
250
 
237
251
  end
238
252
 
239
- property = G::Property.new(symbol, klass, meta)
253
+ property = N::Property.new(symbol, klass, meta)
240
254
 
241
255
  reader = meta[:reader] || true
242
256
  writer = writer || meta[:writer] || false
@@ -248,7 +262,10 @@ class Module
248
262
  meta[:writer] = true if meta[:writer].nil?
249
263
  end
250
264
 
251
- G::PropertyUtils.add_prop(self, property)
265
+ N::PropertyUtils.add_prop(self, property)
266
+
267
+ # gmosx: should be placed AFTER enchant!
268
+ module_eval %{ include N::Validation } if defined?(N::Validation)
252
269
  end
253
270
 
254
271
  # Helper method. Accepts a collection of symbols and generates
@@ -303,7 +320,7 @@ class Module
303
320
  # the meta hash.
304
321
  meta = param
305
322
  else
306
- raise "Error when defining property!"
323
+ raise 'Error when defining property!'
307
324
  end
308
325
  end
309
326