wee 0.1.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/INSTALL +7 -0
  2. data/README +268 -0
  3. data/Rakefile +26 -0
  4. data/TODO +116 -0
  5. data/benchmark/Centrino1300/result.2000.counter.action +45 -0
  6. data/benchmark/Centrino1300/result.2000.counter.render +43 -0
  7. data/benchmark/Centrino1300/result.2000.filehandler +43 -0
  8. data/benchmark/Centrino600/result.2000.counter.action +47 -0
  9. data/benchmark/Centrino600/result.2000.counter.render +45 -0
  10. data/benchmark/Centrino600/result.2000.filehandler +43 -0
  11. data/benchmark/Makefile +48 -0
  12. data/benchmark/bench.sh +24 -0
  13. data/benchmark/counter.rb +96 -0
  14. data/benchmark/filehandler.rb +6 -0
  15. data/doc/rdoc/classes/Array.html +172 -0
  16. data/doc/rdoc/classes/Cache.html +126 -0
  17. data/doc/rdoc/classes/Cache/StorageCache.html +320 -0
  18. data/doc/rdoc/classes/Cache/Strategy.html +128 -0
  19. data/doc/rdoc/classes/Cache/Strategy/CapacityBounded.html +269 -0
  20. data/doc/rdoc/classes/Cache/Strategy/LFU.html +238 -0
  21. data/doc/rdoc/classes/Cache/Strategy/LFU/Item.html +111 -0
  22. data/doc/rdoc/classes/Cache/Strategy/LRU.html +238 -0
  23. data/doc/rdoc/classes/Cache/Strategy/LRU/Item.html +111 -0
  24. data/doc/rdoc/classes/Cache/Strategy/Unbounded.html +225 -0
  25. data/doc/rdoc/classes/Cache/Strategy/Unbounded/Item.html +111 -0
  26. data/doc/rdoc/classes/Enumerable.html +146 -0
  27. data/doc/rdoc/classes/LiteralMethod.html +196 -0
  28. data/doc/rdoc/classes/Object.html +178 -0
  29. data/doc/rdoc/classes/String.html +172 -0
  30. data/doc/rdoc/classes/Struct.html +174 -0
  31. data/doc/rdoc/classes/Wee.html +160 -0
  32. data/doc/rdoc/classes/Wee/AnswerDecoration.html +182 -0
  33. data/doc/rdoc/classes/Wee/Application.html +337 -0
  34. data/doc/rdoc/classes/Wee/Brush.html +245 -0
  35. data/doc/rdoc/classes/Wee/Brush/ActionCallbackMixin.html +149 -0
  36. data/doc/rdoc/classes/Wee/Brush/ActionMixin.html +146 -0
  37. data/doc/rdoc/classes/Wee/Brush/ActionURLCallbackMixin.html +157 -0
  38. data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +210 -0
  39. data/doc/rdoc/classes/Wee/Brush/AssignMixin.html +141 -0
  40. data/doc/rdoc/classes/Wee/Brush/CallbackMixin.html +141 -0
  41. data/doc/rdoc/classes/Wee/Brush/FormTag.html +225 -0
  42. data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +176 -0
  43. data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +283 -0
  44. data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +176 -0
  45. data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +195 -0
  46. data/doc/rdoc/classes/Wee/Brush/InputCallbackMixin.html +149 -0
  47. data/doc/rdoc/classes/Wee/Brush/InputTag.html +172 -0
  48. data/doc/rdoc/classes/Wee/Brush/Page.html +193 -0
  49. data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +267 -0
  50. data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +177 -0
  51. data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +154 -0
  52. data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +173 -0
  53. data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +146 -0
  54. data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +277 -0
  55. data/doc/rdoc/classes/Wee/Brush/TableTag.html +146 -0
  56. data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +229 -0
  57. data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +154 -0
  58. data/doc/rdoc/classes/Wee/Callback.html +231 -0
  59. data/doc/rdoc/classes/Wee/CallbackRegistry.html +308 -0
  60. data/doc/rdoc/classes/Wee/CallbackStream.html +227 -0
  61. data/doc/rdoc/classes/Wee/Canvas.html +235 -0
  62. data/doc/rdoc/classes/Wee/Component.html +933 -0
  63. data/doc/rdoc/classes/Wee/Context.html +111 -0
  64. data/doc/rdoc/classes/Wee/Decoration.html +338 -0
  65. data/doc/rdoc/classes/Wee/Delegate.html +247 -0
  66. data/doc/rdoc/classes/Wee/ErrorPage.html +175 -0
  67. data/doc/rdoc/classes/Wee/ErrorResponse.html +180 -0
  68. data/doc/rdoc/classes/Wee/GenericResponse.html +162 -0
  69. data/doc/rdoc/classes/Wee/HtmlCanvas.html +751 -0
  70. data/doc/rdoc/classes/Wee/HtmlWriter.html +351 -0
  71. data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +180 -0
  72. data/doc/rdoc/classes/Wee/MethodCallback.html +193 -0
  73. data/doc/rdoc/classes/Wee/Page.html +111 -0
  74. data/doc/rdoc/classes/Wee/Presenter.html +521 -0
  75. data/doc/rdoc/classes/Wee/RedirectResponse.html +150 -0
  76. data/doc/rdoc/classes/Wee/RefreshResponse.html +157 -0
  77. data/doc/rdoc/classes/Wee/RenderingContext.html +111 -0
  78. data/doc/rdoc/classes/Wee/Request.html +268 -0
  79. data/doc/rdoc/classes/Wee/RequestHandler.html +336 -0
  80. data/doc/rdoc/classes/Wee/Response.html +260 -0
  81. data/doc/rdoc/classes/Wee/Session.html +469 -0
  82. data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +198 -0
  83. data/doc/rdoc/classes/Wee/Snapshot.html +211 -0
  84. data/doc/rdoc/classes/Wee/StateHolder.html +149 -0
  85. data/doc/rdoc/classes/Wee/StateRegistry.html +434 -0
  86. data/doc/rdoc/classes/Wee/StateRegistry/Snapshot.html +320 -0
  87. data/doc/rdoc/classes/Wee/StateRegistry/WithObject.html +153 -0
  88. data/doc/rdoc/classes/Wee/Utils.html +111 -0
  89. data/doc/rdoc/classes/Wee/Utils/LRUCache.html +148 -0
  90. data/doc/rdoc/classes/Wee/ValueHolder.html +220 -0
  91. data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +330 -0
  92. data/doc/rdoc/created.rid +1 -0
  93. data/doc/rdoc/files/INSTALL.html +118 -0
  94. data/doc/rdoc/files/README.html +466 -0
  95. data/doc/rdoc/files/lib/cache/cache_rb.html +101 -0
  96. data/doc/rdoc/files/lib/wee/adaptors/webrick_rb.html +108 -0
  97. data/doc/rdoc/files/lib/wee/application_rb.html +112 -0
  98. data/doc/rdoc/files/lib/wee/callback_rb.html +107 -0
  99. data/doc/rdoc/files/lib/wee/component_ext_rb.html +101 -0
  100. data/doc/rdoc/files/lib/wee/component_rb.html +109 -0
  101. data/doc/rdoc/files/lib/wee/context_rb.html +101 -0
  102. data/doc/rdoc/files/lib/wee/core/callback_rb.html +115 -0
  103. data/doc/rdoc/files/lib/wee/core/component_rb.html +108 -0
  104. data/doc/rdoc/files/lib/wee/core/decoration_rb.html +133 -0
  105. data/doc/rdoc/files/lib/wee/core/presenter_rb.html +112 -0
  106. data/doc/rdoc/files/lib/wee/core/snapshot_rb.html +113 -0
  107. data/doc/rdoc/files/lib/wee/core/valueholder_rb.html +110 -0
  108. data/doc/rdoc/files/lib/wee/core_rb.html +131 -0
  109. data/doc/rdoc/files/lib/wee/decoration_rb.html +101 -0
  110. data/doc/rdoc/files/lib/wee/holder_rb.html +101 -0
  111. data/doc/rdoc/files/lib/wee/html_canvas_rb.html +108 -0
  112. data/doc/rdoc/files/lib/wee/html_writer_rb.html +108 -0
  113. data/doc/rdoc/files/lib/wee/idgen_rb.html +101 -0
  114. data/doc/rdoc/files/lib/wee/page_rb.html +101 -0
  115. data/doc/rdoc/files/lib/wee/presenter_rb.html +112 -0
  116. data/doc/rdoc/files/lib/wee/renderer/html/brushes_rb.html +101 -0
  117. data/doc/rdoc/files/lib/wee/renderer/html/canvas_rb.html +101 -0
  118. data/doc/rdoc/files/lib/wee/renderer/html/writer_rb.html +108 -0
  119. data/doc/rdoc/files/lib/wee/rendering/html/brushes_rb.html +101 -0
  120. data/doc/rdoc/files/lib/wee/rendering/html/canvas_rb.html +101 -0
  121. data/doc/rdoc/files/lib/wee/rendering/html/writer_rb.html +108 -0
  122. data/doc/rdoc/files/lib/wee/request_rb.html +113 -0
  123. data/doc/rdoc/files/lib/wee/requesthandler_rb.html +101 -0
  124. data/doc/rdoc/files/lib/wee/response_rb.html +108 -0
  125. data/doc/rdoc/files/lib/wee/session_rb.html +109 -0
  126. data/doc/rdoc/files/lib/wee/snapshot_ext_rb.html +101 -0
  127. data/doc/rdoc/files/lib/wee/snapshot_rb.html +107 -0
  128. data/doc/rdoc/files/lib/wee/state_registry_rb.html +110 -0
  129. data/doc/rdoc/files/lib/wee/stuff_rb.html +144 -0
  130. data/doc/rdoc/files/lib/wee/utils/cache_rb.html +108 -0
  131. data/doc/rdoc/files/lib/wee/webrick_rb.html +108 -0
  132. data/doc/rdoc/files/lib/wee_rb.html +132 -0
  133. data/doc/rdoc/fr_class_index.html +93 -0
  134. data/doc/rdoc/fr_file_index.html +51 -0
  135. data/doc/rdoc/fr_method_index.html +242 -0
  136. data/doc/rdoc/index.html +24 -0
  137. data/doc/rdoc/rdoc-style.css +208 -0
  138. data/examples/ObjectSpaceBrowser.rb +199 -0
  139. data/examples/calendar.rb +366 -0
  140. data/examples/cc.rb +94 -0
  141. data/examples/draw.rb +91 -0
  142. data/examples/example.rb +223 -0
  143. data/examples/test.rb +66 -0
  144. data/examples/window.rb +53 -0
  145. data/lib/cache/cache.rb +9 -0
  146. data/lib/wee.rb +18 -8
  147. data/lib/wee/adaptors/webrick.rb +73 -0
  148. data/lib/wee/application.rb +69 -71
  149. data/lib/wee/context.rb +2 -12
  150. data/lib/wee/core.rb +15 -0
  151. data/lib/wee/core/callback.rb +108 -0
  152. data/lib/wee/core/component.rb +314 -0
  153. data/lib/wee/core/decoration.rb +129 -0
  154. data/lib/wee/core/presenter.rb +132 -0
  155. data/lib/wee/core/snapshot.rb +21 -0
  156. data/lib/wee/core/valueholder.rb +19 -0
  157. data/lib/wee/idgen.rb +13 -0
  158. data/lib/wee/page.rb +1 -1
  159. data/lib/wee/renderer/html/brushes.rb +435 -0
  160. data/lib/wee/renderer/html/canvas.rb +148 -0
  161. data/lib/wee/{html_writer.rb → renderer/html/writer.rb} +31 -16
  162. data/lib/wee/request.rb +57 -0
  163. data/lib/wee/requesthandler.rb +77 -0
  164. data/lib/wee/response.rb +77 -0
  165. data/lib/wee/session.rb +70 -64
  166. data/lib/wee/{snapshot.rb → snapshot_ext.rb} +4 -4
  167. data/test/components/calltest.rb +16 -0
  168. data/test/components/counter.rb +17 -0
  169. data/test/components/messagebox.rb +15 -0
  170. data/test/components/page.rb +14 -0
  171. data/test/components/page_decoration.rb +7 -0
  172. data/test/stress.rb +64 -0
  173. data/test/test_component.rb +106 -0
  174. data/test/test_html_canvas.rb +25 -0
  175. data/test/test_html_writer.rb +27 -0
  176. data/test/test_request.rb +13 -0
  177. data/test/utils/cross.rb +65 -0
  178. data/test/utils/generic_plotter.rb +28 -0
  179. data/test/utils/gnuplot.rb +31 -0
  180. data/test/utils/measure_memory.rb +9 -0
  181. data/test/utils/memory_plotter.rb +10 -0
  182. data/test/utils/object_plotter.rb +10 -0
  183. data/test/utils/webrick_background.rb +31 -0
  184. data/wee.gemspec +22 -0
  185. metadata +222 -18
  186. data/lib/wee/component.rb +0 -126
  187. data/lib/wee/delegate_decoration.rb +0 -22
  188. data/lib/wee/handler_registry.rb +0 -89
  189. data/lib/wee/holder.rb +0 -14
  190. data/lib/wee/html_canvas.rb +0 -379
  191. data/lib/wee/state_registry.rb +0 -173
  192. data/lib/wee/stuff.rb +0 -29
  193. data/lib/wee/webrick.rb +0 -15
@@ -0,0 +1,21 @@
1
+ # This class is for backtracking the state of components (or
2
+ # decorations/presenters). Components that want an undo-facility to be
3
+ # implemented (triggered for example by a browsers back-button), have to
4
+ # overwrite the Component#backtrack_state method. Class Wee::Snapshot simply
5
+ # represents a collection of objects from which snapshots were taken via
6
+ # methods take_snapshot.
7
+
8
+ class Wee::Snapshot
9
+ def initialize
10
+ @objects = Hash.new
11
+ end
12
+
13
+ def add(object)
14
+ oid = object.object_id
15
+ @objects[oid] = [object, object.take_snapshot] unless @objects.include?(oid)
16
+ end
17
+
18
+ def restore
19
+ @objects.each_value { |object, value| object.restore_snapshot(value) }
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # Implements a value holder. Useful for backtracking the reference assigned to
2
+ # an instance variable (not the object itself!). An example where this is used
3
+ # is the <tt>@decoration</tt> attribute of class Wee::Component.
4
+
5
+ class Wee::ValueHolder
6
+ attr_accessor :value
7
+
8
+ def initialize(value=nil)
9
+ @value = value
10
+ end
11
+
12
+ def take_snapshot
13
+ @value
14
+ end
15
+
16
+ def restore_snapshot(value)
17
+ @value = value
18
+ end
19
+ end
data/lib/wee/idgen.rb ADDED
@@ -0,0 +1,13 @@
1
+ class Wee::SimpleIdGenerator
2
+ def initialize(initial_value=0)
3
+ @value = initial_value
4
+ end
5
+
6
+ def current
7
+ @value
8
+ end
9
+
10
+ def next
11
+ @value += 1
12
+ end
13
+ end
data/lib/wee/page.rb CHANGED
@@ -1 +1 @@
1
- class Wee::Page < Struct.new(:snapshot, :handler_registry); end
1
+ class Wee::Page < Struct.new(:snapshot, :callbacks); end
@@ -0,0 +1,435 @@
1
+ module Wee
2
+
3
+ class Brush
4
+ attr_accessor :parent, :canvas
5
+
6
+ def initialize
7
+ @parent = @canvas = @closed = nil
8
+ end
9
+
10
+ def with(*args, &block)
11
+ raise "either args or block, but not both" if block and not args.empty?
12
+
13
+ @canvas.nest(&block) if block
14
+ @closed = true
15
+ end
16
+
17
+ def close
18
+ with unless @closed
19
+ end
20
+ end
21
+
22
+ class Brush::GenericTextBrush < Brush
23
+ def initialize(text)
24
+ super()
25
+ @text = text
26
+ end
27
+
28
+ def with
29
+ doc = @canvas.document
30
+ doc << @text
31
+ super
32
+ nil
33
+ end
34
+ end
35
+
36
+ class Brush::GenericEncodedTextBrush < Brush
37
+ def initialize(text)
38
+ super()
39
+ @text = text
40
+ end
41
+
42
+ def with
43
+ doc = @canvas.document
44
+ doc.encode_text(@text)
45
+ super
46
+ nil
47
+ end
48
+ end
49
+
50
+ class Brush::GenericTagBrush < Brush
51
+ def initialize(tag)
52
+ super()
53
+ @tag = tag
54
+ @attributes = Hash.new
55
+ end
56
+
57
+ def type(t)
58
+ @attributes["type"] = t
59
+ self
60
+ end
61
+
62
+ def css_class(c)
63
+ @attributes["class"] = c
64
+ self
65
+ end
66
+
67
+ def id(x)
68
+ @attributes["id"] = x
69
+ self
70
+ end
71
+
72
+ def method_missing(m, arg)
73
+ @attributes[m.to_s] = arg.to_s
74
+ self
75
+ end
76
+
77
+ def with(text=nil, &block)
78
+ doc = @canvas.document
79
+ doc.start_tag(@tag, @attributes)
80
+ if text
81
+ doc.text(text)
82
+ super(text, &block)
83
+ else
84
+ super(&block)
85
+ end
86
+ doc.end_tag(@tag)
87
+ nil
88
+ end
89
+ end
90
+
91
+ class Brush::TableTag < Brush::GenericTagBrush
92
+ def initialize
93
+ super('table')
94
+ end
95
+ end
96
+
97
+ class Brush::TableRowTag < Brush::GenericTagBrush
98
+ def initialize
99
+ super('tr')
100
+ end
101
+
102
+ def align_top
103
+ @attributes['align'] = 'top'
104
+ self
105
+ end
106
+
107
+ def columns(*cols)
108
+ with {
109
+ cols.each {|col| @canvas.table_data(col) }
110
+ }
111
+ end
112
+
113
+ def headings(*headers)
114
+ with {
115
+ headers.each {|head| @canvas.table_heading(head) }
116
+ }
117
+ end
118
+
119
+ def spanning_column(str, colspan)
120
+ with {
121
+ @canvas.table_data.col_span(colspan).with(str)
122
+ }
123
+ end
124
+
125
+ def spacer
126
+ with {
127
+ @canvas.table_data { @canvas.space }
128
+ }
129
+ end
130
+ end
131
+
132
+
133
+ class Brush::InputTag < Brush::GenericTagBrush
134
+ def initialize
135
+ super('input')
136
+ end
137
+
138
+ %w(type name value size maxlength checked src).each do |meth|
139
+ eval %[
140
+ def #{ meth }(arg)
141
+ @attributes['#{ meth }'] = arg
142
+ self
143
+ end
144
+ ]
145
+ end
146
+
147
+ def with
148
+ super
149
+ end
150
+ end
151
+
152
+ module Brush::CallbackMixin
153
+ private
154
+
155
+ def register_callback(type, &block)
156
+ raise ArgumentError, "no callback block given" if block.nil?
157
+ @canvas.rendering_context.callbacks.register_for(@canvas.current_component, type, &block)
158
+ end
159
+ end
160
+
161
+ module Brush::InputCallbackMixin
162
+ include Brush::CallbackMixin
163
+
164
+ public
165
+
166
+ def callback(symbol=nil, &block)
167
+ raise ArgumentError if symbol and block
168
+ block = @canvas.current_component.method(symbol) unless block
169
+ name(register_callback(:input, &block))
170
+ end
171
+ end
172
+
173
+ module Brush::ActionCallbackMixin
174
+ include Brush::CallbackMixin
175
+
176
+ public
177
+
178
+ def callback(symbol=nil, &block)
179
+ raise ArgumentError if symbol and block
180
+ block = @canvas.current_component.method(symbol) unless block
181
+ name(register_callback(:action, &block))
182
+ end
183
+ end
184
+
185
+ # The callback id is listed in the URL (not as a form-data field)
186
+ module Brush::ActionURLCallbackMixin
187
+ include Brush::CallbackMixin
188
+
189
+ public
190
+
191
+ def callback(symbol=nil, &block)
192
+ raise ArgumentError if symbol and block
193
+ block = @canvas.current_component.method(symbol) unless block
194
+ req = @canvas.rendering_context.request
195
+ url = req.build_url(req.request_handler_id, req.page_id, register_callback(:action, &block))
196
+ __set_url(url)
197
+ end
198
+ end
199
+
200
+ class Brush::TextAreaTag < Brush::GenericTagBrush
201
+ include Brush::InputCallbackMixin
202
+
203
+ def initialize
204
+ super('textarea')
205
+ end
206
+
207
+ %w(name rows cols tabindex accesskey onfocus onblur onselect onchange).each do |meth|
208
+ eval %[
209
+ def #{ meth }(arg)
210
+ @attributes['#{ meth }'] = arg
211
+ self
212
+ end
213
+ ]
214
+ end
215
+
216
+ def disabled
217
+ @attributes['disabled'] = nil
218
+ self
219
+ end
220
+
221
+ def readonly
222
+ @attributes['readonly'] = nil
223
+ self
224
+ end
225
+
226
+ def with(*args, &block)
227
+ super
228
+ end
229
+ end
230
+
231
+ class Brush::SelectOptionTag < Brush::GenericTagBrush
232
+ def initialize
233
+ super('option')
234
+ end
235
+
236
+ def selected(bool=true)
237
+ if bool
238
+ @attributes['selected'] = nil
239
+ else
240
+ @attributes.delete('selected')
241
+ end
242
+ self
243
+ end
244
+ end
245
+
246
+ class Brush::SelectListTag < Brush::GenericTagBrush
247
+ include Brush::InputCallbackMixin
248
+
249
+ def initialize(items)
250
+ super('select')
251
+ @items = items
252
+ end
253
+
254
+ %w(selected items labels).each do |meth|
255
+ eval %[
256
+ def #{ meth }(arg)
257
+ @#{ meth } = arg
258
+ self
259
+ end
260
+ ]
261
+ end
262
+
263
+ def multiple
264
+ @multiple = true
265
+ @attributes['multiple'] = nil
266
+ self
267
+ end
268
+
269
+ alias __old_callback callback
270
+ private :__old_callback
271
+ def callback(symbol=nil, &block)
272
+ raise ArgumentError if symbol and block
273
+ block = @canvas.current_component.method(symbol) unless block
274
+
275
+ @callback = block
276
+ self
277
+ end
278
+
279
+ def with
280
+ @labels ||= @items.collect { |i| i.to_s }
281
+ @selected ||= Array.new
282
+
283
+ if @callback
284
+ __old_callback {|input|
285
+ choosen = input.list.map {|idx|
286
+ idx = Integer(idx)
287
+ raise "invalid index in select list" if idx < 0 or idx > @items.size
288
+ @items[idx]
289
+ }
290
+ raise "choosen more than one element from a non-multiple select list" if not @multiple and choosen.size > 1
291
+ @callback.call(choosen)
292
+ }
293
+ end
294
+
295
+ super do
296
+ @items.each_index do |i|
297
+ @canvas.option.value(i).selected(@selected.include?(@items[i])).with(@labels[i])
298
+ end
299
+ @canvas.text("")
300
+ end
301
+ end
302
+ end
303
+
304
+ class Brush::TextInputTag < Brush::InputTag
305
+ include Brush::InputCallbackMixin
306
+
307
+ def initialize
308
+ super
309
+ type('text')
310
+ end
311
+ end
312
+
313
+ class Brush::SubmitButtonTag < Brush::InputTag
314
+ include Brush::ActionCallbackMixin
315
+
316
+ def initialize
317
+ super
318
+ type('submit')
319
+ end
320
+ end
321
+
322
+ # NOTE: The form-fields returned by a image-button-tag is browser-specific.
323
+ # Most browsers do not send the "name" key together with the value specified by
324
+ # "value", only "name.x" and "name.y". This conforms to the standard. But
325
+ # Firefox also sends "name"="value". This is why I raise an exception from the
326
+ # #value method. Note that it's neccessary to parse the passed form-fields and
327
+ # generate a "name" fields in the request, to make this image-button work.
328
+
329
+ class Wee::Brush::ImageButtonTag < Wee::Brush::InputTag
330
+ include Wee::Brush::ActionCallbackMixin
331
+
332
+ def initialize
333
+ super
334
+ type('image')
335
+ end
336
+
337
+ def value(v)
338
+ raise "specified value will not be used in the request"
339
+ end
340
+ end
341
+
342
+ class Brush::TableDataTag < Brush::GenericTagBrush
343
+ def initialize
344
+ super('td')
345
+ end
346
+
347
+ def align_top
348
+ @attributes['align'] = 'top'
349
+ self
350
+ end
351
+ end
352
+
353
+ class Brush::TableHeaderTag < Brush::GenericTagBrush
354
+ def initialize
355
+ super('th')
356
+ end
357
+ end
358
+
359
+
360
+ class Brush::FormTag < Brush::GenericTagBrush
361
+ include Brush::ActionURLCallbackMixin
362
+
363
+ def initialize
364
+ super('form')
365
+ @attributes['method'] = 'POST'
366
+ end
367
+
368
+ def action(href)
369
+ @attributes['action'] = href
370
+ self
371
+ end
372
+
373
+ alias __set_url action
374
+
375
+ def with(*args, &block)
376
+ # If no action was specified, use a dummy one.
377
+ unless @attributes.has_key?('action')
378
+ req = @canvas.rendering_context.request
379
+ @attributes['action'] = req.build_url(req.request_handler_id, req.page_id)
380
+ end
381
+ super
382
+ end
383
+ end
384
+
385
+ class Brush::AnchorTag < Brush::GenericTagBrush
386
+ include Brush::ActionURLCallbackMixin
387
+
388
+ def initialize
389
+ super('a')
390
+ end
391
+
392
+ def url(href)
393
+ @attributes['href'] = href
394
+ self
395
+ end
396
+ alias href url
397
+
398
+ alias __set_url url
399
+ end
400
+
401
+
402
+ class Brush::Page < Brush
403
+ def title(str)
404
+ @title = str
405
+ self
406
+ end
407
+
408
+ def with(text=nil, &block)
409
+ doc = @canvas.document
410
+ doc.start_tag("html")
411
+
412
+ if @title
413
+ doc.start_tag("head")
414
+ doc.start_tag("title")
415
+ doc.text(@title)
416
+ doc.end_tag("title")
417
+ doc.end_tag("head")
418
+ end
419
+
420
+ doc.start_tag("body")
421
+
422
+ if text
423
+ doc.text(text)
424
+ super(text, &block)
425
+ else
426
+ super(&block)
427
+ end
428
+
429
+ doc.end_tag("body")
430
+ doc.end_tag("html")
431
+ nil
432
+ end
433
+ end
434
+
435
+ end # module Wee