wee 0.1.0 → 0.3.1

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 (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
@@ -1,22 +0,0 @@
1
- class Wee::Delegate
2
- attr_accessor :next # next decoration in chain
3
-
4
- def initialize(component)
5
- @component = component
6
- end
7
-
8
- def process_request(context)
9
- @component.decoration.process_request(context)
10
- end
11
-
12
- # Creates a new renderer for this component and renders it.
13
- def render_with_context(rendering_context)
14
- r = renderer_class.new(rendering_context)
15
- r.current_component = self
16
- r.render(@component)
17
- end
18
-
19
- def renderer_class
20
- Wee::HtmlCanvas
21
- end
22
- end
@@ -1,89 +0,0 @@
1
- class Wee::ActionHandler
2
- attr_accessor :obj, :meth, :args
3
-
4
- def self.[](obj, meth, *args)
5
- new(obj, meth, *args)
6
- end
7
-
8
- def initialize(obj, meth, *args)
9
- @obj, @meth, @args = obj, meth.to_s, args
10
- end
11
-
12
- def invoke
13
- @obj.send(@meth, *@args)
14
- end
15
- end
16
-
17
- class Wee::ResourceHandler
18
- attr_accessor :content, :content_type
19
- def initialize(content, content_type)
20
- @content, @content_type = content, content_type
21
- end
22
- end
23
-
24
- class Wee::HandlerRegistry
25
- def initialize
26
- @next_handler_id = 1
27
- @action_registry = Hash.new
28
- @input_registry = Hash.new
29
- @resource_registry = Hash.new
30
- end
31
-
32
- def handler_id_for_action(action_handler)
33
- hid = get_next_handler_id()
34
- raise if @action_registry.has_key?(hid)
35
- @action_registry[hid] = action_handler
36
- return hid
37
- end
38
-
39
- def handler_id_for_input(obj, input)
40
- hid = get_next_handler_id()
41
- raise if @input_registry.has_key?(hid)
42
- @input_registry[hid] = [obj, input.to_s]
43
- return hid
44
- end
45
-
46
- def handler_id_for_resource(resource)
47
- hid = get_next_handler_id()
48
- raise if @resource_registry.has_key?(hid)
49
- @resource_registry[hid] = resource
50
- return hid
51
- end
52
-
53
- def get_action(handler_id, obj)
54
- action_handler = @action_registry[handler_id]
55
- return nil unless action_handler
56
-
57
- if action_handler.obj == obj
58
- action_handler
59
- else
60
- nil
61
- end
62
- end
63
-
64
- def get_input(handler_id, obj)
65
- return nil unless @input_registry.has_key?(handler_id)
66
-
67
- component, input = @input_registry[handler_id]
68
-
69
- if component == obj
70
- input
71
- else
72
- nil
73
- end
74
- end
75
-
76
- def get_resource(handler_id)
77
- return @resource_registry[handler_id]
78
- end
79
-
80
- private
81
-
82
- # TODO: randomize
83
- def get_next_handler_id
84
- @next_handler_id.to_s
85
- ensure
86
- @next_handler_id += 1
87
- end
88
-
89
- end
data/lib/wee/holder.rb DELETED
@@ -1,14 +0,0 @@
1
- class Wee::ValueHolder
2
- attr_accessor :value
3
-
4
- def initialize(value=nil)
5
- @value = value
6
- end
7
- end
8
-
9
- class Wee::StateHolder < Wee::ValueHolder
10
- def initialize(value)
11
- super
12
- Wee::Session.current.state_registry << self
13
- end
14
- end
@@ -1,379 +0,0 @@
1
- module Wee
2
-
3
- class Canvas
4
- def initialize
5
- @parent_brush = nil
6
- @current_brush = nil
7
- end
8
-
9
- def set_brush(brush)
10
- # tell previous brush to finish
11
- @current_brush.close if @current_brush
12
-
13
- brush.parent = @parent_brush
14
- brush.canvas = self
15
- @current_brush = brush
16
-
17
- return brush
18
- end
19
-
20
- def nest(&block)
21
- @parent_brush = @current_brush
22
- @current_brush = nil
23
- block.call
24
- @current_brush.close if @current_brush
25
- @parent_brush = @parent_brush.parent
26
- end
27
- end
28
-
29
- class HtmlCanvas < Canvas
30
- attr_reader :context # the current Wee::RenderingContext
31
- attr_reader :document
32
- attr_accessor :current_component
33
-
34
- def initialize(rendering_context)
35
- @context = rendering_context
36
- @document = rendering_context.document
37
- end
38
-
39
- def table(*args, &block)
40
- handle(Brush::TableTag.new, *args, &block)
41
- end
42
-
43
- def table_row(*args, &block)
44
- handle(Brush::TableRowTag.new, *args, &block)
45
- end
46
-
47
- def table_data(*args, &block)
48
- handle(Brush::TableDataTag.new, *args, &block)
49
- end
50
-
51
- def table_header(*args, &block)
52
- handle(Brush::TableHeaderTag.new, *args, &block)
53
- end
54
-
55
- def form(*args, &block)
56
- handle(Brush::FormTag.new, *args, &block)
57
- end
58
-
59
- def input(*args, &block)
60
- handle(Brush::InputTag.new, *args, &block)
61
- end
62
-
63
- def text_input(*args, &block)
64
- handle(Brush::TextInputTag.new, *args, &block)
65
- end
66
-
67
- def submit_button(*args, &block)
68
- handle(Brush::SubmitButtonTag.new, *args, &block)
69
- end
70
-
71
- def page(*args, &block)
72
- handle(Brush::Page.new, *args, &block)
73
- end
74
-
75
- def anchor(*args, &block)
76
- handle(Brush::AnchorTag.new, *args, &block)
77
- end
78
-
79
- def space(n=1)
80
- set_brush(Brush::GenericTextBrush.new("&nbsp;"*n))
81
- end
82
-
83
- def break
84
- set_brush(Brush::GenericTagBrush.new("br"))
85
- end
86
-
87
- def image
88
- set_brush(Brush::GenericTagBrush.new("img"))
89
- end
90
-
91
- def text(str)
92
- set_brush(Brush::GenericTextBrush.new(str))
93
- end
94
- alias << text
95
-
96
- def render(obj)
97
- obj.render_on(self)
98
- nil
99
- end
100
-
101
- private
102
-
103
- def handle(brush, *args, &block)
104
- set_brush(brush)
105
- if not args.empty? or block
106
- brush.with(*args, &block)
107
- else
108
- brush
109
- end
110
- end
111
- end
112
-
113
- class Brush
114
- attr_accessor :parent, :canvas
115
-
116
- def with(*args, &block)
117
- raise "either args or block, but not both" if block and not args.empty?
118
-
119
- @canvas.nest(&block) if block
120
- @closed = true
121
- end
122
-
123
- def close
124
- with unless @closed
125
- end
126
- end
127
-
128
- class Brush::GenericTextBrush < Brush
129
- def initialize(text)
130
- @text = text
131
- end
132
-
133
- def with
134
- doc = @canvas.document
135
- doc << @text
136
- super
137
- nil
138
- end
139
- end
140
-
141
- class Brush::GenericTagBrush < Brush
142
- def initialize(tag)
143
- @tag = tag
144
- @attributes = Hash.new
145
- end
146
-
147
- def id(x)
148
- @attributes["id"] = x
149
- self
150
- end
151
-
152
- def method_missing(m, arg)
153
- @attributes[m.to_s] = arg.to_s
154
- self
155
- end
156
-
157
- def with(text=nil, &block)
158
- doc = @canvas.document
159
- doc.start_tag(@tag, @attributes)
160
- if text
161
- doc.text(text)
162
- super(text, &block)
163
- else
164
- super(&block)
165
- end
166
- doc.end_tag(@tag)
167
- nil
168
- end
169
- end
170
-
171
- class Brush::TableTag < Brush::GenericTagBrush
172
- def initialize
173
- super('table')
174
- end
175
- end
176
-
177
- class Brush::TableRowTag < Brush::GenericTagBrush
178
- def initialize
179
- super('tr')
180
- end
181
-
182
- def align_top
183
- @attributes['align'] = 'top'
184
- self
185
- end
186
-
187
- def columns(*cols)
188
- with {
189
- cols.each {|col| @canvas.table_data(col) }
190
- }
191
- end
192
-
193
- def headings(*headers)
194
- with {
195
- headers.each {|head| @canvas.table_heading(head) }
196
- }
197
- end
198
-
199
- def spanning_column(str, colspan)
200
- with {
201
- @canvas.table_data.col_span(colspan).with(str)
202
- }
203
- end
204
-
205
- def spacer
206
- with {
207
- @canvas.table_data { @canvas.space }
208
- }
209
- end
210
- end
211
-
212
-
213
- class Brush::InputTag < Brush::GenericTagBrush
214
- def initialize
215
- super('input')
216
- end
217
-
218
- %w(type name value size maxlength checked src).each do |meth|
219
- eval %[
220
- def #{ meth }(arg)
221
- @attributes['#{ meth }'] = arg
222
- self
223
- end
224
- ]
225
- end
226
-
227
- def with
228
- super
229
- end
230
- end
231
-
232
- class Brush::TextInputTag < Brush::InputTag
233
- def initialize
234
- super
235
- type('text')
236
- end
237
-
238
- def attr(attr_name)
239
- assign(attr_name.to_s + "=")
240
- value(@canvas.current_component.send(attr_name))
241
- self
242
- end
243
-
244
- def assign(act, obj=nil)
245
- ctx = @canvas.context.context
246
- obj ||= @canvas.current_component
247
-
248
- name(ctx.handler_registry.handler_id_for_input(obj, act))
249
- end
250
- end
251
-
252
- class Brush::SubmitButtonTag < Brush::InputTag
253
- def initialize
254
- super
255
- type('submit')
256
- end
257
-
258
- # TODO: action for another object
259
- def action(act, *args)
260
- ctx = @canvas.context.context
261
- obj = @canvas.current_component
262
-
263
- name(ctx.handler_registry.handler_id_for_action(Wee::ActionHandler[obj, act, *args]))
264
- end
265
- end
266
-
267
- class Brush::TableDataTag < Brush::GenericTagBrush
268
- def initialize
269
- super('td')
270
- end
271
-
272
- def align_top
273
- @attributes['align'] = 'top'
274
- self
275
- end
276
- end
277
-
278
- class Brush::TableHeaderTag < Brush::GenericTagBrush
279
- def initialize
280
- super('th')
281
- end
282
- end
283
-
284
- module Brush::ActionMixin
285
- # TODO: action for another object
286
- def action(act, *args)
287
- ctx = @canvas.context.context
288
- obj = @canvas.current_component
289
- href = ctx.application.gen_handler_url(ctx.session_id, ctx.page_id,
290
- act ? ctx.handler_registry.handler_id_for_action(Wee::ActionHandler[obj, act, *args]) : '')
291
- __action(href)
292
- end
293
- end
294
-
295
- class Brush::FormTag < Brush::GenericTagBrush
296
- include Brush::ActionMixin
297
-
298
- def initialize
299
- super('form')
300
- @attributes['method'] = 'POST'
301
- end
302
-
303
- def __action(href)
304
- @attributes['action'] = href
305
- self
306
- end
307
-
308
- def with(*args, &block)
309
- action(nil) unless @attributes.has_key?('action')
310
- super
311
- end
312
- end
313
-
314
- class Brush::AnchorTag < Brush::GenericTagBrush
315
- include Brush::ActionMixin
316
-
317
- def initialize
318
- super('a')
319
- end
320
-
321
- def url(href)
322
- @attributes['href'] = href
323
- self
324
- end
325
-
326
- alias __action url
327
- end
328
-
329
-
330
- class Brush::Page < Brush
331
- def title(str)
332
- @title = str
333
- self
334
- end
335
-
336
- def with(text=nil, &block)
337
- doc = @canvas.document
338
- doc.start_tag("html")
339
-
340
- if @title
341
- doc.start_tag("head")
342
- doc.start_tag("title")
343
- doc.text(@title)
344
- doc.end_tag("title")
345
- doc.end_tag("head")
346
- end
347
-
348
- doc.start_tag("body")
349
-
350
- if text
351
- doc.text(text)
352
- super(text, &block)
353
- else
354
- super(&block)
355
- end
356
-
357
- doc.end_tag("body")
358
- doc.end_tag("html")
359
- nil
360
- end
361
- end
362
-
363
- end # module Wee
364
-
365
- if __FILE__ == $0
366
- require 'html_writer'
367
-
368
- doc = Wee::HtmlWriter.new('')
369
- c = Wee::HtmlCanvas.new(nil, doc)
370
- c.form.url("foo").with {
371
- c.table {
372
- c.table_row.id("myrow").with {
373
- c.table_data.align_top.with("Hello world")
374
- }
375
- }
376
- c.space
377
- }
378
- puts doc.port
379
- end