wee 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/ChangeLog +286 -0
  2. data/Features +185 -0
  3. data/doc/rdoc/classes/ActionView.html +107 -0
  4. data/doc/rdoc/classes/ActionView/Base.html +133 -0
  5. data/doc/rdoc/classes/Array.html +7 -59
  6. data/doc/rdoc/classes/Cache/StorageCache.html +38 -38
  7. data/doc/rdoc/classes/Cache/Strategy/CapacityBounded.html +30 -30
  8. data/doc/rdoc/classes/Cache/Strategy/LFU.html +24 -24
  9. data/doc/rdoc/classes/Cache/Strategy/LRU.html +24 -24
  10. data/doc/rdoc/classes/Cache/Strategy/Unbounded.html +24 -24
  11. data/doc/rdoc/classes/Enumerable.html +6 -6
  12. data/doc/rdoc/classes/Hash.html +120 -0
  13. data/doc/rdoc/classes/Main.html +58 -34
  14. data/doc/rdoc/classes/Object.html +12 -12
  15. data/doc/rdoc/classes/OgScaffolder.html +165 -166
  16. data/doc/rdoc/classes/OgScaffolder/Editor.html +112 -112
  17. data/doc/rdoc/classes/String.html +7 -59
  18. data/doc/rdoc/classes/Struct.html +14 -14
  19. data/doc/rdoc/classes/Wee.html +70 -6
  20. data/doc/rdoc/classes/Wee/AbstractSession.html +502 -0
  21. data/doc/rdoc/classes/Wee/AnswerDecoration.html +11 -11
  22. data/doc/rdoc/classes/Wee/Application.html +139 -84
  23. data/doc/rdoc/classes/Wee/Brush.html +21 -18
  24. data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +90 -17
  25. data/doc/rdoc/classes/Wee/Brush/CheckboxTag.html +162 -0
  26. data/doc/rdoc/classes/Wee/Brush/FileUploadTag.html +7 -7
  27. data/doc/rdoc/classes/Wee/Brush/FormTag.html +41 -17
  28. data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +12 -12
  29. data/doc/rdoc/classes/Wee/Brush/GenericSingleTagBrush.html +7 -7
  30. data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +112 -86
  31. data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +12 -12
  32. data/doc/rdoc/classes/Wee/Brush/HiddenInputTag.html +160 -0
  33. data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +15 -15
  34. data/doc/rdoc/classes/Wee/Brush/ImageTag.html +21 -21
  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/RadioButtonTag.html +234 -0
  39. data/doc/rdoc/classes/Wee/Brush/RadioButtonTag/RadioGroup.html +207 -0
  40. data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +124 -28
  41. data/doc/rdoc/classes/Wee/Brush/SelectListTag/SelectListCallback.html +7 -7
  42. data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +7 -7
  43. data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +7 -7
  44. data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +14 -14
  45. data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +7 -7
  46. data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +42 -42
  47. data/doc/rdoc/classes/Wee/Brush/TableTag.html +7 -7
  48. data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +48 -15
  49. data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +7 -7
  50. data/doc/rdoc/classes/Wee/CallbackRegistry.html +38 -38
  51. data/doc/rdoc/classes/Wee/CallbackStream.html +18 -18
  52. data/doc/rdoc/classes/Wee/CanvasMixin.html +225 -0
  53. data/doc/rdoc/classes/Wee/Component.html +202 -201
  54. data/doc/rdoc/classes/Wee/Component/OnAnswer.html +7 -7
  55. data/doc/rdoc/classes/Wee/ComponentDispatcher.html +289 -0
  56. data/doc/rdoc/classes/Wee/ComponentRunner.html +321 -0
  57. data/doc/rdoc/classes/Wee/Context.html +63 -3
  58. data/doc/rdoc/classes/Wee/Decoration.html +45 -45
  59. data/doc/rdoc/classes/Wee/Delegate.html +30 -30
  60. data/doc/rdoc/classes/Wee/DupReplaceSnapshotMixin.html +164 -0
  61. data/doc/rdoc/classes/Wee/ErrorResponse.html +16 -16
  62. data/doc/rdoc/classes/Wee/Examples.html +114 -0
  63. data/doc/rdoc/classes/Wee/Examples/Calculator.html +319 -0
  64. data/doc/rdoc/classes/Wee/Examples/Counter.html +289 -0
  65. data/doc/rdoc/classes/Wee/Examples/EditableCounter.html +210 -0
  66. data/doc/rdoc/classes/Wee/Examples/Window.html +346 -0
  67. data/doc/rdoc/classes/Wee/FastCGIAdaptor.html +227 -0
  68. data/doc/rdoc/classes/Wee/FormDecoration.html +6 -6
  69. data/doc/rdoc/classes/Wee/GenericResponse.html +7 -7
  70. data/doc/rdoc/classes/Wee/HtmlCanvasRenderer.html +1230 -0
  71. data/doc/rdoc/classes/Wee/HtmlWriter.html +40 -40
  72. data/doc/rdoc/classes/Wee/IdGenerator.html +148 -0
  73. data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +27 -14
  74. data/doc/rdoc/classes/Wee/LoginDecoration.html +261 -0
  75. data/doc/rdoc/classes/Wee/Md5IdGenerator.html +14 -14
  76. data/doc/rdoc/classes/Wee/MessageBox.html +14 -14
  77. data/doc/rdoc/classes/Wee/Nitro.html +114 -0
  78. data/doc/rdoc/classes/Wee/Nitro/ControllerClassMixin.html +192 -0
  79. data/doc/rdoc/classes/Wee/Nitro/ControllerMixin.html +345 -0
  80. data/doc/rdoc/classes/Wee/Nitro/FormTag.html +155 -0
  81. data/doc/rdoc/classes/Wee/Nitro/HtmlCanvasRenderer.html +178 -0
  82. data/doc/rdoc/classes/Wee/Page.html +4 -0
  83. data/doc/rdoc/classes/Wee/PageDecoration.html +18 -18
  84. data/doc/rdoc/classes/Wee/PagelessApplication.html +13 -11
  85. data/doc/rdoc/classes/Wee/PagelessComponentDriver.html +296 -0
  86. data/doc/rdoc/classes/Wee/PagelessRequest.html +52 -21
  87. data/doc/rdoc/classes/Wee/PagelessSession.html +130 -91
  88. data/doc/rdoc/classes/Wee/Pager.html +534 -0
  89. data/doc/rdoc/classes/Wee/Presenter.html +482 -298
  90. data/doc/rdoc/classes/Wee/Rails.html +114 -0
  91. data/doc/rdoc/classes/Wee/Rails/ControllerClassMixin.html +192 -0
  92. data/doc/rdoc/classes/Wee/Rails/ControllerMixin.html +342 -0
  93. data/doc/rdoc/classes/Wee/Rails/FormTag.html +155 -0
  94. data/doc/rdoc/classes/Wee/Rails/HtmlCanvasRenderer.html +177 -0
  95. data/doc/rdoc/classes/Wee/RedirectResponse.html +7 -7
  96. data/doc/rdoc/classes/Wee/RefreshResponse.html +7 -7
  97. data/doc/rdoc/classes/Wee/Renderer.html +208 -0
  98. data/doc/rdoc/classes/Wee/RenderingContext.html +175 -3
  99. data/doc/rdoc/classes/Wee/Request.html +197 -46
  100. data/doc/rdoc/classes/Wee/RequestHandler.html +31 -31
  101. data/doc/rdoc/classes/Wee/Response.html +44 -43
  102. data/doc/rdoc/classes/Wee/Session.html +296 -402
  103. data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +14 -14
  104. data/doc/rdoc/classes/Wee/Snapshot.html +19 -19
  105. data/doc/rdoc/classes/Wee/Utils.html +22 -22
  106. data/doc/rdoc/classes/Wee/Utils/LRUCache.html +6 -6
  107. data/doc/rdoc/classes/Wee/ValueHolder.html +19 -19
  108. data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +72 -46
  109. data/doc/rdoc/classes/Wee/WrapperDecoration.html +6 -6
  110. data/doc/rdoc/created.rid +1 -1
  111. data/doc/rdoc/files/INSTALL.html +1 -1
  112. data/doc/rdoc/files/README.html +8 -12
  113. data/doc/rdoc/files/lib/cache/cache_rb.html +1 -1
  114. data/doc/rdoc/files/lib/wee/abstractsession_rb.html +108 -0
  115. data/doc/rdoc/files/lib/wee/adaptors/fastcgi_rb.html +108 -0
  116. data/doc/rdoc/files/lib/wee/adaptors/nitro_rb.html +101 -0
  117. data/doc/rdoc/files/lib/wee/adaptors/rails_rb.html +101 -0
  118. data/doc/rdoc/files/lib/wee/adaptors/webrick_rb.html +1 -1
  119. data/doc/rdoc/files/lib/wee/application_rb.html +1 -1
  120. data/doc/rdoc/files/lib/wee/components/component_dispatcher_rb.html +108 -0
  121. data/doc/rdoc/files/lib/wee/components/form_decoration_rb.html +1 -1
  122. data/doc/rdoc/files/lib/wee/components/login_decoration_rb.html +101 -0
  123. data/doc/rdoc/files/lib/wee/components/messagebox_rb.html +1 -1
  124. data/doc/rdoc/files/lib/wee/components/page_decoration_rb.html +1 -1
  125. data/doc/rdoc/files/lib/wee/components/pager_rb.html +101 -0
  126. data/doc/rdoc/files/lib/wee/components/wrapper_decoration_rb.html +1 -1
  127. data/doc/rdoc/files/lib/wee/components_rb.html +4 -1
  128. data/doc/rdoc/files/lib/wee/continuation/core/component_rb.html +1 -1
  129. data/doc/rdoc/files/lib/wee/continuation/session_rb.html +1 -1
  130. data/doc/rdoc/files/lib/wee/continuation_rb.html +1 -1
  131. data/doc/rdoc/files/lib/wee/core/callback_rb.html +1 -1
  132. data/doc/rdoc/files/lib/wee/core/component_rb.html +1 -1
  133. data/doc/rdoc/files/lib/wee/core/componentrunner_rb.html +110 -0
  134. data/doc/rdoc/files/lib/wee/core/context_rb.html +101 -0
  135. data/doc/rdoc/files/lib/wee/core/decoration_rb.html +1 -1
  136. data/doc/rdoc/files/lib/wee/core/idgen_rb.html +101 -0
  137. data/doc/rdoc/files/lib/wee/core/page_rb.html +101 -0
  138. data/doc/rdoc/files/lib/wee/core/presenter_rb.html +1 -1
  139. data/doc/rdoc/files/lib/wee/core/renderer_rb.html +107 -0
  140. data/doc/rdoc/files/lib/wee/core/snapshot_rb.html +1 -1
  141. data/doc/rdoc/files/lib/wee/core/valueholder_rb.html +2 -2
  142. data/doc/rdoc/files/lib/wee/core_ext_rb.html +101 -0
  143. data/doc/rdoc/files/lib/wee/core_rb.html +7 -14
  144. data/doc/rdoc/files/lib/wee/databases/og/application_rb.html +1 -1
  145. data/doc/rdoc/files/lib/wee/databases/og/old_scaffolder_rb.html +1 -1
  146. data/doc/rdoc/files/lib/wee/databases/og/scaffolder_rb.html +1 -1
  147. data/doc/rdoc/files/lib/wee/databases/og/session_rb.html +1 -1
  148. data/doc/rdoc/files/lib/wee/databases/og_rb.html +1 -1
  149. data/doc/rdoc/files/lib/wee/examples/calculator_rb.html +107 -0
  150. data/doc/rdoc/files/lib/wee/examples/counter_rb.html +101 -0
  151. data/doc/rdoc/files/lib/wee/examples/editable_counter_rb.html +114 -0
  152. data/doc/rdoc/files/lib/wee/examples/window_rb.html +101 -0
  153. data/doc/rdoc/files/lib/wee/idgen/md5_rb.html +1 -1
  154. data/doc/rdoc/files/lib/wee/idgen/simple_rb.html +1 -1
  155. data/doc/rdoc/files/lib/wee/page_rb.html +1 -1
  156. data/doc/rdoc/files/lib/wee/pageless/application_rb.html +8 -1
  157. data/doc/rdoc/files/lib/wee/pageless/request_rb.html +1 -1
  158. data/doc/rdoc/files/lib/wee/pageless/session_rb.html +2 -1
  159. data/doc/rdoc/files/lib/wee/pageless_rb.html +1 -1
  160. data/doc/rdoc/files/lib/wee/renderer/html/brushes_rb.html +1 -1
  161. data/doc/rdoc/files/lib/wee/renderer/html/canvas_rb.html +1 -1
  162. data/doc/rdoc/files/lib/wee/renderer/html/writer_rb.html +1 -1
  163. data/doc/rdoc/files/lib/wee/request_rb.html +5 -4
  164. data/doc/rdoc/files/lib/wee/requesthandler_rb.html +1 -1
  165. data/doc/rdoc/files/lib/wee/response_rb.html +2 -1
  166. data/doc/rdoc/files/lib/wee/session_rb.html +2 -3
  167. data/doc/rdoc/files/lib/wee/skeleton/og/components/main_rb.html +1 -1
  168. data/doc/rdoc/files/lib/wee/skeleton/og/conf/db_rb.html +2 -2
  169. data/doc/rdoc/files/lib/wee/skeleton/og/models/recipe_rb.html +1 -1
  170. data/doc/rdoc/files/lib/wee/skeleton/og/run_rb.html +1 -1
  171. data/doc/rdoc/files/lib/wee/skeleton/simple/components/main_rb.html +1 -1
  172. data/doc/rdoc/files/lib/wee/skeleton/simple/run_rb.html +1 -1
  173. data/doc/rdoc/files/lib/wee/snapshot_ext_rb.html +1 -1
  174. data/doc/rdoc/files/lib/wee/template_rb.html +1 -1
  175. data/doc/rdoc/files/lib/wee/utils/autoreload_rb.html +1 -1
  176. data/doc/rdoc/files/lib/wee/utils/cache_rb.html +1 -1
  177. data/doc/rdoc/files/lib/wee/utils/helper_rb.html +1 -1
  178. data/doc/rdoc/files/lib/wee/utils_rb.html +1 -1
  179. data/doc/rdoc/files/lib/wee_rb.html +5 -3
  180. data/doc/rdoc/fr_class_index.html +34 -2
  181. data/doc/rdoc/fr_file_index.html +17 -1
  182. data/doc/rdoc/fr_method_index.html +464 -314
  183. data/examples/ajax/ajax.rb +1 -1
  184. data/examples/demo.rb +47 -0
  185. data/examples/{calendar.rb → demo/calendar.rb} +89 -97
  186. data/examples/{example.rb → demo/example.rb} +17 -97
  187. data/examples/dispatcher.rb +37 -0
  188. data/examples/draw.rb +14 -11
  189. data/examples/nitro/run.rb +42 -0
  190. data/examples/radio.rb +44 -0
  191. data/examples/test.rb +3 -27
  192. data/lib/wee.rb +15 -3
  193. data/lib/wee/adaptors/nitro.rb +154 -0
  194. data/lib/wee/adaptors/rails.rb +154 -0
  195. data/lib/wee/application.rb +22 -20
  196. data/lib/wee/components.rb +3 -0
  197. data/lib/wee/components/component_dispatcher.rb +46 -0
  198. data/lib/wee/components/login_decoration.rb +35 -0
  199. data/lib/wee/components/messagebox.rb +2 -2
  200. data/lib/wee/components/pager.rb +102 -0
  201. data/lib/wee/continuation/core/component.rb +13 -12
  202. data/lib/wee/continuation/session.rb +11 -19
  203. data/lib/wee/core.rb +8 -7
  204. data/lib/wee/core/component.rb +8 -28
  205. data/lib/wee/core/componentrunner.rb +73 -0
  206. data/lib/wee/core/context.rb +27 -0
  207. data/lib/wee/core/idgen.rb +5 -0
  208. data/lib/wee/core/page.rb +1 -0
  209. data/lib/wee/core/presenter.rb +10 -126
  210. data/lib/wee/core/renderer.rb +23 -0
  211. data/lib/wee/core_ext.rb +122 -0
  212. data/lib/wee/databases/og/scaffolder.rb +0 -1
  213. data/lib/wee/examples/calculator.rb +70 -0
  214. data/lib/wee/examples/counter.rb +33 -0
  215. data/lib/wee/examples/editable_counter.rb +31 -0
  216. data/{examples → lib/wee/examples}/window.rb +29 -23
  217. data/lib/wee/idgen/md5.rb +1 -1
  218. data/lib/wee/idgen/simple.rb +1 -1
  219. data/lib/wee/pageless/session.rb +2 -3
  220. data/lib/wee/renderer/html/brushes.rb +142 -22
  221. data/lib/wee/renderer/html/canvas.rb +57 -19
  222. data/lib/wee/response.rb +3 -2
  223. data/lib/wee/session.rb +10 -54
  224. data/lib/wee/skeleton/og/components/main.rb +5 -1
  225. data/lib/wee/skeleton/og/conf/db.rb +1 -1
  226. data/lib/wee/snapshot_ext.rb +4 -10
  227. data/lib/wee/template.rb +19 -5
  228. data/lib/wee/utils/helper.rb +2 -2
  229. metadata +90 -13
  230. data/examples/calculator.rb +0 -67
  231. data/lib/wee/context.rb +0 -2
@@ -0,0 +1,33 @@
1
+ class Wee::Examples::Counter < Wee::Component
2
+ attr_accessor :count
3
+
4
+ def initialize(initial_count=0)
5
+ super()
6
+ @count = initial_count
7
+ end
8
+
9
+ def backtrack_state(snap)
10
+ super
11
+ snap.add(self)
12
+ end
13
+
14
+ def dec
15
+ @count -= 1
16
+ end
17
+
18
+ def inc
19
+ @count += 1
20
+ end
21
+
22
+ def render
23
+ r.anchor.callback(:dec).with("--")
24
+ r.space
25
+ render_count
26
+ r.space
27
+ r.anchor.callback(:inc).with("++")
28
+ end
29
+
30
+ def render_count
31
+ r.text @count.to_s
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ # NEEDS: FormDecoration
2
+
3
+ require 'wee/examples/counter'
4
+
5
+ class Wee::Examples::EditableCounter < Wee::Examples::Counter
6
+
7
+ def initialize(initial_count=0)
8
+ super
9
+ @show_edit_field = false
10
+ end
11
+
12
+ def render_count
13
+ if @show_edit_field
14
+ r.text_input.callback(:count=).value(@count).size(6)
15
+ r.submit_button.callback(:submit).value('S')
16
+ else
17
+ r.anchor.callback(:submit).with(@count)
18
+ end
19
+ end
20
+
21
+ def submit
22
+ if @count.to_s !~ /^\d+$/
23
+ call Wee::MessageBox.new("You entered an invalid counter! Please try again!")
24
+ @count = 0
25
+ else
26
+ @show_edit_field = !@show_edit_field
27
+ end
28
+ @count = @count.to_i
29
+ end
30
+
31
+ end
@@ -1,12 +1,16 @@
1
- class Wee::Window < Wee::Component
1
+ class Wee::Examples::Window < Wee::Component
2
2
 
3
- def initialize(title, pos, child)
3
+ attr_accessor :title, :pos_x, :pos_y, :child
4
+
5
+ def initialize(&block)
4
6
  super()
5
- @title = title
6
- @child = child
7
7
  @status = :normal
8
- self.children << @child
9
- @pos = pos
8
+ @pos_x, @pos_y = "0px", "0px"
9
+ block.call(self) if block
10
+ end
11
+
12
+ def children
13
+ [@child].uniq
10
14
  end
11
15
 
12
16
  def process_callbacks(&block)
@@ -14,40 +18,42 @@ class Wee::Window < Wee::Component
14
18
  super
15
19
  end
16
20
 
17
- def minimize
18
- @status = :minimized
19
- end
20
-
21
- def maximize
22
- @status = :normal
23
- end
24
-
25
- def close
26
- @status = :closed
27
- end
28
-
29
21
  def render
30
22
  return if @status == :closed
31
23
 
32
- r.table.cellspacing(0).style("border:solid 1px grey; position: relative; top: #{@pos}; left: #{200+@pos.to_i}").with do
24
+ r.table.cellspacing(0).style("border:solid 1px grey; position: absolute; left: #{@pos_x}; top: #{@pos_y};").with do
33
25
  r.table_row.style("background-color: lightblue; width: 100%").with do
34
26
  r.table_data.style("text-align: left; width: 66%").with(@title)
35
27
  r.table_data.style("text-align: right").with do
36
28
  if @status == :minimized
37
- r.anchor.callback{maximize}.with("#")
29
+ r.anchor.callback(:maximize).with("^")
38
30
  else
39
- r.anchor.callback{minimize}.with("_")
31
+ r.anchor.callback(:minimize).with("_")
40
32
  end
41
33
  r.space
42
- r.anchor.callback{close}.with("X")
34
+ r.anchor.callback(:close).with("x")
43
35
  end
44
36
  end
45
37
  r.table_row do
46
38
  r.table_data.colspan(2).with do
47
- r.render(@child) if @status == :normal
39
+ r.render(@child) if @child and @status == :normal
48
40
  end
49
41
  end
50
42
  end
51
43
  end
52
44
 
45
+ public
46
+
47
+ def minimize
48
+ @status = :minimized
49
+ end
50
+
51
+ def maximize
52
+ @status = :normal
53
+ end
54
+
55
+ def close
56
+ @status = :closed
57
+ end
58
+
53
59
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'digest/md5'
5
5
 
6
- class Wee::Md5IdGenerator
6
+ class Wee::Md5IdGenerator < Wee::IdGenerator
7
7
  def initialize(salt='wee')
8
8
  @salt = salt
9
9
  end
@@ -1,6 +1,6 @@
1
1
  # Returned ids are guaranteed to be unique, but they are easily guessable.
2
2
 
3
- class Wee::SimpleIdGenerator
3
+ class Wee::SimpleIdGenerator < Wee::IdGenerator
4
4
  def initialize(initial_value=0)
5
5
  @value = initial_value
6
6
  end
@@ -5,7 +5,6 @@ require 'cgi'
5
5
  # backtrack.
6
6
 
7
7
  class Wee::PagelessSession < Wee::Session
8
- attr_accessor :root_component
9
8
  undef page_store
10
9
 
11
10
  attr_accessor :callbacks
@@ -14,7 +13,7 @@ class Wee::PagelessSession < Wee::Session
14
13
  def setup(&block)
15
14
  with_session do
16
15
  block.call(self) if block
17
- raise ArgumentError, "No root component specified" if @root_component.nil?
16
+ raise ArgumentError, "No component runner specified" if @component_runner.nil?
18
17
  end
19
18
  end
20
19
 
@@ -47,7 +46,7 @@ class Wee::PagelessSession < Wee::Session
47
46
  # new page view.
48
47
 
49
48
  callback_stream = Wee::CallbackStream.new(self.callbacks, @context.request.fields)
50
- send_response = invoke_callbacks(callback_stream)
49
+ send_response = @component_runner.process_callbacks(callback_stream)
51
50
 
52
51
  post_callbacks_hook()
53
52
 
@@ -154,7 +154,7 @@ class Brush::GenericTagBrush < Brush
154
154
  def onclick_update(update_id, symbol=nil, *args, &block)
155
155
  raise ArgumentError if symbol and block
156
156
  url = @canvas.url_for_callback(to_callback(symbol, args, block))
157
- onclick("javascript: new Ajax.Updater('#{ update_id }', '#{ url }', {method:'get'});")
157
+ onclick("javascript: new Ajax.Updater('#{ update_id }', '#{ url }', {method:'get'}); return false;")
158
158
  end
159
159
 
160
160
  # This method construct the css-class attribute by looking up the property
@@ -301,8 +301,21 @@ class Brush::TextAreaTag < Brush::GenericTagBrush
301
301
  html_attr :name, :rows, :cols, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange
302
302
  bool_attr :disabled, :readonly
303
303
 
304
+ def value(val)
305
+ @value = val
306
+ self
307
+ end
308
+
304
309
  def with(*args, &block)
305
- super
310
+ if @value
311
+ if block or !args.empty?
312
+ raise "please use either method 'value' or 'with'"
313
+ else
314
+ super(@value)
315
+ end
316
+ else
317
+ super
318
+ end
306
319
  end
307
320
  end
308
321
 
@@ -315,21 +328,36 @@ class Brush::SelectOptionTag < Brush::GenericTagBrush
315
328
  end
316
329
 
317
330
  class Brush::SelectListTag < Brush::GenericTagBrush
331
+
332
+ bool_attr :disabled, :readonly, :multiple
333
+ alias multi multiple
334
+
318
335
  def initialize(items)
319
336
  super('select')
320
337
  @items = items
321
338
  end
322
339
 
323
- %w(selected items labels).each do |meth|
324
- eval %[
325
- def #{ meth }(arg)
326
- @#{ meth } = arg
327
- self
328
- end
329
- ]
340
+ def items(arg)
341
+ @items = arg
342
+ self
330
343
  end
331
344
 
332
- bool_attr :multiple
345
+ def selected(arg=nil, &block)
346
+ raise if arg and block
347
+ @selected = arg || block
348
+ self
349
+ end
350
+
351
+ def labels(arg=nil, &block)
352
+ raise if arg and block
353
+
354
+ if block
355
+ @labels = proc{|i| block.call(@items[i])}
356
+ else
357
+ @labels = arg
358
+ end
359
+ self
360
+ end
333
361
 
334
362
  def callback(symbol=nil, *args, &block)
335
363
  @callback = to_callback(symbol, args, block)
@@ -367,20 +395,30 @@ class Brush::SelectListTag < Brush::GenericTagBrush
367
395
  end
368
396
 
369
397
  super do
370
- if is_multiple
398
+ meth =
399
+ if is_multiple
371
400
  @selected ||= Array.new
372
- @items.each_index {|i|
373
- @canvas.option.value(i).selected(@selected.include?(@items[i])).with(@labels[i])
374
- }
401
+ @selected.kind_of?(Proc) ? (:call) : (:include?)
375
402
  else
376
- @items.each_index {|i|
377
- @canvas.option.value(i).selected(@selected == @items[i]).with(@labels[i])
378
- }
403
+ @selected.kind_of?(Proc) ? (:call) : (:==)
379
404
  end
405
+
406
+ @items.each_index {|i|
407
+ @canvas.option.value(i).selected(@selected.send(meth, @items[i])).with(@labels[i])
408
+ }
380
409
  end
381
410
  end
382
411
  end
383
412
 
413
+ class Brush::HiddenInputTag < Brush::InputTag
414
+ def initialize
415
+ super
416
+ type('hidden')
417
+ end
418
+
419
+ alias callback __input_callback
420
+ end
421
+
384
422
  class Brush::TextInputTag < Brush::InputTag
385
423
  def initialize
386
424
  super
@@ -390,6 +428,64 @@ class Brush::TextInputTag < Brush::InputTag
390
428
  alias callback __input_callback
391
429
  end
392
430
 
431
+ class Brush::RadioButtonTag < Brush::InputTag
432
+ def initialize
433
+ super
434
+ type('radio')
435
+ end
436
+
437
+ class RadioGroup
438
+ def initialize(canvas)
439
+ @name = canvas.register_callback(:input, self)
440
+ @callbacks = {}
441
+ @ids = Wee::SimpleIdGenerator.new
442
+ end
443
+
444
+ def add_callback(callback)
445
+ value = @ids.next.to_s
446
+ @callbacks[value] = callback
447
+ return [@name, value]
448
+ end
449
+
450
+ def call(value)
451
+ if @callbacks.has_key?(value)
452
+ cb = @callbacks[value]
453
+ cb.call(value) if cb
454
+ else
455
+ raise "invalid radio button/group value"
456
+ end
457
+ end
458
+ end
459
+
460
+ def group(radio_group)
461
+ @group = radio_group
462
+ self
463
+ end
464
+
465
+ def callback(symbol=nil, *args, &block)
466
+ @callback = to_callback(symbol, args, block)
467
+ self
468
+ end
469
+
470
+ def with
471
+ if @group
472
+ n, v = @group.add_callback(@callback)
473
+ name(n)
474
+ value(v)
475
+ end
476
+ super
477
+ end
478
+
479
+ end
480
+
481
+ class Brush::CheckboxTag < Wee::Brush::InputTag
482
+ def initialize
483
+ super
484
+ type('checkbox')
485
+ end
486
+ alias callback __input_callback
487
+ end
488
+
393
489
  class Brush::FileUploadTag < Brush::InputTag
394
490
  def initialize
395
491
  super
@@ -456,12 +552,16 @@ class Brush::FormTag < Brush::GenericTagBrush
456
552
  alias callback __actionurl_callback
457
553
  alias named_callback __actionurl_named_callback
458
554
 
555
+ def onsubmit_update(update_id, symbol=nil, *args, &block)
556
+ raise ArgumentError if symbol and block
557
+ url = @canvas.url_for_callback(to_callback(symbol, args, block), :live_update)
558
+ onsubmit("javascript: new Ajax.Updater('#{ update_id }', '#{ url }', {method:'get', parameters: Form.serialize(this)}); return false;")
559
+ end
560
+
459
561
  def with(*args, &block)
460
562
  # If no action was specified, use a dummy one.
461
563
  unless @attributes.has_key?('action')
462
- req = @canvas.rendering_context.request
463
- # TODO?
464
- @attributes['action'] = req.build_url
564
+ @attributes['action'] = @canvas.build_url
465
565
  end
466
566
  super
467
567
  end
@@ -477,8 +577,28 @@ class Brush::AnchorTag < Brush::GenericTagBrush
477
577
  alias tooltip title
478
578
 
479
579
  alias __set_url url
480
- alias callback __actionurl_callback
481
- alias named_callback __actionurl_named_callback
580
+
581
+ def info(info=nil)
582
+ @info = info
583
+ self
584
+ end
585
+
586
+ def callback(symbol=nil, *args, &block)
587
+ if @info
588
+ __set_url(@canvas.url_for_callback(to_callback(symbol, args, block), :action, :info => @info))
589
+ else
590
+ __set_url(@canvas.url_for_callback(to_callback(symbol, args, block)))
591
+ end
592
+ end
593
+
594
+ def named_callback(name, symbol=nil, *args, &block)
595
+ if @info
596
+ __set_url(@canvas.url_for_named_callback(name, to_callback(symbol, args, block), :info => @info))
597
+ else
598
+ __set_url(@canvas.url_for_named_callback(name, to_callback(symbol, args, block)))
599
+ end
600
+ end
601
+
482
602
  end
483
603
 
484
604
  class Brush::Page < Brush
@@ -1,7 +1,7 @@
1
1
  module Wee
2
2
 
3
- class Canvas
4
- def initialize
3
+ module CanvasMixin
4
+ def initialize_canvas
5
5
  @parent_brush = nil
6
6
  @current_brush = nil
7
7
  end
@@ -31,10 +31,10 @@ class Canvas
31
31
  end
32
32
  end
33
33
 
34
- class HtmlCanvas < Canvas
35
- attr_reader :rendering_context # the current Wee::RenderingContext
34
+ class HtmlCanvasRenderer < Renderer
35
+ include CanvasMixin
36
+
36
37
  attr_reader :document
37
- attr_accessor :current_component
38
38
 
39
39
  def self.generic_tag(*attrs)
40
40
  attrs.each { |a|
@@ -56,28 +56,36 @@ class HtmlCanvas < Canvas
56
56
  }
57
57
  end
58
58
 
59
- def initialize(rendering_context)
60
- super()
61
- @rendering_context = rendering_context
62
- @document = rendering_context.document
59
+ def initialize(rendering_context, current_component=nil, &block)
60
+ # cache the document, to reduce method calls
61
+ @document = rendering_context.document
62
+
63
+ initialize_canvas
64
+ super
63
65
  end
64
66
 
65
67
  generic_tag :html, :head, :body, :title, :style, :h1, :h2, :h3, :h4, :h5, :div
66
68
  generic_tag :div, :span, :ul, :ol, :li
67
69
  generic_single_tag :link, :hr
68
70
 
69
- def url_for_callback(callback)
70
- url_for_callback_id(register_callback(:action, callback))
71
+ def url_for_callback(callback, type=:action, hash=nil)
72
+ url_for_callback_id(register_callback(type, callback), hash)
71
73
  end
72
74
 
73
- def url_for_named_callback(name, callback)
74
- url_for_callback_id(register_named_callback(name, :action, callback))
75
+ def url_for_named_callback(name, callback, hash=nil)
76
+ url_for_callback_id(register_named_callback(name, :action, callback), hash)
77
+ end
78
+
79
+ def url_for_callback_id(callback_id, hash=nil)
80
+ if hash
81
+ build_url(hash.update(:callback_id => callback_id))
82
+ else
83
+ build_url(:callback_id => callback_id)
84
+ end
75
85
  end
76
86
 
77
- def url_for_callback_id(callback_id)
78
- req = self.rendering_context.request
79
- url = req.build_url(:callback_id => callback_id)
80
- return url
87
+ def build_url(*args)
88
+ rendering_context.request.build_url(*args)
81
89
  end
82
90
 
83
91
  def register_callback(type, callback)
@@ -112,10 +120,28 @@ class HtmlCanvas < Canvas
112
120
  handle(Brush::InputTag.new, *args, &block)
113
121
  end
114
122
 
123
+ def hidden_input(*args, &block)
124
+ handle(Brush::HiddenInputTag.new, *args, &block)
125
+ end
126
+
115
127
  def text_input(*args, &block)
116
128
  handle(Brush::TextInputTag.new, *args, &block)
117
129
  end
118
130
 
131
+ def new_radio_group
132
+ Wee::Brush::RadioButtonTag::RadioGroup.new(self)
133
+ end
134
+
135
+ def radio_button(*args, &block)
136
+ handle(Brush::RadioButtonTag.new, *args, &block)
137
+ end
138
+
139
+ def check_box(*args, &block)
140
+ handle(Wee::Brush::CheckboxTag.new, *args, &block)
141
+ end
142
+
143
+ alias checkbox check_box
144
+
119
145
  def text_area(*args, &block)
120
146
  handle(Brush::TextAreaTag.new, *args, &block)
121
147
  end
@@ -160,8 +186,12 @@ class HtmlCanvas < Canvas
160
186
  handle(Brush::JavascriptTag.new, *args, &block)
161
187
  end
162
188
 
163
- def paragraph
164
- set_brush(Brush::GenericSingleTagBrush.new("p"))
189
+ def paragraph(*args, &block)
190
+ handle(Brush::GenericTagBrush.new("p"), *args, &block)
191
+ end
192
+
193
+ def label(*args, &block)
194
+ handle(Brush::GenericTagBrush.new("label"), *args, &block)
165
195
  end
166
196
 
167
197
  def break
@@ -185,6 +215,14 @@ class HtmlCanvas < Canvas
185
215
  set_brush(Brush::GenericEncodedTextBrush.new(str))
186
216
  end
187
217
 
218
+ # converts \n into <br/>
219
+ def multiline_text(text, encode=true)
220
+ meth = encode ? :encode_text : :text
221
+ lines = text.split("\n")
222
+ send(meth, lines.first)
223
+ lines[1..-1].each { |l| self.break; send(meth, l) }
224
+ end
225
+
188
226
  def render(obj)
189
227
  self.close
190
228
  obj.do_render_chain(@rendering_context)