nitro 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/ChangeLog +175 -0
  2. data/README +41 -7
  3. data/RELEASES +24 -0
  4. data/Rakefile +5 -7
  5. data/bin/new_app.rb +26 -4
  6. data/bin/new_form.rb +54 -0
  7. data/bin/proto/config.rb +3 -3
  8. data/bin/proto/root/index.xhtml +2 -34
  9. data/bin/proto/root/style.css +4 -70
  10. data/bin/proto/root/style.xsl +8 -39
  11. data/doc/tutorial.txt +5 -0
  12. data/examples/blog/app.rb +2 -1
  13. data/examples/blog/config.rb +7 -2
  14. data/examples/blog/root/style.xsl +1 -2
  15. data/examples/flash/README +34 -0
  16. data/examples/flash/app.rb +20 -0
  17. data/examples/flash/config.rb +38 -0
  18. data/examples/flash/lib/flash.rb +40 -0
  19. data/examples/flash/root/index.xhtml +25 -0
  20. data/examples/flash/root/show_inline_text.xhtml +12 -0
  21. data/examples/flash/tmp.swf +0 -0
  22. data/examples/og/README +7 -0
  23. data/examples/og/mock_example.rb +58 -0
  24. data/examples/og/run.rb +9 -5
  25. data/examples/tiny/root/include.xhtml +3 -0
  26. data/examples/tiny/root/index.xhtml +2 -1
  27. data/lib/glue/property.rb +166 -107
  28. data/lib/glue/property.rb.old +307 -0
  29. data/lib/nitro/builders/form.rb +26 -17
  30. data/lib/nitro/events.rb +1 -1
  31. data/lib/nitro/markup.rb +120 -0
  32. data/lib/nitro/server/cookie.rb +1 -1
  33. data/lib/nitro/server/dispatcher.rb +5 -6
  34. data/lib/nitro/server/filters.rb +1 -1
  35. data/lib/nitro/server/render.rb +33 -29
  36. data/lib/nitro/server/shaders.rb +32 -3
  37. data/lib/nitro/server/user.rb +1 -1
  38. data/lib/nitro/server/webrick.rb +9 -4
  39. data/lib/nitro/ui/popup.rb +1 -1
  40. data/lib/nitro/ui/select.rb +1 -1
  41. data/lib/nitro/ui/tabs.rb +1 -1
  42. data/lib/nitro/version.rb +2 -2
  43. data/lib/og.rb +17 -6
  44. data/lib/og/backend.rb +34 -4
  45. data/lib/og/backends/mysql.rb +3 -17
  46. data/lib/og/backends/psql.rb +5 -17
  47. data/lib/og/meta.rb +41 -26
  48. data/lib/og/mock.rb +223 -0
  49. data/lib/og/version.rb +2 -2
  50. data/lib/parts/content.rb +61 -0
  51. data/test/glue/{tc_properties.rb → tc_property.rb} +0 -1
  52. data/test/glue/tc_property_mixins.rb +62 -0
  53. data/test/og/tc_lifecycle.rb +107 -0
  54. data/test/tc_og.rb +31 -4
  55. data/vendor/README +6 -0
  56. data/vendor/binding_of_caller.rb +81 -0
  57. data/vendor/breakpoint.rb +526 -0
  58. data/vendor/breakpoint_client.rb +157 -0
  59. metadata +135 -95
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: cookie.rb 152 2004-11-13 20:02:35Z gmosx $
5
+ # $Id: cookie.rb 112 2004-10-27 10:59:55Z gmosx $
6
6
 
7
7
  require "cgi"
8
8
 
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: dispatcher.rb 167 2004-11-23 14:03:10Z gmosx $
5
+ # $Id: dispatcher.rb 200 2004-12-27 11:24:41Z gmosx $
6
6
 
7
7
  require 'nitro/server/render'
8
8
 
@@ -15,6 +15,7 @@ module Dispatcher
15
15
 
16
16
  def process(request, response)
17
17
  begin
18
+ # gmosx, INVESTIGATE: this is not really needed.
18
19
  $og.get_connection if $og
19
20
 
20
21
  session = create_session(request, response)
@@ -38,14 +39,12 @@ module Dispatcher
38
39
  <p>Click <a href="#{request.referer}">here</a> to return
39
40
  to the previous page.</p>
40
41
  }
41
- =begin
42
- if request.error_log
42
+ if @rendering_errors
43
43
  body << %{
44
- <h3>Request error log</h3>
45
- <pre>#{request.error_log.join("\n")}</pre>
44
+ <h3>Rendering errors</h3>
45
+ <pre>#{@rendering_errors.join("\n")}</pre>
46
46
  }
47
47
  end
48
- =end
49
48
  body << %{
50
49
  <h3>Exception</h3>
51
50
  <pre>#{pp_exception(e)}</pre>
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 20024 Navel, all rights reserved.
5
- # $Id: filters.rb 152 2004-11-13 20:02:35Z gmosx $
5
+ # $Id: filters.rb 133 2004-11-10 19:08:29Z gmosx $
6
6
 
7
7
  require "socket"
8
8
  require "thread"
@@ -2,7 +2,9 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: render.rb 185 2004-12-10 13:29:09Z gmosx $
5
+ # $Id: render.rb 200 2004-12-27 11:24:41Z gmosx $
6
+
7
+ require 'cgi'
6
8
 
7
9
  module N
8
10
 
@@ -53,7 +55,7 @@ module RenderUtils
53
55
  meth = parts[2]
54
56
  end
55
57
 
56
- # p '--', api, base, render_class, meth, '--'
58
+ # p '--', api, base, render_class, meth, '--'
57
59
 
58
60
  return api, base, render_class, meth
59
61
  end
@@ -125,7 +127,7 @@ module RenderUtils
125
127
  if klass.instance_methods.include?("#{meth}__xhtml")
126
128
  valid = true
127
129
  code << %{
128
- #{meth}__xhtml();
130
+ return unless #{meth}__xhtml();
129
131
  }
130
132
  end
131
133
 
@@ -133,7 +135,7 @@ module RenderUtils
133
135
  if template = template_for_method(base, meth)
134
136
  valid = true
135
137
  code << %{
136
- __#{meth}_xhtml();
138
+ return unless __#{meth}_xhtml();
137
139
  }
138
140
  end
139
141
 
@@ -158,9 +160,11 @@ module RenderUtils
158
160
  end
159
161
  }
160
162
  end
161
-
162
- # puts '++', code, '++'
163
-
163
+ =begin
164
+ puts '--'
165
+ puts dump(code)
166
+ puts '--'
167
+ =end
164
168
  klass.class_eval(code)
165
169
 
166
170
  return "__#{meth}"
@@ -198,7 +202,7 @@ module RenderUtils
198
202
  if klass.instance_methods.include?("#{meth}__xml")
199
203
  valid = true
200
204
  code << %{
201
- #{meth}__xml();
205
+ return unless #{meth}__xml();
202
206
  }
203
207
  end
204
208
 
@@ -206,7 +210,7 @@ module RenderUtils
206
210
  if template = template_for_method(base, meth, 'xml')
207
211
  valid = true
208
212
  code << %{
209
- __#{meth}_xml();
213
+ return unless __#{meth}_xml();
210
214
  }
211
215
  end
212
216
 
@@ -236,20 +240,20 @@ module RenderUtils
236
240
  return "__rest_#{meth}"
237
241
  end
238
242
 
239
- #
240
- #
241
- def load_statically_included(filename)
242
- $log.debug "Statically including '#{filename}'" if $DBG
243
-
244
- text = File.read(filename)
245
- text.gsub!(/<\?xml.*\?>/, '')
246
- text.gsub!(/<\/?root(.*?)>/m, ' ');
247
-
248
- return text
243
+ def self.dump(str)
244
+ str.split("\n").each_with_index do |line, idx|
245
+ puts "#{idx+1}: #{line}"
246
+ end
249
247
  end
250
-
251
248
  end
252
249
 
250
+ # = RenderExit
251
+ #
252
+ # Raise this exception to stop rendering.
253
+ #
254
+ class RenderExit < Exception
255
+ end
256
+
253
257
  # = Render
254
258
  #
255
259
  module Render
@@ -324,6 +328,9 @@ module Render
324
328
  r.send(meth)
325
329
  @out = r.out
326
330
  end
331
+ rescue N::RenderExit => e
332
+ # Just stop rendering.
333
+ # For example called by redirects.
327
334
  rescue Exception, StandardError => e
328
335
  log_error "error while handling '#{path}'."
329
336
  log_error pp_exception(e)
@@ -345,15 +352,12 @@ module Render
345
352
  # Send a redirect response.
346
353
  #
347
354
  def redirect(url, status = 303)
348
- begin
349
- @response.status = status
350
- @response.set_redirect(status, url)
351
- rescue Exception, StandardError => ex
352
- # drink it!
353
- end
354
-
355
- # stop the filter pipeline
356
- return false
355
+ @response.status = status
356
+ @response.body = "<html><a href=\"#{url.to_s}\">#{url.to_s}</a>.</html>\n"
357
+ @response.header['location'] = url.to_s
358
+
359
+ # stop the rendering
360
+ raise N::RenderExit
357
361
  end
358
362
 
359
363
  # Redirect to the referer of this method.
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: shaders.rb 188 2004-12-10 14:14:17Z gmosx $
5
+ # $Id: shaders.rb 189 2004-12-13 21:38:05Z gmosx $
6
6
 
7
7
  module N
8
8
 
@@ -62,12 +62,28 @@ class RubyShader < N::Shader
62
62
  # Convert the xhtml script to actual Ruby code, ready to be
63
63
  # evaluated.
64
64
  #
65
+ #--
66
+ # Investigate:
67
+ # perhaps xl:href should be used to be XLink compatible?
68
+ #++
69
+ #
65
70
  def process(hash, text)
66
71
  # strip the xml header! (interracts with the following gsub!)
67
72
  text.gsub!(/<\?xml.*\?>/, "")
68
73
 
69
- # statically include files.
70
- # TODO: Add here!
74
+ # statically include sub script files.
75
+ # The target file is included at compile time.
76
+ #
77
+ # gmosx: must be xformed before the <?r pi.
78
+ #
79
+ # Example:
80
+ # <?include xl:href="root/myfile.sx" ?>
81
+ #
82
+ text.gsub!(/<\?include href="(.*?)"(.*)\?>/) { |match|
83
+ # gmosx: xmm match matches the whole string.
84
+ # match = overload_path($1)
85
+ load_statically_included("#$root_dir/#$1")
86
+ }
71
87
 
72
88
  # xform include instructions <include href="xxx" />
73
89
  # must be transformed before the processinc instructions.
@@ -103,6 +119,19 @@ class RubyShader < N::Shader
103
119
  process_next(hash, text)
104
120
  end
105
121
 
122
+ # Loads and statically includes a file.
123
+ #
124
+ def load_statically_included(filename)
125
+ $log.debug "Statically including '#{filename}'" if $DBG
126
+
127
+ text = File.read(filename)
128
+ text.gsub!(/<\?xml.*\?>/, '')
129
+ text.gsub!(/<\/?root(.*?)>/m, ' ');
130
+
131
+ return text
132
+ end
133
+
134
+
106
135
  end
107
136
 
108
137
  # = XSLTShader
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: user.rb 152 2004-11-13 20:02:35Z gmosx $
5
+ # $Id: user.rb 99 2004-10-22 09:50:28Z gmosx $
6
6
 
7
7
  require "singleton"
8
8
 
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: webrick.rb 167 2004-11-23 14:03:10Z gmosx $
5
+ # $Id: webrick.rb 200 2004-12-27 11:24:41Z gmosx $
6
6
 
7
7
  require "webrick"
8
8
 
@@ -45,7 +45,7 @@ module WEBrick
45
45
  def fill(obj, name = nil)
46
46
  # if an object is passed create an instance.
47
47
  obj = obj.new if obj.is_a?(Class)
48
-
48
+
49
49
  @query.each do |param, val|
50
50
  begin
51
51
  # gmosx: DO NOT escape by default !!!
@@ -90,9 +90,14 @@ class WebrickServer < N::AppServer
90
90
  #
91
91
  def start
92
92
  Socket.do_not_reverse_lookup = true # patch for OS X
93
+
94
+ =begin
95
+ accesslog = WEBrick::BasicLog::new('/dev/null')
96
+ referer = WEBrick::BasicLog::new('/dev/null')
97
+ =end
93
98
 
94
- accesslog = WEBrick::BasicLog::new("/dev/null")
95
- referer = WEBrick::BasicLog::new("/dev/null")
99
+ accesslog = WEBrick::BasicLog::new('log/access.log')
100
+ referer = WEBrick::BasicLog::new('log/referer.log')
96
101
 
97
102
  @webrick = WEBrick::HTTPServer.new(
98
103
  :BindAddress => $appsrv_address,
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: popup.rb 152 2004-11-13 20:02:35Z gmosx $
5
+ # $Id: popup.rb 99 2004-10-22 09:50:28Z gmosx $
6
6
 
7
7
  module N; module UI
8
8
 
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: select.rb 152 2004-11-13 20:02:35Z gmosx $
5
+ # $Id: select.rb 99 2004-10-22 09:50:28Z gmosx $
6
6
 
7
7
  module N; module UI
8
8
 
data/lib/nitro/ui/tabs.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: tabs.rb 152 2004-11-13 20:02:35Z gmosx $
5
+ # $Id: tabs.rb 101 2004-10-22 12:35:39Z gmosx $
6
6
 
7
7
  module N; module UI
8
8
 
data/lib/nitro/version.rb CHANGED
@@ -2,10 +2,10 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: version.rb 185 2004-12-10 13:29:09Z gmosx $
5
+ # $Id: version.rb 194 2004-12-20 20:23:57Z gmosx $
6
6
 
7
7
  # The name of the server.
8
8
  $srv_name = 'Nitro'
9
9
 
10
10
  # The version of the server.
11
- $srv_version = '0.6.0'
11
+ $srv_version = '0.7.0'
data/lib/og.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: og.rb 185 2004-12-10 13:29:09Z gmosx $
5
+ # $Id: og.rb 197 2004-12-21 13:50:17Z gmosx $
6
6
 
7
7
  require "glue/property"
8
8
  require "glue/array"
@@ -28,6 +28,11 @@ $og_auto_manage_classes = true
28
28
  # If true, automatically include the Og meta-language into Module.
29
29
  $og_include_meta_language = true
30
30
 
31
+ # Attach the following prefix to all generated SQL table names.
32
+ # Usefull on hosting scenarios where you have to run multiple
33
+ # web applications/sites on a single database.
34
+ $og_table_prefix = nil
35
+
31
36
  require "og/meta"
32
37
 
33
38
  # = Og
@@ -169,7 +174,10 @@ class Database
169
174
  @config[:connection_count].times do
170
175
  @connection_pool << Og::Connection.new(self)
171
176
  end
172
-
177
+
178
+ # gmosx, FIXME: this automanage code is not elegant and slow
179
+ # should probably recode this, along with glue/property.rb
180
+ #
173
181
  if $og_auto_manage_classes
174
182
  # automatically manage classes with properties and metadata.
175
183
  # gmosx: Any idea how to optimize this?
@@ -286,8 +294,6 @@ class Database
286
294
  Og::Utils.eval_og_oid(klass) unless klass.instance_methods.include?(:oid)
287
295
 
288
296
  klass.class_eval %{
289
- inherit_meta(superclass) if superclass
290
-
291
297
  DBTABLE = "#{Og::Utils.table(klass)}"
292
298
  DBSEQ = "#{Og::Utils.table(klass)}_oids_seq"
293
299
 
@@ -311,7 +317,12 @@ class Database
311
317
  # class and its instances.
312
318
  #
313
319
  def enchant(klass)
314
- klass.class_eval %{
320
+ klass.module_eval <<-"end_eval", __FILE__, __LINE__
321
+ def self.create(*params)
322
+ obj = #{klass}.new(*params)
323
+ obj.save!
324
+ end
325
+
315
326
  def self.save(obj)
316
327
  $og << obj
317
328
  end
@@ -362,7 +373,7 @@ class Database
362
373
  def delete!
363
374
  $og.delete(@oid, #{klass})
364
375
  end
365
- }
376
+ end_eval
366
377
  end
367
378
 
368
379
  # Automatically wrap connection methods.
data/lib/og/backend.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: backend.rb 185 2004-12-10 13:29:09Z gmosx $
5
+ # $Id: backend.rb 197 2004-12-21 13:50:17Z gmosx $
6
6
 
7
7
  require "yaml"
8
8
 
@@ -28,13 +28,13 @@ module Utils
28
28
  # The name of the SQL table where objects of this class are stored.
29
29
  #
30
30
  def self.table(klass)
31
- "_#{encode(klass)}"
31
+ "_#{$og_table_prefix}#{encode(klass)}"
32
32
  end
33
33
 
34
34
  # The name of the join table for the two given classes.
35
35
  #
36
36
  def self.join_table(klass1, klass2)
37
- "_j_#{Og::Utils.encode(klass1)}_#{Og::Utils.encode(klass2)}"
37
+ "_#{$og_table_prefix}j_#{Og::Utils.encode(klass1)}_#{Og::Utils.encode(klass2)}"
38
38
  end
39
39
 
40
40
  # Returns the props that will be included in the insert query.
@@ -232,7 +232,37 @@ class Backend
232
232
  def rollback
233
233
  exec "ROLLBACK"
234
234
  end
235
-
235
+
236
+ # Create the fields that correpsond to the klass properties.
237
+ # The generated fields array is used in create_table.
238
+ # If the property has an :sql metadata this overrides the default mapping.
239
+ # If the property has an :extra_sql metadata the extra sql is appended
240
+ # after the default mapping.
241
+ #
242
+ def create_fields(klass, typemap)
243
+ fields = []
244
+
245
+ klass.__props.each do |p|
246
+ klass.sql_index(p.symbol) if p.meta[:sql_index]
247
+
248
+ field = "#{p.symbol}"
249
+
250
+ if p.meta and p.meta[:sql]
251
+ field << " #{p.meta[:sql]}"
252
+ else
253
+ field << " #{typemap[p.klass]}"
254
+ # attach extra sql
255
+ if p.meta and extra_sql = p.meta[:extra_sql]
256
+ field << " #{extra_sql}"
257
+ end
258
+ end
259
+
260
+ fields << field
261
+ end
262
+
263
+ return fields
264
+ end
265
+
236
266
  # Create the managed object table. The properties of the
237
267
  # object are mapped to the table columns. Additional sql relations
238
268
  # and constrains are created (indicices, sequences, etc).