wee 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/ChangeLog +132 -0
  2. data/INSTALL +13 -3
  3. data/README +3 -3
  4. data/Rakefile +5 -1
  5. data/bin/wee +100 -0
  6. data/doc/rdoc/classes/Array.html +12 -12
  7. data/doc/rdoc/classes/Cache/StorageCache.html +38 -38
  8. data/doc/rdoc/classes/Cache/Strategy/CapacityBounded.html +30 -30
  9. data/doc/rdoc/classes/Cache/Strategy/LFU.html +24 -24
  10. data/doc/rdoc/classes/Cache/Strategy/LRU.html +24 -24
  11. data/doc/rdoc/classes/Cache/Strategy/Unbounded.html +24 -24
  12. data/doc/rdoc/classes/Enumerable.html +6 -6
  13. data/doc/rdoc/classes/Main.html +265 -0
  14. data/doc/rdoc/classes/Object.html +12 -12
  15. data/doc/rdoc/classes/OgApplication.html +2 -2
  16. data/doc/rdoc/classes/OgScaffolder.html +444 -64
  17. data/doc/rdoc/classes/OgScaffolder/Editor.html +490 -0
  18. data/doc/rdoc/classes/OgSession.html +4 -4
  19. data/doc/rdoc/classes/Recipe.html +113 -0
  20. data/doc/rdoc/classes/String.html +12 -12
  21. data/doc/rdoc/classes/Struct.html +12 -12
  22. data/doc/rdoc/classes/Wee.html +10 -1
  23. data/doc/rdoc/classes/Wee/AnswerDecoration.html +9 -9
  24. data/doc/rdoc/classes/Wee/Application.html +48 -47
  25. data/doc/rdoc/classes/Wee/Brush.html +19 -23
  26. data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +17 -14
  27. data/doc/rdoc/classes/Wee/Brush/FileUploadTag.html +20 -14
  28. data/doc/rdoc/classes/Wee/Brush/FormTag.html +25 -21
  29. data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +12 -12
  30. data/doc/rdoc/classes/Wee/Brush/GenericSingleTagBrush.html +7 -7
  31. data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +234 -100
  32. data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +12 -12
  33. data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +28 -22
  34. data/doc/rdoc/classes/Wee/Brush/ImageTag.html +23 -24
  35. data/doc/rdoc/classes/Wee/Brush/InputTag.html +14 -14
  36. data/doc/rdoc/classes/Wee/Brush/JavascriptTag.html +7 -7
  37. data/doc/rdoc/classes/Wee/Brush/Page.html +14 -14
  38. data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +33 -57
  39. data/doc/rdoc/classes/Wee/Brush/SelectListTag/SelectListCallback.html +154 -0
  40. data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +7 -7
  41. data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +20 -14
  42. data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +14 -14
  43. data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +7 -7
  44. data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +42 -42
  45. data/doc/rdoc/classes/Wee/Brush/TableTag.html +7 -7
  46. data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +27 -21
  47. data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +20 -14
  48. data/doc/rdoc/classes/Wee/CallbackRegistry.html +64 -36
  49. data/doc/rdoc/classes/Wee/CallbackStream.html +21 -21
  50. data/doc/rdoc/classes/Wee/Canvas.html +24 -24
  51. data/doc/rdoc/classes/Wee/Component.html +179 -151
  52. data/doc/rdoc/classes/Wee/Component/OnAnswer.html +12 -12
  53. data/doc/rdoc/classes/Wee/Decoration.html +42 -42
  54. data/doc/rdoc/classes/Wee/Delegate.html +27 -27
  55. data/doc/rdoc/classes/Wee/ErrorResponse.html +14 -14
  56. data/doc/rdoc/classes/Wee/FormDecoration.html +6 -6
  57. data/doc/rdoc/classes/Wee/GenericResponse.html +7 -7
  58. data/doc/rdoc/classes/Wee/HtmlCanvas.html +326 -219
  59. data/doc/rdoc/classes/Wee/HtmlWriter.html +40 -40
  60. data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +19 -19
  61. data/doc/rdoc/classes/Wee/Md5IdGenerator.html +181 -0
  62. data/doc/rdoc/classes/Wee/MessageBox.html +12 -12
  63. data/doc/rdoc/classes/Wee/PageDecoration.html +18 -18
  64. data/doc/rdoc/classes/Wee/PagelessApplication.html +152 -0
  65. data/doc/rdoc/classes/Wee/PagelessRequest.html +177 -0
  66. data/doc/rdoc/classes/Wee/PagelessSession.html +320 -0
  67. data/doc/rdoc/classes/Wee/Presenter.html +145 -89
  68. data/doc/rdoc/classes/Wee/RedirectResponse.html +7 -7
  69. data/doc/rdoc/classes/Wee/RefreshResponse.html +7 -7
  70. data/doc/rdoc/classes/Wee/Request.html +116 -50
  71. data/doc/rdoc/classes/Wee/RequestHandler.html +31 -31
  72. data/doc/rdoc/classes/Wee/Response.html +76 -28
  73. data/doc/rdoc/classes/Wee/Session.html +129 -506
  74. data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +22 -40
  75. data/doc/rdoc/classes/Wee/Snapshot.html +19 -19
  76. data/doc/rdoc/classes/Wee/Utils.html +70 -17
  77. data/doc/rdoc/classes/Wee/Utils/LRUCache.html +6 -6
  78. data/doc/rdoc/classes/Wee/ValueHolder.html +18 -18
  79. data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +82 -49
  80. data/doc/rdoc/classes/Wee/WrapperDecoration.html +6 -6
  81. data/doc/rdoc/created.rid +1 -1
  82. data/doc/rdoc/files/INSTALL.html +17 -5
  83. data/doc/rdoc/files/README.html +9 -11
  84. data/doc/rdoc/files/lib/wee/adaptors/webrick_rb.html +1 -1
  85. data/doc/rdoc/files/lib/wee/application_rb.html +1 -1
  86. data/doc/rdoc/files/lib/wee/components/page_decoration_rb.html +1 -1
  87. data/doc/rdoc/files/lib/wee/continuation/session_rb.html +1 -3
  88. data/doc/rdoc/files/lib/wee/core/callback_rb.html +1 -1
  89. data/doc/rdoc/files/lib/wee/core/component_rb.html +1 -1
  90. data/doc/rdoc/files/lib/wee/core_rb.html +3 -3
  91. data/doc/rdoc/files/lib/wee/databases/og/application_rb.html +101 -0
  92. data/doc/rdoc/files/lib/wee/databases/og/old_scaffolder_rb.html +101 -0
  93. data/doc/rdoc/files/lib/wee/databases/og/scaffolder_rb.html +108 -0
  94. data/doc/rdoc/files/lib/wee/databases/og/session_rb.html +101 -0
  95. data/doc/rdoc/files/lib/wee/databases/og_rb.html +4 -1
  96. data/doc/rdoc/files/lib/wee/idgen/md5_rb.html +115 -0
  97. data/doc/rdoc/files/lib/wee/idgen/simple_rb.html +107 -0
  98. data/doc/rdoc/files/lib/wee/pageless/application_rb.html +101 -0
  99. data/doc/rdoc/files/lib/wee/pageless/request_rb.html +101 -0
  100. data/doc/rdoc/files/lib/wee/pageless/session_rb.html +108 -0
  101. data/doc/rdoc/files/lib/wee/pageless_rb.html +110 -0
  102. data/doc/rdoc/files/lib/wee/renderer/html/brushes_rb.html +1 -1
  103. data/doc/rdoc/files/lib/wee/renderer/html/canvas_rb.html +8 -1
  104. data/doc/rdoc/files/lib/wee/request_rb.html +1 -1
  105. data/doc/rdoc/files/lib/wee/response_rb.html +1 -1
  106. data/doc/rdoc/files/lib/wee/session_rb.html +1 -1
  107. data/doc/rdoc/files/lib/wee/skeleton/og/components/main_rb.html +101 -0
  108. data/doc/rdoc/files/lib/wee/skeleton/og/conf/db_rb.html +114 -0
  109. data/doc/rdoc/files/lib/wee/skeleton/og/models/recipe_rb.html +101 -0
  110. data/doc/rdoc/files/lib/wee/skeleton/og/run_rb.html +115 -0
  111. data/doc/rdoc/files/lib/wee/skeleton/simple/components/main_rb.html +101 -0
  112. data/doc/rdoc/files/lib/wee/skeleton/simple/run_rb.html +111 -0
  113. data/doc/rdoc/files/lib/wee/template_rb.html +101 -0
  114. data/doc/rdoc/files/lib/wee/utils/autoreload_rb.html +1 -1
  115. data/doc/rdoc/files/lib/wee/utils/helper_rb.html +1 -1
  116. data/doc/rdoc/files/lib/wee_rb.html +4 -2
  117. data/doc/rdoc/fr_class_index.html +8 -4
  118. data/doc/rdoc/fr_file_index.html +17 -1
  119. data/doc/rdoc/fr_method_index.html +312 -267
  120. data/examples/live-update.rb +1 -1
  121. data/install.rb +14 -0
  122. data/lib/wee.rb +6 -2
  123. data/lib/wee/adaptors/webrick.rb +17 -5
  124. data/lib/wee/application.rb +2 -1
  125. data/lib/wee/continuation/session.rb +1 -146
  126. data/lib/wee/core/callback.rb +11 -5
  127. data/lib/wee/core/component.rb +14 -10
  128. data/lib/wee/databases/og.rb +3 -113
  129. data/lib/wee/databases/og/application.rb +3 -0
  130. data/lib/wee/databases/og/old_scaffolder.rb +98 -0
  131. data/lib/wee/databases/og/scaffolder.rb +174 -0
  132. data/lib/wee/databases/og/session.rb +9 -0
  133. data/lib/wee/idgen/md5.rb +21 -0
  134. data/lib/wee/{idgen.rb → idgen/simple.rb} +2 -4
  135. data/lib/wee/pageless.rb +3 -0
  136. data/lib/wee/pageless/application.rb +9 -0
  137. data/lib/wee/pageless/request.rb +15 -0
  138. data/lib/wee/pageless/session.rb +89 -0
  139. data/lib/wee/renderer/html/brushes.rb +100 -115
  140. data/lib/wee/renderer/html/canvas.rb +32 -2
  141. data/lib/wee/request.rb +36 -24
  142. data/lib/wee/response.rb +8 -1
  143. data/lib/wee/session.rb +13 -7
  144. data/lib/wee/skeleton/og/README +38 -0
  145. data/lib/wee/skeleton/og/components/main.rb +16 -0
  146. data/lib/wee/skeleton/og/conf/db.rb +8 -0
  147. data/lib/wee/skeleton/og/models/recipe.rb +5 -0
  148. data/lib/wee/skeleton/og/run.rb +23 -0
  149. data/lib/wee/skeleton/simple/README +32 -0
  150. data/lib/wee/skeleton/simple/components/main.rb +25 -0
  151. data/lib/wee/skeleton/simple/run.rb +12 -0
  152. data/lib/wee/template.rb +28 -0
  153. data/lib/wee/utils/autoreload.rb +29 -0
  154. data/lib/wee/utils/helper.rb +9 -5
  155. data/test/test_request.rb +4 -3
  156. data/wee.gemspec +3 -1
  157. metadata +91 -22
@@ -47,45 +47,36 @@ class Brush::GenericEncodedTextBrush < Brush
47
47
  end
48
48
  end
49
49
 
50
- module Brush::ToCallback
51
- private
50
+ class Brush::GenericTagBrush < Brush
52
51
 
53
- def to_callback(symbol, args, block)
54
- raise ArgumentError if symbol and block
55
- if symbol
56
- Wee::LiteralMethodCallback.new(@canvas.current_component, symbol, *args)
57
- else
58
- raise ArgumentError if not args.empty?
59
- block
52
+ class << self
53
+ private
54
+
55
+ def bool_attr(*attrs)
56
+ attrs.each { |a|
57
+ class_eval "
58
+ def #{ a }(bool=true)
59
+ if bool
60
+ @attributes['#{ a }'] = nil
61
+ else
62
+ @attributes.delete('#{ a }')
63
+ end
64
+ self
65
+ end
66
+ "
67
+ }
60
68
  end
61
- end
62
- end
63
-
64
- class Brush::GenericTagBrush < Brush
65
69
 
66
- def self.bool_attr(*attrs)
67
- attrs.each { |a|
68
- class_eval "
69
- def #{ a }(bool=true)
70
- if bool
71
- @attributes['#{ a }'] = nil
72
- else
73
- @attributes.delete('#{ a }')
70
+ def html_attr(*attrs)
71
+ attrs.each { |a|
72
+ class_eval "
73
+ def #{ a }(value)
74
+ html_attr('#{ a }', value)
74
75
  end
75
- self
76
- end
77
- "
78
- }
79
- end
76
+ "
77
+ }
78
+ end
80
79
 
81
- def self.html_attr(*attrs)
82
- attrs.each { |a|
83
- class_eval "
84
- def #{ a }(value)
85
- html_attr('#{ a }', value)
86
- end
87
- "
88
- }
89
80
  end
90
81
 
91
82
  private
@@ -99,8 +90,45 @@ class Brush::GenericTagBrush < Brush
99
90
  self
100
91
  end
101
92
 
93
+ # Converts the arguments into a callable object.
94
+ #
95
+ def to_callback(symbol, args, block)
96
+ raise ArgumentError if symbol and block
97
+ if symbol.nil?
98
+ raise ArgumentError if not args.empty?
99
+ block
100
+ else
101
+ if symbol.is_a?(Symbol) or symbol.is_a?(String)
102
+ Wee::LiteralMethodCallback.new(@canvas.current_component, symbol, *args)
103
+ else
104
+ raise ArgumentError if not args.empty?
105
+ symbol
106
+ end
107
+ end
108
+ end
109
+
102
110
  public
103
111
 
112
+ def __input_callback(symbol=nil, *args, &block)
113
+ name(@canvas.register_callback(:input, to_callback(symbol, args, block)))
114
+ end
115
+
116
+ def __action_callback(symbol=nil, *args, &block)
117
+ name(@canvas.register_callback(:action, to_callback(symbol, args, block)))
118
+ end
119
+
120
+ # The callback id is listed in the URL (not as a form-data field)
121
+
122
+ def __actionurl_callback(symbol=nil, *args, &block)
123
+ __set_url(@canvas.url_for_callback(to_callback(symbol, args, block)))
124
+ end
125
+
126
+ # The callback id is listed in the URL (not as a form-data field)
127
+
128
+ def __actionurl_named_callback(name, symbol=nil, *args, &block)
129
+ __set_url(@canvas.url_for_named_callback(name, to_callback(symbol, args, block)))
130
+ end
131
+
104
132
  def method_missing(id, attr)
105
133
  html_attr(id.to_s, attr)
106
134
  end
@@ -117,8 +145,6 @@ class Brush::GenericTagBrush < Brush
117
145
  html_attr("class", c)
118
146
  end
119
147
 
120
- include Brush::ToCallback
121
-
122
148
  def onclick_callback(symbol=nil, *args, &block)
123
149
  raise ArgumentError if symbol and block
124
150
  url = @canvas.url_for_callback(to_callback(symbol, args, block))
@@ -128,8 +154,7 @@ class Brush::GenericTagBrush < Brush
128
154
  # This method construct the css-class attribute by looking up the property
129
155
  # from the current component.
130
156
 
131
- def css_class_for(c)
132
- prop = 'css.' + c
157
+ def css_class_for(prop)
133
158
  val = @canvas.current_component.lookup_property(prop)
134
159
  raise "no property found for: <#{ prop }>" if val.nil?
135
160
  css_class(val)
@@ -167,8 +192,7 @@ class Brush::ImageTag < Brush::GenericSingleTagBrush
167
192
  # This method construct the src attribute by looking up the property from the
168
193
  # current component.
169
194
 
170
- def src_for(s)
171
- prop = "img." + s
195
+ def src_for(prop)
172
196
  val = @canvas.current_component.lookup_property(prop)
173
197
  raise "no property found for: <#{ prop }>" if val.nil?
174
198
  src(val)
@@ -248,7 +272,6 @@ class Brush::TableRowTag < Brush::GenericTagBrush
248
272
  end
249
273
  end
250
274
 
251
-
252
275
  class Brush::InputTag < Brush::GenericSingleTagBrush
253
276
  def initialize
254
277
  super('input')
@@ -262,48 +285,13 @@ class Brush::InputTag < Brush::GenericSingleTagBrush
262
285
  end
263
286
  end
264
287
 
265
-
266
- module Brush::InputCallbackMixin
267
- public
268
-
269
- def callback(symbol=nil, *args, &block)
270
- raise ArgumentError if symbol and block
271
- name(@canvas.register_callback(:input, to_callback(symbol, args, block)))
272
- end
273
-
274
- include Brush::ToCallback
275
- end
276
-
277
- module Brush::ActionCallbackMixin
278
- public
279
-
280
- def callback(symbol=nil, *args, &block)
281
- raise ArgumentError if symbol and block
282
- name(@canvas.register_callback(:action, to_callback(symbol, args, block)))
283
- end
284
-
285
- include Brush::ToCallback
286
- end
287
-
288
- # The callback id is listed in the URL (not as a form-data field)
289
- module Brush::ActionURLCallbackMixin
290
- public
291
-
292
- def callback(symbol=nil, *args, &block)
293
- raise ArgumentError if symbol and block
294
- __set_url(@canvas.url_for_callback(to_callback(symbol, args, block)))
295
- end
296
-
297
- include Brush::ToCallback
298
- end
299
-
300
288
  class Brush::TextAreaTag < Brush::GenericTagBrush
301
- include Brush::InputCallbackMixin
302
-
303
289
  def initialize
304
290
  super('textarea')
305
291
  end
306
292
 
293
+ alias callback __input_callback
294
+
307
295
  html_attr :name, :rows, :cols, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange
308
296
  bool_attr :disabled, :readonly
309
297
 
@@ -321,8 +309,6 @@ class Brush::SelectOptionTag < Brush::GenericTagBrush
321
309
  end
322
310
 
323
311
  class Brush::SelectListTag < Brush::GenericTagBrush
324
- include Brush::InputCallbackMixin
325
-
326
312
  def initialize(items)
327
313
  super('select')
328
314
  @items = items
@@ -339,32 +325,34 @@ class Brush::SelectListTag < Brush::GenericTagBrush
339
325
 
340
326
  bool_attr :multiple
341
327
 
342
- alias __old_callback callback
343
- private :__old_callback
344
- def callback(symbol=nil, &block)
345
- raise ArgumentError if symbol and block
346
- block = Wee::LiteralMethodCallback.new(@canvas.current_component, symbol) unless block
347
-
348
- @callback = block
328
+ def callback(symbol=nil, *args, &block)
329
+ @callback = to_callback(symbol, args, block)
349
330
  self
350
331
  end
351
332
 
333
+ class SelectListCallback < Struct.new(:callback, :items, :is_multiple)
334
+ def call(input)
335
+ choosen = input.list.map {|idx|
336
+ idx = Integer(idx)
337
+ raise "invalid index in select list" if idx < 0 or idx > items.size
338
+ items[idx]
339
+ }
340
+ if choosen.size > 1 and not is_multiple
341
+ raise "choosen more than one element from a non-multiple select list"
342
+ end
343
+ callback.call(choosen)
344
+ end
345
+ end
346
+
352
347
  def with
353
348
  @labels ||= @items.collect { |i| i.to_s }
354
349
  @selected ||= Array.new
355
350
 
356
351
  if @callback
357
- __old_callback {|input|
358
- choosen = input.list.map {|idx|
359
- idx = Integer(idx)
360
- raise "invalid index in select list" if idx < 0 or idx > @items.size
361
- @items[idx]
362
- }
363
- if choosen.size > 1 and not @attributes.has_key?('multiple')
364
- raise "choosen more than one element from a non-multiple select list"
365
- end
366
- @callback.call(choosen)
367
- }
352
+ # A callback was specified. We have to wrap it inside a
353
+ # SelectListCallback object as we want to perform some
354
+ # additional actions.
355
+ __input_callback(SelectListCallback.new(@callback, @items, @attributes.has_key?('multiple')))
368
356
  end
369
357
 
370
358
  super do
@@ -376,32 +364,30 @@ class Brush::SelectListTag < Brush::GenericTagBrush
376
364
  end
377
365
 
378
366
  class Brush::TextInputTag < Brush::InputTag
379
- include Brush::InputCallbackMixin
380
-
381
367
  def initialize
382
368
  super
383
369
  type('text')
384
370
  end
371
+
372
+ alias callback __input_callback
385
373
  end
386
374
 
387
375
  class Brush::FileUploadTag < Brush::InputTag
388
- include Brush::InputCallbackMixin
389
-
390
376
  def initialize
391
377
  super
392
378
  type('file')
393
379
  end
394
- end
395
-
396
380
 
381
+ alias callback __input_callback
382
+ end
397
383
 
398
384
  class Brush::SubmitButtonTag < Brush::InputTag
399
- include Brush::ActionCallbackMixin
400
-
401
385
  def initialize
402
386
  super
403
387
  type('submit')
404
388
  end
389
+
390
+ alias callback __action_callback
405
391
  end
406
392
 
407
393
  # NOTE: The form-fields returned by a image-button-tag is browser-specific.
@@ -412,19 +398,18 @@ end
412
398
  # generate a "name" fields in the request, to make this image-button work.
413
399
 
414
400
  class Brush::ImageButtonTag < Brush::InputTag
415
- include Brush::ActionCallbackMixin
416
-
417
401
  def initialize
418
402
  super
419
403
  type('image')
420
404
  end
421
405
 
406
+ alias callback __action_callback
407
+
422
408
  def value(v)
423
409
  raise "specified value will not be used in the request"
424
410
  end
425
411
  end
426
412
 
427
-
428
413
  class Brush::TableDataTag < Brush::GenericTagBrush
429
414
  def initialize
430
415
  super('td')
@@ -441,10 +426,7 @@ class Brush::TableHeaderTag < Brush::GenericTagBrush
441
426
  end
442
427
  end
443
428
 
444
-
445
429
  class Brush::FormTag < Brush::GenericTagBrush
446
- include Brush::ActionURLCallbackMixin
447
-
448
430
  def initialize
449
431
  super('form')
450
432
  @attributes['method'] = 'POST'
@@ -453,11 +435,14 @@ class Brush::FormTag < Brush::GenericTagBrush
453
435
  html_attr :action, :enctype
454
436
 
455
437
  alias __set_url action
438
+ alias callback __actionurl_callback
439
+ alias named_callback __actionurl_named_callback
456
440
 
457
441
  def with(*args, &block)
458
442
  # If no action was specified, use a dummy one.
459
443
  unless @attributes.has_key?('action')
460
444
  req = @canvas.rendering_context.request
445
+ # TODO?
461
446
  @attributes['action'] = req.build_url(req.request_handler_id, req.page_id)
462
447
  end
463
448
  super
@@ -465,8 +450,6 @@ class Brush::FormTag < Brush::GenericTagBrush
465
450
  end
466
451
 
467
452
  class Brush::AnchorTag < Brush::GenericTagBrush
468
- include Brush::ActionURLCallbackMixin
469
-
470
453
  def initialize
471
454
  super('a')
472
455
  end
@@ -474,10 +457,12 @@ class Brush::AnchorTag < Brush::GenericTagBrush
474
457
  html_attr :href, :title
475
458
  alias url href
476
459
  alias tooltip title
460
+
477
461
  alias __set_url url
462
+ alias callback __actionurl_callback
463
+ alias named_callback __actionurl_named_callback
478
464
  end
479
465
 
480
-
481
466
  class Brush::Page < Brush
482
467
  def title(t)
483
468
  @title = t
@@ -63,11 +63,20 @@ class HtmlCanvas < Canvas
63
63
  end
64
64
 
65
65
  generic_tag :html, :head, :body, :title, :style, :h1, :h2, :h3, :h4, :h5, :div
66
- generic_single_tag :link
66
+ generic_tag :div, :span, :ul, :ol, :li
67
+ generic_single_tag :link, :hr
67
68
 
68
69
  def url_for_callback(callback)
70
+ url_for_callback_id(register_callback(:action, callback))
71
+ end
72
+
73
+ def url_for_named_callback(name, callback)
74
+ url_for_callback_id(register_named_callback(name, :action, callback))
75
+ end
76
+
77
+ def url_for_callback_id(callback_id)
69
78
  req = self.rendering_context.request
70
- url = req.build_url(req.request_handler_id, req.page_id, register_callback(:action, callback))
79
+ url = req.build_url(req.request_handler_id, req.page_id, callback_id)
71
80
  return url
72
81
  end
73
82
 
@@ -75,6 +84,10 @@ class HtmlCanvas < Canvas
75
84
  self.rendering_context.callbacks.register_for(self.current_component, type, callback)
76
85
  end
77
86
 
87
+ def register_named_callback(name, type, callback)
88
+ self.rendering_context.callbacks.register_named_for(self.current_component, type, callback, name)
89
+ end
90
+
78
91
  def table(*args, &block)
79
92
  handle(Brush::TableTag.new, *args, &block)
80
93
  end
@@ -178,6 +191,23 @@ class HtmlCanvas < Canvas
178
191
  nil
179
192
  end
180
193
 
194
+ require 'erb'
195
+
196
+ def template(filename)
197
+ raise "Template file #{ filename } not found!" unless File.exists?(filename)
198
+ self.close
199
+ compiler = ERB::Compiler.new(nil)
200
+ compiler.put_cmd = 'r << '
201
+ src = compiler.compile(File.read(filename))
202
+ if $DEBUG
203
+ puts "-------------------------"
204
+ puts src
205
+ puts "-------------------------"
206
+ end
207
+ @current_component.instance_eval(src, '(erb)', 1)
208
+ return nil
209
+ end
210
+
181
211
  private
182
212
 
183
213
  def handle(brush, *args, &block)
data/lib/wee/request.rb CHANGED
@@ -6,11 +6,40 @@
6
6
 
7
7
  class Wee::Request
8
8
 
9
- attr_reader :request_handler_id, :page_id, :fields
9
+ DELIM = '=/'
10
10
 
11
- def initialize(app_path, path, headers, fields)
12
- @app_path, @path, @headers = app_path, path, headers
11
+ attr_accessor :request_handler_id
12
+ attr_reader :page_id, :fields, :cookies
13
13
 
14
+ def initialize(app_path, path, headers, fields, cookies)
15
+ @app_path, @path, @headers, @cookies = app_path, path, headers, cookies
16
+ parse_fields(fields)
17
+ parse_path
18
+ end
19
+
20
+ def application_path
21
+ @app_path
22
+ end
23
+
24
+ def build_url(request_handler_id=nil, page_id=nil, callback_id=nil)
25
+ raise ArgumentError if request_handler_id.nil? and not page_id.nil?
26
+
27
+ arr = [request_handler_id, page_id].compact
28
+
29
+ url = ""
30
+ url << @app_path
31
+ unless arr.empty?
32
+ url << '/' if url[-1,1] != '/' # /appXXX -> /app/XXX
33
+ url << (DELIM + arr.join('/'))
34
+ end
35
+ url << ('?' + callback_id) if callback_id
36
+
37
+ return url
38
+ end
39
+
40
+ private
41
+
42
+ def parse_fields(fields)
14
43
  fields ||= Hash.new
15
44
  @fields = Hash.new
16
45
 
@@ -29,29 +58,12 @@ class Wee::Request
29
58
  end
30
59
  end
31
60
  end
32
-
33
- full_app_path, req_path = @path.split('@', 2)
34
- @request_handler_id = @page_id = nil
35
- @request_handler_id, @page_id = req_path.split('/', 2) if req_path
36
61
  end
37
62
 
38
- def application_path
39
- @app_path
63
+ def parse_path
64
+ full_app_path, req_path = @path.split(DELIM, 2)
65
+ @request_handler_id = @page_id = nil
66
+ @request_handler_id, @page_id = req_path.split('/', 2) if req_path
40
67
  end
41
68
 
42
- def build_url(request_handler_id=nil, page_id=nil, callback_id=nil)
43
- raise ArgumentError if request_handler_id.nil? and not page_id.nil?
44
-
45
- arr = [request_handler_id, page_id].compact
46
-
47
- url = ""
48
- url << @app_path
49
- unless arr.empty?
50
- url << '/' if url[-1,1] != '/' # /app@ -> /app/@
51
- url << ('@' + arr.join('/'))
52
- end
53
- url << ('?' + callback_id) if callback_id
54
-
55
- return url
56
- end
57
69
  end