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,42 @@
1
+ require 'wee'
2
+ require 'wee/adaptors/nitro'
3
+ require 'wee/examples/calculator'
4
+ require 'wee/examples/window'
5
+
6
+ require 'rubygems'
7
+ require 'nitro'
8
+ require 'nitro/controller'
9
+
10
+ class MyComponent < Wee::Component
11
+ def initialize
12
+ super
13
+ add_decoration(Wee::FormDecoration.new)
14
+ add_decoration(Wee::PageDecoration.new('Hello from Wee/Nitro!'))
15
+
16
+ @windows = (0..2).map {|i|
17
+ Wee::Examples::Window.new {|w|
18
+ w.title = 'Calculator'
19
+ w.pos_y = (i*200).to_s + "px"
20
+ w.child = Wee::Examples::Calculator.new
21
+ }
22
+ }
23
+ end
24
+
25
+ def children
26
+ @windows
27
+ end
28
+
29
+ def render
30
+ @windows.each {|window| r.render window}
31
+ end
32
+ end
33
+
34
+ class AppController < Nitro::Controller
35
+ include Wee::Nitro::ControllerMixin
36
+
37
+ scaffold_with_component do
38
+ MyComponent.new
39
+ end
40
+ end
41
+
42
+ Nitro.run(:host => '127.0.0.1', :port => 9999, :dispatcher => Nitro::Dispatcher.new('/app' => AppController))
@@ -0,0 +1,44 @@
1
+ require 'wee'
2
+ require 'wee/adaptors/webrick'
3
+ require 'wee/utils'
4
+
5
+ class RadioTest < Wee::Component
6
+ def initialize
7
+ super
8
+ add_decoration(Wee::PageDecoration.new("Radio Test"))
9
+ end
10
+
11
+ def render
12
+ grp1 = r.new_radio_group
13
+ grp2 = r.new_radio_group
14
+
15
+ r.form do
16
+ r.paragraph
17
+ r.text "Group1"
18
+ r.break
19
+
20
+ r.text "R1: "
21
+ r.radio_button.group(grp1).checked.callback { p "G1.R1" }
22
+ r.break
23
+
24
+ r.text "R2: "
25
+ r.radio_button.group(grp1).callback { p "G1.R2" }
26
+
27
+ r.paragraph
28
+ r.text "Group2"
29
+ r.break
30
+
31
+ r.text "R1: "
32
+ r.radio_button.group(grp2).checked.callback { p "G2.R1" }
33
+ r.break
34
+
35
+ r.text "R2: "
36
+ r.radio_button.group(grp2).callback { p "G2.R2" }
37
+
38
+ r.paragraph
39
+ r.submit_button.value('Submit')
40
+ end
41
+ end
42
+ end
43
+
44
+ Wee::WEBrickAdaptor.register('/app' => Wee::Utils.app_for(RadioTest)).start
@@ -1,36 +1,12 @@
1
+ #!/usr/bin/env ruby
1
2
  $LOAD_PATH.unshift << "../lib"
2
3
  require 'wee'
3
-
4
- class Counter < Wee::Component
5
- def initialize(cnt)
6
- super()
7
- @cnt = cnt
8
- end
9
-
10
- def backtrack_state(snap)
11
- super
12
- snap.add(self)
13
- end
14
-
15
- def dec
16
- @cnt -= 1
17
- end
18
-
19
- def inc
20
- @cnt += 1
21
- end
22
-
23
- def render
24
- r.anchor.callback(:dec).with("--")
25
- r.space; r.text(@cnt.to_s); r.space
26
- r.anchor.callback(:inc).with("++")
27
- end
28
- end
4
+ require 'wee/examples/counter'
29
5
 
30
6
  class MainPage < Wee::Component
31
7
  def initialize
32
8
  super
33
- @counters = (1..10).map {|i| Counter.new(i)}
9
+ @counters = (1..10).map {|i| Wee::Examples::Counter.new(i)}
34
10
  children.push(*@counters)
35
11
  end
36
12
 
data/lib/wee.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  module Wee
2
- Version = "0.8.0"
2
+ Version = "0.9.0"
3
3
  LibPath = File.dirname(__FILE__)
4
4
  end
5
5
 
6
+ module Wee::Examples; end
7
+
6
8
  require 'wee/core'
9
+ require 'wee/core_ext'
7
10
 
8
- require 'wee/context'
9
11
  require 'wee/application'
10
12
  require 'wee/requesthandler'
11
13
  require 'wee/request'
@@ -20,7 +22,17 @@ require 'wee/template'
20
22
  require 'wee/renderer/html/writer'
21
23
  require 'wee/renderer/html/brushes'
22
24
  require 'wee/renderer/html/canvas'
23
- Wee::DefaultRenderer = Wee::HtmlCanvas
25
+ Wee::DefaultRenderer = Wee::HtmlCanvasRenderer
24
26
 
25
27
  require 'wee/idgen/simple'
26
28
  require 'wee/idgen/md5'
29
+
30
+ def Wee.run(component, add_page_decoration=true, mount_path='/app')
31
+ require 'wee/utils'
32
+ require 'wee/adaptors/webrick'
33
+
34
+ component = component.new if component.kind_of?(Class)
35
+ component.add_decoration(Wee::PageDecoration.new('Welcome to Wee!')) if add_page_decoration
36
+ component.add_decoration(Wee::FormDecoration.new)
37
+ Wee::WEBrickAdaptor.register(mount_path => Wee::Utils.app_for { component }).start
38
+ end
@@ -0,0 +1,154 @@
1
+ class Wee::PagelessComponentDriver < Wee::ComponentRunner
2
+ attr_accessor :callbacks
3
+
4
+ def initialize(root_component, callbacks=nil)
5
+ super(root_component)
6
+ @callbacks = callbacks
7
+ @mutex = Mutex.new
8
+ end
9
+
10
+ def render(*args)
11
+ @mutex.synchronize { super }
12
+ end
13
+
14
+ def process_callbacks(*args)
15
+ @mutex.synchronize { super }
16
+ end
17
+ end
18
+
19
+ class Wee::Presenter
20
+ def renderer_class
21
+ Wee::Nitro::HtmlCanvasRenderer
22
+ end
23
+ end
24
+
25
+ class Wee::RenderingContext
26
+ attr_accessor :component_name
27
+ attr_accessor :controller
28
+ attr_accessor :redirect_action
29
+ end
30
+
31
+
32
+ module Wee::Nitro
33
+
34
+ class FormTag < Wee::Brush::FormTag
35
+ def with(*args, &block)
36
+ rctx = @canvas.rendering_context
37
+ controller = rctx.request.path.split('/').first
38
+
39
+ super(*args) do
40
+ block.call if block
41
+ @canvas.hidden_input.name('__c').value(rctx.component_name)
42
+ @canvas.hidden_input.name('__a').value(rctx.redirect_action) if rctx.redirect_action
43
+ end
44
+ end
45
+ end
46
+
47
+ class HtmlCanvasRenderer < Wee::HtmlCanvasRenderer
48
+ def form(*args, &block)
49
+ handle(Wee::Nitro::FormTag.new, *args, &block)
50
+ end
51
+
52
+ def build_url(hash={})
53
+ cid = hash[:callback_id]
54
+ controller = rendering_context.request.path.split('/').first
55
+ url = "/#{ controller }/callback"
56
+ url << "?__c=#{ rendering_context.component_name }"
57
+ url << "&__a=#{ rendering_context.redirect_action }" if rendering_context.redirect_action
58
+ url << "&#{ cid }" if cid
59
+ url
60
+ end
61
+ end
62
+
63
+ module ControllerClassMixin
64
+ def register_component(name, &block)
65
+ registered_components[name] = block
66
+ end
67
+
68
+ def registered_components
69
+ @@registered_components ||= Hash.new
70
+ end
71
+
72
+ def scaffold_with_component(name=nil, &block)
73
+ name ||= self.name
74
+ register_component(name, &block) if block
75
+ send(:define_method, :index) do
76
+ show_component name
77
+ end
78
+ end
79
+ end
80
+
81
+ module ControllerMixin
82
+
83
+ def self.included(klass)
84
+ klass.extend(ControllerClassMixin)
85
+ end
86
+
87
+ public
88
+
89
+ def callback
90
+ c = components[request.params['__c']]
91
+ raise "no component found" if c.nil?
92
+ callback_stream = Wee::CallbackStream.new(c.callbacks, request.params)
93
+ c.process_callbacks(callback_stream)
94
+
95
+ controller = request.path.split('/').first
96
+ action = request.params['__a'] || 'index'
97
+ redirect [controller, action].join("/")
98
+ end
99
+
100
+ protected
101
+
102
+ def make_component(name, obj)
103
+ if components.has_key?(name)
104
+ raise "disallowed to overwrite component #{ name }"
105
+ else
106
+ components[name] = Wee::PagelessComponentDriver.new(obj, Wee::CallbackRegistry.new(Wee::SimpleIdGenerator.new))
107
+ end
108
+ end
109
+
110
+ def drop_component(name)
111
+ if components.has_key?(name)
112
+ components.delete(name)
113
+ else
114
+ raise "component #{ name } not found"
115
+ end
116
+ end
117
+
118
+ def has_component?(name)
119
+ components.has_key?(name)
120
+ end
121
+
122
+ def _show_component(name, hash={}, out='')
123
+ cb = Wee::CallbackRegistry.new(Wee::SimpleIdGenerator.new)
124
+ ctx = Wee::Context.new(request(), response(), session())
125
+ rctx = Wee::RenderingContext.new(ctx, cb, Wee::HtmlWriter.new(out))
126
+ rctx.component_name = name
127
+ rctx.controller = self
128
+ rctx.redirect_action = hash[:redirect_action]
129
+
130
+ unless c = components[name]
131
+ if block = self.class.registered_components[name]
132
+ make_component name, block.call
133
+ c = components[name]
134
+ end
135
+ end
136
+
137
+ raise "component #{ name } not found" if c.nil?
138
+
139
+ c.render(rctx)
140
+ c.callbacks = cb
141
+ out
142
+ end
143
+
144
+ def show_component(name, hash={})
145
+ _show_component(name, hash, @out)
146
+ end
147
+
148
+ def components
149
+ session[:COMPONENTS] ||= Hash.new
150
+ end
151
+
152
+ end
153
+
154
+ end # module Wee::Nitro
@@ -0,0 +1,154 @@
1
+ class Wee::PagelessComponentDriver < Wee::ComponentRunner
2
+ attr_accessor :callbacks
3
+
4
+ def initialize(root_component, callbacks=nil)
5
+ super(root_component)
6
+ @callbacks = callbacks
7
+ @mutex = Mutex.new
8
+ end
9
+
10
+ def render(*args)
11
+ @mutex.synchronize { super }
12
+ end
13
+
14
+ def process_callbacks(*args)
15
+ @mutex.synchronize { super }
16
+ end
17
+ end
18
+
19
+ class Wee::Presenter
20
+ def renderer_class
21
+ Wee::Rails::HtmlCanvasRenderer
22
+ end
23
+ end
24
+
25
+ class Wee::RenderingContext
26
+ attr_accessor :component_name
27
+ attr_accessor :controller
28
+ attr_accessor :redirect_action
29
+ end
30
+
31
+ module Wee::Rails
32
+
33
+ class FormTag < Wee::Brush::FormTag
34
+ def with(*args, &block)
35
+ rctx = @canvas.rendering_context
36
+ controller = rctx.request.path.split('/').first
37
+
38
+ super(*args) do
39
+ block.call if block
40
+ @canvas.hidden_input.name('__c').value(rctx.component_name)
41
+ @canvas.hidden_input.name('__a').value(rctx.redirect_action) if rctx.redirect_action
42
+ end
43
+ end
44
+ end
45
+
46
+ class HtmlCanvasRenderer < Wee::HtmlCanvasRenderer
47
+ def form(*args, &block)
48
+ handle(Wee::Rails::FormTag.new, *args, &block)
49
+ end
50
+
51
+ def build_url(hash={})
52
+ cid = hash[:callback_id]
53
+ url = rendering_context.controller.url_for :action => 'callback'
54
+ url << "?__c=#{ rendering_context.component_name }"
55
+ url << "&__a=#{ rendering_context.redirect_action }" if rendering_context.redirect_action
56
+ url << "&#{ cid }" if cid
57
+ url
58
+ end
59
+ end
60
+
61
+ module ControllerClassMixin
62
+ def register_component(name, &block)
63
+ registered_components[name] = block
64
+ end
65
+
66
+ def registered_components
67
+ @@registered_components ||= Hash.new
68
+ end
69
+
70
+ def scaffold_with_component(name=nil, &block)
71
+ name ||= self.name
72
+ register_component(name, &block) if block
73
+ send(:define_method, :index) do
74
+ show_component name
75
+ end
76
+ end
77
+ end
78
+
79
+ module ControllerMixin
80
+
81
+ def self.included(klass)
82
+ klass.extend(ControllerClassMixin)
83
+ end
84
+
85
+ public
86
+
87
+ def callback
88
+ c = components[@params['__c']]
89
+ raise "no component found" if c.nil?
90
+ callback_stream = Wee::CallbackStream.new(c.callbacks, @params)
91
+ c.process_callbacks(callback_stream)
92
+ redirect_to :action => (@params['__a'] || "index")
93
+ end
94
+
95
+ protected
96
+
97
+ def make_component(name, obj)
98
+ if components.has_key?(name)
99
+ raise "disallowed to overwrite component #{ name }"
100
+ else
101
+ components[name] = Wee::PagelessComponentDriver.new(obj, Wee::CallbackRegistry.new(Wee::SimpleIdGenerator.new))
102
+ end
103
+ end
104
+
105
+ def drop_component(name)
106
+ if components.has_key?(name)
107
+ components.delete(name)
108
+ else
109
+ raise "component #{ name } not found"
110
+ end
111
+ end
112
+
113
+ def has_component?(name)
114
+ components.has_key?(name)
115
+ end
116
+
117
+ def _show_component(name, hash={}, out='')
118
+ cb = Wee::CallbackRegistry.new(Wee::SimpleIdGenerator.new)
119
+ ctx = Wee::Context.new(@request, @response, @session)
120
+ rctx = Wee::RenderingContext.new(ctx, cb, Wee::HtmlWriter.new(out))
121
+ rctx.component_name = name
122
+ rctx.controller = self
123
+ rctx.redirect_action = hash[:redirect_action]
124
+
125
+ unless c = components[name]
126
+ if block = self.class.registered_components[name]
127
+ make_component name, block.call
128
+ c = components[name]
129
+ end
130
+ end
131
+
132
+ raise "component #{ name } not found" if c.nil?
133
+
134
+ c.render(rctx)
135
+ c.callbacks = cb
136
+ out
137
+ end
138
+
139
+ def show_component(name, hash={})
140
+ render_text(_show_component(name, hash))
141
+ end
142
+
143
+ def components
144
+ @session[:COMPONENTS] ||= Hash.new
145
+ end
146
+
147
+ end
148
+
149
+ end # module Wee::Rails
150
+
151
+ class ActionView::Base
152
+ include Wee::Rails::ControllerMixin
153
+ alias show_component _show_component
154
+ end