wee 0.8.0 → 0.9.0

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 (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,73 @@
1
+ # Wee::ComponentRunner wraps a root component and provides methods that act on
2
+ # the components tree defined by the root component.
3
+
4
+ class Wee::ComponentRunner
5
+
6
+ # Values are parameters to method #process_callbacks_of
7
+
8
+ DEFAULT_CALLBACK_PROCESSING = [
9
+ # Invokes all specified input callbacks. NOTE: Input callbacks should never
10
+ # call other components!
11
+ [:input, true, false],
12
+
13
+ # Invokes the first found action callback. NOTE: Only the first action
14
+ # callback is invoked. Any other action callback is ignored.
15
+ [:action, false, true],
16
+
17
+ # Invoke live_update callback (NOTE: only the first is invoked).
18
+ [:live_update, false, true]
19
+ ]
20
+
21
+ attr_accessor :root_component
22
+
23
+ def initialize(root_component)
24
+ @root_component = root_component
25
+ @callback_processing = DEFAULT_CALLBACK_PROCESSING
26
+ end
27
+
28
+ # This method takes a snapshot from the current state of the root component
29
+ # and returns it.
30
+
31
+ def snapshot
32
+ @root_component.backtrack_state_chain(snap = Wee::Snapshot.new)
33
+ return snap.freeze
34
+ end
35
+
36
+ # Render the root component with the given rendering context.
37
+
38
+ def render(rendering_context)
39
+ @root_component.do_render_chain(rendering_context)
40
+ end
41
+
42
+ # This method triggers several tree traversals to process the callbacks of
43
+ # the root component.
44
+ #
45
+ # Returns nil or a Response object in case of a premature response.
46
+
47
+ def process_callbacks(callback_stream)
48
+ if callback_stream.all_of_type(:action).size > 1
49
+ raise "Not allowed to specify more than one action callback"
50
+ end
51
+
52
+ catch(:wee_abort_callback_processing) {
53
+ @callback_processing.each {|args| process_callbacks_of(callback_stream, *args) }
54
+ nil
55
+ }
56
+ end
57
+
58
+ protected
59
+
60
+ def process_callbacks_of(callback_stream, type, pass_value=true, once=false)
61
+ @root_component.process_callbacks_chain {|this|
62
+ callback_stream.with_callbacks_for(this, type) { |callback, value|
63
+ if pass_value
64
+ callback.call(value)
65
+ else
66
+ callback.call
67
+ end
68
+ return if once
69
+ }
70
+ }
71
+ end
72
+
73
+ end
@@ -0,0 +1,27 @@
1
+ class Wee::Context
2
+ attr_accessor :request, :response, :session
3
+
4
+ def initialize(request=nil, response=nil, session=nil)
5
+ @request, @response, @session = request, response, session
6
+ end
7
+ end
8
+
9
+ class Wee::RenderingContext
10
+ attr_accessor :context, :callbacks, :document
11
+
12
+ def initialize(context=nil, callbacks=nil, document=nil)
13
+ @context, @callbacks, @document = context, callbacks, document
14
+ end
15
+
16
+ def request
17
+ @context.request
18
+ end
19
+
20
+ def response
21
+ @context.response
22
+ end
23
+
24
+ def session
25
+ @context.session
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ class Wee::IdGenerator
2
+ def next
3
+ raise "subclass responsibility"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ class Wee::Page < Struct.new(:snapshot, :callbacks); end
@@ -37,10 +37,10 @@ class Wee::Presenter
37
37
  protected
38
38
 
39
39
  # Returns the current renderer object for use by the render methods.
40
- def renderer() @renderer end
40
+ def renderer() @__renderer end
41
41
 
42
42
  # Short cut for #renderer.
43
- def r() @renderer end
43
+ def r() @__renderer end
44
44
 
45
45
  # Creates a new renderer object of the class returned by method
46
46
  # #renderer_class, then makes this the current renderer for the time the
@@ -48,23 +48,23 @@ class Wee::Presenter
48
48
  # the former one and closes the newly created renderer.
49
49
 
50
50
  def with_renderer_for(rendering_context)
51
- renderer = renderer_class.new(rendering_context)
52
- renderer.current_component = self
53
- old_renderer = @renderer
51
+ old_renderer = @__renderer
54
52
  begin
55
- @renderer = renderer
56
- yield
53
+ renderer_class.new(rendering_context, self) {|@__renderer| yield }
57
54
  ensure
58
- @renderer = old_renderer
59
- renderer.close # write outstanding brushes to the document
55
+ @__renderer = old_renderer
60
56
  end
61
57
  end
62
58
 
63
59
  # Returns the class used as renderer for this presenter. Overwrite this
64
60
  # method if you want to use a different renderer.
61
+ #
62
+ # Returned class must be a subclass of Wee::Renderer.
63
+ #
64
+ # NEEDS TO BE OVERWRITTEN by some non-core files.
65
65
 
66
66
  def renderer_class
67
- Wee::DefaultRenderer
67
+ raise "Method renderer_class needs to be implemented!"
68
68
  end
69
69
 
70
70
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -97,120 +97,4 @@ class Wee::Presenter
97
97
  def backtrack_state(snapshot)
98
98
  end
99
99
 
100
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101
- # :section: Session
102
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103
-
104
- public
105
-
106
- # Returns the current session. A presenter (or component) has always an
107
- # associated session. The returned object is of class Wee::Session or a
108
- # subclass thereof.
109
-
110
- def session
111
- Wee::Session.current
112
- end
113
-
114
- # Send a premature response.
115
-
116
- protected
117
-
118
- def send_response(response)
119
- throw :wee_send_response, response
120
- end
121
-
122
- # Call the block inside a rendering environment, then send the response prematurely.
123
-
124
- def send_render_response(&block)
125
- # Generate a response
126
- response = Wee::GenericResponse.new('text/html', '')
127
-
128
- # Get the current context we are in
129
- context = session.current_context
130
-
131
- # A rendering context is needed to use 'r' (if you want, you can simply
132
- # omit this and just return the response with some html/xml filled in.
133
- rendering_context = Wee::RenderingContext.new(
134
- context.request,
135
- context.response,
136
- session.current_callbacks,
137
- Wee::HtmlWriter.new(response.content))
138
-
139
- with_renderer_for(rendering_context, &block)
140
-
141
- send_response(response)
142
- end
143
-
144
-
145
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
146
- # :section: Properties
147
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148
-
149
- public
150
-
151
- def properties() @__properties end
152
- def properties=(props) @__properties = props end
153
-
154
- # Returns an "owned" property.
155
-
156
- def get_property(prop)
157
- if self.properties
158
- self.properties[prop]
159
- else
160
- nil
161
- end
162
- end
163
-
164
- # Tries to lookup a property from different places. +nil+ as property value
165
- # is not allowed!
166
- #
167
- # Search order:
168
- #
169
- # 1. self.get_property(prop)
170
- #
171
- # 2. session.get_property(prop, self.class)
172
- #
173
- # 3. application.get_property(prop, self.class)
174
- #
175
- # 4. session.get_property(prop, nil)
176
- #
177
- # 5. application.get_property(prop, nil)
178
- #
179
- # 6. @@properties[prop]
180
- #
181
-
182
- def lookup_property(prop)
183
- val = get_property(prop)
184
- return val if val != nil
185
-
186
- sess = session()
187
- app = sess.application
188
- klass = self.class
189
-
190
- val = sess.get_property(prop, klass)
191
- return val if val != nil
192
-
193
- val = app.get_property(prop, klass)
194
- return val if val != nil
195
-
196
- val = sess.get_property(prop, nil)
197
- return val if val != nil
198
-
199
- val = app.get_property(prop, nil)
200
- return val if val != nil
201
-
202
- if defined?(@@properties)
203
- val = @@properties[prop]
204
- return val if val != nil
205
- end
206
-
207
- return nil
208
- end
209
-
210
- # This is currently only used for describing which properties are required by
211
- # the underlying component.
212
-
213
- def self.uses_property(*args)
214
- end
215
-
216
100
  end
@@ -0,0 +1,23 @@
1
+ # Base class of all Renderer classes.
2
+
3
+ class Wee::Renderer
4
+ attr_reader :rendering_context # holds the current Wee::RenderingContext
5
+ attr_accessor :current_component
6
+
7
+ def initialize(rendering_context, current_component=nil, &block)
8
+ @rendering_context = rendering_context
9
+ @current_component = current_component
10
+ if block
11
+ begin
12
+ block.call(self)
13
+ ensure
14
+ close
15
+ end
16
+ end
17
+ end
18
+
19
+ # Subclass responsibility.
20
+
21
+ def close
22
+ end
23
+ end
@@ -0,0 +1,122 @@
1
+ class Wee::Presenter
2
+
3
+ def renderer_class
4
+ Wee::DefaultRenderer
5
+ end
6
+
7
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8
+ # :section: Session
9
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10
+
11
+ public
12
+
13
+ # Returns the current session. A presenter (or component) has always an
14
+ # associated session. The returned object is of class Wee::Session or a
15
+ # subclass thereof.
16
+
17
+ def session
18
+ Wee::Session.current
19
+ end
20
+
21
+ # Send a premature response.
22
+
23
+ protected
24
+
25
+ def send_response(response)
26
+ throw :wee_abort_callback_processing, response
27
+ end
28
+
29
+ # Call the block inside a rendering environment, then send the response prematurely.
30
+
31
+ def send_render_response(&block)
32
+ # Generate a response
33
+ response = Wee::GenericResponse.new('text/html', '')
34
+
35
+ # Get the current context we are in
36
+ context = session.current_context
37
+
38
+ # A rendering context is needed to use 'r' (if you want, you can simply
39
+ # omit this and just return the response with some html/xml filled in.
40
+ rendering_context = Wee::RenderingContext.new(
41
+ context,
42
+ session.current_callbacks,
43
+ Wee::HtmlWriter.new(response.content))
44
+
45
+ with_renderer_for(rendering_context, &block)
46
+
47
+ send_response(response)
48
+ end
49
+
50
+
51
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52
+ # :section: Properties
53
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54
+
55
+ public
56
+
57
+ def properties() @__properties end
58
+ def properties=(props) @__properties = props end
59
+
60
+ # Returns an "owned" property.
61
+
62
+ def get_property(prop)
63
+ if self.properties
64
+ self.properties[prop]
65
+ else
66
+ nil
67
+ end
68
+ end
69
+
70
+ # Tries to lookup a property from different places. +nil+ as property value
71
+ # is not allowed!
72
+ #
73
+ # Search order:
74
+ #
75
+ # 1. self.get_property(prop)
76
+ #
77
+ # 2. session.get_property(prop, self.class)
78
+ #
79
+ # 3. application.get_property(prop, self.class)
80
+ #
81
+ # 4. session.get_property(prop, nil)
82
+ #
83
+ # 5. application.get_property(prop, nil)
84
+ #
85
+ # 6. @@properties[prop]
86
+ #
87
+
88
+ def lookup_property(prop)
89
+ val = get_property(prop)
90
+ return val if val != nil
91
+
92
+ sess = session()
93
+ app = sess.application
94
+ klass = self.class
95
+
96
+ val = sess.get_property(prop, klass)
97
+ return val if val != nil
98
+
99
+ val = app.get_property(prop, klass)
100
+ return val if val != nil
101
+
102
+ val = sess.get_property(prop, nil)
103
+ return val if val != nil
104
+
105
+ val = app.get_property(prop, nil)
106
+ return val if val != nil
107
+
108
+ if defined?(@@properties)
109
+ val = @@properties[prop]
110
+ return val if val != nil
111
+ end
112
+
113
+ return nil
114
+ end
115
+
116
+ # This is currently only used for describing which properties are required by
117
+ # the underlying component.
118
+
119
+ def self.uses_property(*args)
120
+ end
121
+
122
+ end
@@ -164,7 +164,6 @@ class OgScaffolder::Editor < Wee::Component
164
164
  r.select_list((1..31).to_a).selected(t.day).callback {|day| set_date_of(prop, day, :day) }
165
165
  end
166
166
 
167
-
168
167
  def render_buttons
169
168
  r.paragraph
170
169
  r.submit_button.value('Save').callback(:save)
@@ -0,0 +1,70 @@
1
+ # NEEDS: FormDecoration
2
+
3
+ class Wee::Examples::Calculator < Wee::Component
4
+ def initialize
5
+ super()
6
+
7
+ @number_stack = []
8
+ @input = ""
9
+ end
10
+
11
+ def render
12
+ # the number stack
13
+
14
+ r.ul { @number_stack.each {|num| r.li(num)} }
15
+
16
+ # the display
17
+
18
+ r.text_input.value(@input).readonly
19
+
20
+ r.space
21
+
22
+ r.submit_button.value("Enter").callback(:enter)
23
+
24
+ r.submit_button.value("C").callback(:clear)
25
+
26
+ r.break
27
+
28
+ # the number buttons
29
+
30
+ (0..9).each {|num|
31
+ r.submit_button.value(num).callback(:append, num.to_s)
32
+ }
33
+
34
+ # the decimal point
35
+
36
+ r.submit_button.value(".").disabled(@input.include?(".")).callback(:append, '.')
37
+
38
+ # binary operators
39
+
40
+ ['+', '-', '*', '/'].each { |op|
41
+ r.submit_button.value(op).callback(:operation, op)
42
+ }
43
+ end
44
+
45
+ def enter
46
+ @number_stack << @input.to_f
47
+ @input = ""
48
+ end
49
+
50
+ def clear
51
+ @input = ""
52
+ end
53
+
54
+ def append(str)
55
+ @input << str
56
+ end
57
+
58
+ def operation(op)
59
+ unless @input.empty?
60
+ @number_stack << @input.to_f
61
+ @input = ""
62
+ end
63
+ if @number_stack.size < 2
64
+ call Wee::MessageBox.new('Stack underflow!')
65
+ else
66
+ r2, r1 = @number_stack.pop, @number_stack.pop
67
+ @number_stack.push(r1.send(op, r2))
68
+ end
69
+ end
70
+ end