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
@@ -57,26 +57,9 @@ class Wee::Application
57
57
  # No id was given -> check whether the maximum number of request-handlers
58
58
  # limit is reached. if not, create new id and handler
59
59
 
60
- @mutex.synchronize {
61
- if @max_request_handlers != nil and @request_handlers.size >= @max_request_handlers
62
- # limit reached -> remove non-alive handlers...
63
- garbage_collect_handlers()
64
-
65
- # ...and test again
66
- if @request_handlers.size >= @max_request_handlers
67
- # TODO: show a custom error message
68
- raise "maximum number of request-handlers reached"
69
- end
70
- end
71
-
72
- request_handler_id = unique_request_handler_id()
73
- request_handler = @default_request_handler.call
74
- request_handler.id = request_handler_id
75
- request_handler.application = self
76
- @request_handlers[request_handler_id] = request_handler
77
- }
78
-
79
- context.request.request_handler_id = request_handler_id
60
+ request_handler = @default_request_handler.call
61
+ insert_new_request_handler(request_handler)
62
+ context.request.request_handler_id = request_handler.id
80
63
  handle_request(context)
81
64
  return
82
65
 
@@ -103,6 +86,25 @@ class Wee::Application
103
86
  context.response = Wee::ErrorResponse.new(exn)
104
87
  end
105
88
 
89
+ def insert_new_request_handler(request_handler)
90
+ @mutex.synchronize {
91
+ if @max_request_handlers != nil and @request_handlers.size >= @max_request_handlers
92
+ # limit reached -> remove non-alive handlers...
93
+ garbage_collect_handlers()
94
+
95
+ # ...and test again
96
+ if @request_handlers.size >= @max_request_handlers
97
+ # TODO: show a custom error message
98
+ raise "maximum number of request-handlers reached"
99
+ end
100
+ end
101
+
102
+ request_handler.id = unique_request_handler_id()
103
+ request_handler.application = self
104
+ @request_handlers[request_handler.id] = request_handler
105
+ }
106
+ end
107
+
106
108
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107
109
  # :section: Properties
108
110
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -2,3 +2,6 @@ require 'wee/components/wrapper_decoration'
2
2
  require 'wee/components/form_decoration'
3
3
  require 'wee/components/page_decoration'
4
4
  require 'wee/components/messagebox'
5
+ require 'wee/components/component_dispatcher'
6
+ require 'wee/components/login_decoration'
7
+ require 'wee/components/pager'
@@ -0,0 +1,46 @@
1
+ require 'set'
2
+
3
+ class Wee::ComponentDispatcher < Wee::Component
4
+ def initialize
5
+ super()
6
+ @rules = []
7
+ @components = Set.new
8
+ end
9
+
10
+ def add_rule(pattern, component, &block)
11
+ @components.add(component)
12
+ @rules << [pattern, component, block]
13
+ end
14
+
15
+ def do_render(rendering_context)
16
+ if component = match(session.current_context.request.info)
17
+ component.do_render_chain(rendering_context)
18
+ end
19
+ end
20
+
21
+ def process_callbacks(&block)
22
+ if component = match(session.current_context.request.info)
23
+ component.process_callbacks_chain(&block)
24
+ end
25
+ end
26
+
27
+ def backtrack_state(snapshot)
28
+ snapshot.add(@__decoration)
29
+ @components.each do |component|
30
+ component.backtrack_state_chain(snapshot)
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ def match(info)
37
+ info ||= ""
38
+ @rules.each do |pattern, component, block|
39
+ if info =~ pattern
40
+ block.call(component, $~) if block
41
+ return component
42
+ end
43
+ end
44
+ nil
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ class Wee::LoginDecoration < Wee::Decoration
2
+ def initialize(login_page)
3
+ @login_page = login_page
4
+ end
5
+
6
+ def process_callbacks(&block)
7
+ if logged_in?
8
+ super
9
+ else
10
+ @login_page.process_callbacks_chain(&block)
11
+ end
12
+ end
13
+
14
+ def do_render(rendering_context)
15
+ if logged_in?
16
+ super
17
+ else
18
+ @login_page.do_render_chain(rendering_context)
19
+ end
20
+ end
21
+
22
+ def backtrack_state(snapshot)
23
+ if logged_in?
24
+ super
25
+ else
26
+ @login_page.backtrack_state_chain(snapshot)
27
+ end
28
+ end
29
+
30
+ # Overwrite this method!
31
+
32
+ def logged_in?
33
+ raise "subclass responsibility"
34
+ end
35
+ end
@@ -7,9 +7,9 @@ class Wee::MessageBox < Wee::Component
7
7
  def render
8
8
  r.bold(@text)
9
9
  r.form do
10
- r.submit_button.value('OK').callback { answer true }
10
+ r.submit_button.value('OK').callback(:answer, true)
11
11
  r.space
12
- r.submit_button.value('Cancel').callback { answer false }
12
+ r.submit_button.value('Cancel').callback(:answer, false)
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,102 @@
1
+ class Wee::Pager < Wee::Component
2
+ attr_accessor :num_entries, :entries_per_page
3
+ attr_reader :current_page
4
+
5
+ def initialize(num_entries=0)
6
+ super()
7
+ @num_entries = num_entries
8
+ @current_page = 0
9
+ @entries_per_page = 20
10
+ yield self if block_given?
11
+ end
12
+
13
+ # Returns the number of pages
14
+
15
+ def num_pages
16
+ n, rest = @num_entries.divmod(@entries_per_page)
17
+ if rest > 0 then n + 1 else n end
18
+ end
19
+
20
+ # Returns the index of the first entry on the current page
21
+
22
+ def current_start_index
23
+ @current_page * @entries_per_page
24
+ end
25
+
26
+ # Returns the index of the last page
27
+
28
+ def last_page_index
29
+ num_pages() - 1
30
+ end
31
+
32
+ # Go to first page
33
+
34
+ def first
35
+ goto(0)
36
+ end
37
+
38
+ # Go to last page
39
+
40
+ def last
41
+ goto(last_page_index())
42
+ end
43
+
44
+ # Go to previous page
45
+
46
+ def prev
47
+ goto(@current_page - 1)
48
+ end
49
+
50
+ # Go to next page
51
+
52
+ def next
53
+ goto(@current_page + 1)
54
+ end
55
+
56
+ # Go to page with index +page+
57
+ # Note that page-indices start with zero!
58
+
59
+ def goto(page)
60
+ @current_page = page
61
+ validate
62
+ end
63
+
64
+ def render
65
+ return if num_pages() <= 0
66
+ render_arrow(:first, "<<", "Go to first page"); r.space(2)
67
+ render_arrow(:prev, "<", "Go to previous page"); r.space(2)
68
+ render_index; r.space(2)
69
+ render_arrow(:next, ">", "Go to next page"); r.space(2)
70
+ render_arrow(:last, ">>", "Go to last page")
71
+ end
72
+
73
+ private
74
+
75
+ def render_arrow(sym, text, tooltip=text)
76
+ r.anchor.callback(sym).tooltip(tooltip).with { r.encode_text(text) }
77
+ end
78
+
79
+ def render_index
80
+ last = last_page_index()
81
+ (0 .. last).each do |i|
82
+ if i == @current_page
83
+ render_page_num(i, true)
84
+ else
85
+ render_page_num(i, false)
86
+ end
87
+ r.space if i < last
88
+ end
89
+ end
90
+
91
+ def render_page_num(num, current)
92
+ if current
93
+ r.bold(num+1)
94
+ else
95
+ r.anchor.callback(:goto, num).with(num+1)
96
+ end
97
+ end
98
+
99
+ def validate
100
+ @current_page = [[0, @current_page].max, last_page_index()].min
101
+ end
102
+ end
@@ -20,18 +20,19 @@ class Wee::Component
20
20
  # +on_answer+ attribute. Then a Delegate decoration is added to the calling
21
21
  # component (self), which delegates to the component to be called
22
22
  # (+component+). Then we unwind the calling stack back to the Session by
23
- # throwing <i>:wee_back_to_session</i>. This means, that there is only ever
24
- # one action callback invoked per request. When at a later point in time the
25
- # called component invokes #answer, this will throw a <i>:wee_answer</i>
26
- # exception which is catched in the AnswerDecoration. The AnswerDecoration
27
- # then jumps back to the continuation we created at the beginning, and
28
- # finally method #call returns.
23
+ # throwing <i>:wee_abort_callback_processing</i>. This means, that there is
24
+ # only ever one action callback invoked per request. When at a later point
25
+ # in time the called component invokes #answer, this will throw a
26
+ # <i>:wee_answer</i> exception which is catched in the AnswerDecoration. The
27
+ # AnswerDecoration then jumps back to the continuation we created at the
28
+ # beginning, and finally method #call returns.
29
29
  #
30
30
  # Note that #call returns to an "old" stack-frame from a previous request.
31
- # That is why we throw <i>:wee_back_to_session</i> after invoking an action
32
- # callback, and that's why only ever one is invoked. We could remove this
33
- # limitation without problems, but then there would be a difference between
34
- # those action callbacks that call other components and those that do not.
31
+ # That is why we throw <i>:wee_abort_callback_processing</i> after invoking
32
+ # an action callback, and that's why only ever one is invoked. We could
33
+ # remove this limitation without problems, but then there would be a
34
+ # difference between those action callbacks that call other components and
35
+ # those that do not.
35
36
 
36
37
  def call(component, return_callback=:use_continuation, *additional_args)
37
38
  add_decoration(delegate = Wee::Delegate.new(component))
@@ -40,7 +41,7 @@ class Wee::Component
40
41
  if return_callback == :use_continuation
41
42
  result = callcc {|cc|
42
43
  answer.on_answer = cc
43
- throw :wee_back_to_session
44
+ throw :wee_abort_callback_processing, nil
44
45
  }
45
46
  remove_decoration(delegate)
46
47
  component.remove_decoration(answer)
@@ -48,7 +49,7 @@ class Wee::Component
48
49
  else
49
50
  answer.on_answer = OnAnswer.new(self, component, delegate, answer,
50
51
  return_callback, additional_args)
51
- throw :wee_back_to_session
52
+ throw :wee_abort_callback_processing, nil
52
53
  end
53
54
  end
54
55
 
@@ -1,26 +1,9 @@
1
1
  require 'timeout'
2
2
 
3
- class Wee::Session
4
- def initialize(&block)
5
- Thread.current[:wee_session] = self
6
-
7
- @idgen = Wee::SimpleIdGenerator.new
8
- @in_queue, @out_queue = SizedQueue.new(1), SizedQueue.new(1)
9
-
10
- block.call(self)
3
+ class Wee::AbstractSession
11
4
 
12
- raise ArgumentError, "No root component specified" if @root_component.nil?
13
- raise ArgumentError, "No page_store specified" if @page_store.nil?
14
-
15
- @initial_snapshot = snapshot()
16
-
17
- start_request_response_loop
18
- super()
19
- ensure
20
- Thread.current[:wee_session] = nil
21
- end
5
+ # Called by Wee::Application to send the session a request.
22
6
 
23
- # called by application to send the session a request
24
7
  def handle_request(context)
25
8
  super
26
9
 
@@ -31,6 +14,15 @@ class Wee::Session
31
14
  # Wait for the response.
32
15
  return @out_queue.pop
33
16
  end
17
+ end
18
+
19
+ class Wee::Session
20
+ def initialize(&block)
21
+ super()
22
+ @in_queue, @out_queue = SizedQueue.new(1), SizedQueue.new(1)
23
+ setup(&block)
24
+ start_request_response_loop
25
+ end
34
26
 
35
27
  def start_request_response_loop
36
28
  Thread.abort_on_exception = true
@@ -1,15 +1,16 @@
1
- # The only dependencies of the core classes are:
2
- #
3
- # * Wee::Session.current in class Wee::Presenter#session
4
- # * Wee::DefaultRenderer in Wee::Presenter#renderer_class
5
- #
1
+ # There are no dependencies to outer classes!
2
+
3
+ module Wee; end
6
4
 
7
- # independent files
8
5
  require 'wee/core/valueholder'
9
6
  require 'wee/core/snapshot'
10
7
  require 'wee/core/callback'
8
+ require 'wee/core/page'
9
+ require 'wee/core/context'
10
+ require 'wee/core/idgen'
11
+ require 'wee/core/renderer'
12
+ require 'wee/core/componentrunner'
11
13
 
12
- # dependent files
13
14
  require 'wee/core/presenter'
14
15
  require 'wee/core/decoration'
15
16
  require 'wee/core/component'
@@ -78,32 +78,18 @@ class Wee::Component < Wee::Presenter
78
78
  def initialize() # :notnew:
79
79
  @__decoration = Wee::ValueHolder.new(self)
80
80
  @__children = []
81
- @__parent = nil
82
81
  end
83
82
 
84
83
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85
84
  # :section: Children/Composite
86
85
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87
86
 
88
- public
89
-
90
- # Returns the parent component (or nil if it's the root component). Note
91
- # that if you #call a component, the parent attribute will not be set
92
- # automatically.
93
-
94
- def parent
95
- @__parent
96
- end
97
-
98
- # Reparents the component. You should not call this method yourself!
99
-
100
- def parent=(new_parent)
101
- @__parent = new_parent
102
- end
103
-
104
87
  protected
105
88
 
106
89
  # Returns all direct child components collected in an array.
90
+ #
91
+ # You can overwrite this method to return all direct child components of this
92
+ # component.
107
93
 
108
94
  def children
109
95
  @__children
@@ -127,14 +113,8 @@ class Wee::Component < Wee::Presenter
127
113
  # snapshot.add(self.children)
128
114
  # end
129
115
  #
130
- # NOTE: Each component has exactly one parent component (or none in the case
131
- # of the root component or when using #call). As such, you can't (and should
132
- # not!) add a child more than once to another component.
133
- #
134
116
 
135
117
  def add_child(child)
136
- raise "Child already has a parent!" if not child.parent.nil?
137
- child.parent = self
138
118
  self.children << child
139
119
  child
140
120
  end
@@ -328,10 +308,10 @@ class Wee::Component < Wee::Presenter
328
308
  # delegates to the component to be called (+component+).
329
309
  #
330
310
  # Then we unwind the calling stack back to the Session by throwing
331
- # <i>:wee_back_to_session</i>. This means, that there is only ever one action
332
- # callback invoked per request. This is not neccessary, we could simply omit
333
- # this, but then we'd break compatibility with the implementation using
334
- # continuations.
311
+ # <i>:wee_abort_callback_processing</i>. This means, that there is only ever
312
+ # one action callback invoked per request. This is not neccessary, we could
313
+ # simply omit this, but then we'd break compatibility with the implementation
314
+ # using continuations.
335
315
  #
336
316
  # When at a later point in time the called component invokes #answer, this
337
317
  # will throw a <i>:wee_answer</i> exception which is catched in the
@@ -345,7 +325,7 @@ class Wee::Component < Wee::Presenter
345
325
  component.add_decoration(answer = Wee::AnswerDecoration.new)
346
326
  answer.on_answer = OnAnswer.new(self, component, delegate, answer,
347
327
  return_callback, args)
348
- throw :wee_back_to_session
328
+ throw :wee_abort_callback_processing, nil
349
329
  end
350
330
 
351
331
  class OnAnswer < Struct.new(:calling_component, :called_component, :delegate,