wee 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +286 -0
- data/Features +185 -0
- data/doc/rdoc/classes/ActionView.html +107 -0
- data/doc/rdoc/classes/ActionView/Base.html +133 -0
- data/doc/rdoc/classes/Array.html +7 -59
- data/doc/rdoc/classes/Cache/StorageCache.html +38 -38
- data/doc/rdoc/classes/Cache/Strategy/CapacityBounded.html +30 -30
- data/doc/rdoc/classes/Cache/Strategy/LFU.html +24 -24
- data/doc/rdoc/classes/Cache/Strategy/LRU.html +24 -24
- data/doc/rdoc/classes/Cache/Strategy/Unbounded.html +24 -24
- data/doc/rdoc/classes/Enumerable.html +6 -6
- data/doc/rdoc/classes/Hash.html +120 -0
- data/doc/rdoc/classes/Main.html +58 -34
- data/doc/rdoc/classes/Object.html +12 -12
- data/doc/rdoc/classes/OgScaffolder.html +165 -166
- data/doc/rdoc/classes/OgScaffolder/Editor.html +112 -112
- data/doc/rdoc/classes/String.html +7 -59
- data/doc/rdoc/classes/Struct.html +14 -14
- data/doc/rdoc/classes/Wee.html +70 -6
- data/doc/rdoc/classes/Wee/AbstractSession.html +502 -0
- data/doc/rdoc/classes/Wee/AnswerDecoration.html +11 -11
- data/doc/rdoc/classes/Wee/Application.html +139 -84
- data/doc/rdoc/classes/Wee/Brush.html +21 -18
- data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +90 -17
- data/doc/rdoc/classes/Wee/Brush/CheckboxTag.html +162 -0
- data/doc/rdoc/classes/Wee/Brush/FileUploadTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/FormTag.html +41 -17
- data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +12 -12
- data/doc/rdoc/classes/Wee/Brush/GenericSingleTagBrush.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +112 -86
- data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +12 -12
- data/doc/rdoc/classes/Wee/Brush/HiddenInputTag.html +160 -0
- data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +15 -15
- data/doc/rdoc/classes/Wee/Brush/ImageTag.html +21 -21
- data/doc/rdoc/classes/Wee/Brush/InputTag.html +14 -14
- data/doc/rdoc/classes/Wee/Brush/JavascriptTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/Page.html +14 -14
- data/doc/rdoc/classes/Wee/Brush/RadioButtonTag.html +234 -0
- data/doc/rdoc/classes/Wee/Brush/RadioButtonTag/RadioGroup.html +207 -0
- data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +124 -28
- data/doc/rdoc/classes/Wee/Brush/SelectListTag/SelectListCallback.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +14 -14
- data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +42 -42
- data/doc/rdoc/classes/Wee/Brush/TableTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +48 -15
- data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +7 -7
- data/doc/rdoc/classes/Wee/CallbackRegistry.html +38 -38
- data/doc/rdoc/classes/Wee/CallbackStream.html +18 -18
- data/doc/rdoc/classes/Wee/CanvasMixin.html +225 -0
- data/doc/rdoc/classes/Wee/Component.html +202 -201
- data/doc/rdoc/classes/Wee/Component/OnAnswer.html +7 -7
- data/doc/rdoc/classes/Wee/ComponentDispatcher.html +289 -0
- data/doc/rdoc/classes/Wee/ComponentRunner.html +321 -0
- data/doc/rdoc/classes/Wee/Context.html +63 -3
- data/doc/rdoc/classes/Wee/Decoration.html +45 -45
- data/doc/rdoc/classes/Wee/Delegate.html +30 -30
- data/doc/rdoc/classes/Wee/DupReplaceSnapshotMixin.html +164 -0
- data/doc/rdoc/classes/Wee/ErrorResponse.html +16 -16
- data/doc/rdoc/classes/Wee/Examples.html +114 -0
- data/doc/rdoc/classes/Wee/Examples/Calculator.html +319 -0
- data/doc/rdoc/classes/Wee/Examples/Counter.html +289 -0
- data/doc/rdoc/classes/Wee/Examples/EditableCounter.html +210 -0
- data/doc/rdoc/classes/Wee/Examples/Window.html +346 -0
- data/doc/rdoc/classes/Wee/FastCGIAdaptor.html +227 -0
- data/doc/rdoc/classes/Wee/FormDecoration.html +6 -6
- data/doc/rdoc/classes/Wee/GenericResponse.html +7 -7
- data/doc/rdoc/classes/Wee/HtmlCanvasRenderer.html +1230 -0
- data/doc/rdoc/classes/Wee/HtmlWriter.html +40 -40
- data/doc/rdoc/classes/Wee/IdGenerator.html +148 -0
- data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +27 -14
- data/doc/rdoc/classes/Wee/LoginDecoration.html +261 -0
- data/doc/rdoc/classes/Wee/Md5IdGenerator.html +14 -14
- data/doc/rdoc/classes/Wee/MessageBox.html +14 -14
- data/doc/rdoc/classes/Wee/Nitro.html +114 -0
- data/doc/rdoc/classes/Wee/Nitro/ControllerClassMixin.html +192 -0
- data/doc/rdoc/classes/Wee/Nitro/ControllerMixin.html +345 -0
- data/doc/rdoc/classes/Wee/Nitro/FormTag.html +155 -0
- data/doc/rdoc/classes/Wee/Nitro/HtmlCanvasRenderer.html +178 -0
- data/doc/rdoc/classes/Wee/Page.html +4 -0
- data/doc/rdoc/classes/Wee/PageDecoration.html +18 -18
- data/doc/rdoc/classes/Wee/PagelessApplication.html +13 -11
- data/doc/rdoc/classes/Wee/PagelessComponentDriver.html +296 -0
- data/doc/rdoc/classes/Wee/PagelessRequest.html +52 -21
- data/doc/rdoc/classes/Wee/PagelessSession.html +130 -91
- data/doc/rdoc/classes/Wee/Pager.html +534 -0
- data/doc/rdoc/classes/Wee/Presenter.html +482 -298
- data/doc/rdoc/classes/Wee/Rails.html +114 -0
- data/doc/rdoc/classes/Wee/Rails/ControllerClassMixin.html +192 -0
- data/doc/rdoc/classes/Wee/Rails/ControllerMixin.html +342 -0
- data/doc/rdoc/classes/Wee/Rails/FormTag.html +155 -0
- data/doc/rdoc/classes/Wee/Rails/HtmlCanvasRenderer.html +177 -0
- data/doc/rdoc/classes/Wee/RedirectResponse.html +7 -7
- data/doc/rdoc/classes/Wee/RefreshResponse.html +7 -7
- data/doc/rdoc/classes/Wee/Renderer.html +208 -0
- data/doc/rdoc/classes/Wee/RenderingContext.html +175 -3
- data/doc/rdoc/classes/Wee/Request.html +197 -46
- data/doc/rdoc/classes/Wee/RequestHandler.html +31 -31
- data/doc/rdoc/classes/Wee/Response.html +44 -43
- data/doc/rdoc/classes/Wee/Session.html +296 -402
- data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +14 -14
- data/doc/rdoc/classes/Wee/Snapshot.html +19 -19
- data/doc/rdoc/classes/Wee/Utils.html +22 -22
- data/doc/rdoc/classes/Wee/Utils/LRUCache.html +6 -6
- data/doc/rdoc/classes/Wee/ValueHolder.html +19 -19
- data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +72 -46
- data/doc/rdoc/classes/Wee/WrapperDecoration.html +6 -6
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/INSTALL.html +1 -1
- data/doc/rdoc/files/README.html +8 -12
- data/doc/rdoc/files/lib/cache/cache_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/abstractsession_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/adaptors/fastcgi_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/adaptors/nitro_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/adaptors/rails_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/adaptors/webrick_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/application_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/components/component_dispatcher_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/components/form_decoration_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/components/login_decoration_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/components/messagebox_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/components/page_decoration_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/components/pager_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/components/wrapper_decoration_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/components_rb.html +4 -1
- data/doc/rdoc/files/lib/wee/continuation/core/component_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/continuation/session_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/continuation_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core/callback_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core/component_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core/componentrunner_rb.html +110 -0
- data/doc/rdoc/files/lib/wee/core/context_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/core/decoration_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core/idgen_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/core/page_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/core/presenter_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core/renderer_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/core/snapshot_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core/valueholder_rb.html +2 -2
- data/doc/rdoc/files/lib/wee/core_ext_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/core_rb.html +7 -14
- data/doc/rdoc/files/lib/wee/databases/og/application_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/databases/og/old_scaffolder_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/databases/og/scaffolder_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/databases/og/session_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/databases/og_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/examples/calculator_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/examples/counter_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/examples/editable_counter_rb.html +114 -0
- data/doc/rdoc/files/lib/wee/examples/window_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/idgen/md5_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/idgen/simple_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/page_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/pageless/application_rb.html +8 -1
- data/doc/rdoc/files/lib/wee/pageless/request_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/pageless/session_rb.html +2 -1
- data/doc/rdoc/files/lib/wee/pageless_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/renderer/html/brushes_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/renderer/html/canvas_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/renderer/html/writer_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/request_rb.html +5 -4
- data/doc/rdoc/files/lib/wee/requesthandler_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/response_rb.html +2 -1
- data/doc/rdoc/files/lib/wee/session_rb.html +2 -3
- data/doc/rdoc/files/lib/wee/skeleton/og/components/main_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/skeleton/og/conf/db_rb.html +2 -2
- data/doc/rdoc/files/lib/wee/skeleton/og/models/recipe_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/skeleton/og/run_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/skeleton/simple/components/main_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/skeleton/simple/run_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/snapshot_ext_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/template_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/utils/autoreload_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/utils/cache_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/utils/helper_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/utils_rb.html +1 -1
- data/doc/rdoc/files/lib/wee_rb.html +5 -3
- data/doc/rdoc/fr_class_index.html +34 -2
- data/doc/rdoc/fr_file_index.html +17 -1
- data/doc/rdoc/fr_method_index.html +464 -314
- data/examples/ajax/ajax.rb +1 -1
- data/examples/demo.rb +47 -0
- data/examples/{calendar.rb → demo/calendar.rb} +89 -97
- data/examples/{example.rb → demo/example.rb} +17 -97
- data/examples/dispatcher.rb +37 -0
- data/examples/draw.rb +14 -11
- data/examples/nitro/run.rb +42 -0
- data/examples/radio.rb +44 -0
- data/examples/test.rb +3 -27
- data/lib/wee.rb +15 -3
- data/lib/wee/adaptors/nitro.rb +154 -0
- data/lib/wee/adaptors/rails.rb +154 -0
- data/lib/wee/application.rb +22 -20
- data/lib/wee/components.rb +3 -0
- data/lib/wee/components/component_dispatcher.rb +46 -0
- data/lib/wee/components/login_decoration.rb +35 -0
- data/lib/wee/components/messagebox.rb +2 -2
- data/lib/wee/components/pager.rb +102 -0
- data/lib/wee/continuation/core/component.rb +13 -12
- data/lib/wee/continuation/session.rb +11 -19
- data/lib/wee/core.rb +8 -7
- data/lib/wee/core/component.rb +8 -28
- data/lib/wee/core/componentrunner.rb +73 -0
- data/lib/wee/core/context.rb +27 -0
- data/lib/wee/core/idgen.rb +5 -0
- data/lib/wee/core/page.rb +1 -0
- data/lib/wee/core/presenter.rb +10 -126
- data/lib/wee/core/renderer.rb +23 -0
- data/lib/wee/core_ext.rb +122 -0
- data/lib/wee/databases/og/scaffolder.rb +0 -1
- data/lib/wee/examples/calculator.rb +70 -0
- data/lib/wee/examples/counter.rb +33 -0
- data/lib/wee/examples/editable_counter.rb +31 -0
- data/{examples → lib/wee/examples}/window.rb +29 -23
- data/lib/wee/idgen/md5.rb +1 -1
- data/lib/wee/idgen/simple.rb +1 -1
- data/lib/wee/pageless/session.rb +2 -3
- data/lib/wee/renderer/html/brushes.rb +142 -22
- data/lib/wee/renderer/html/canvas.rb +57 -19
- data/lib/wee/response.rb +3 -2
- data/lib/wee/session.rb +10 -54
- data/lib/wee/skeleton/og/components/main.rb +5 -1
- data/lib/wee/skeleton/og/conf/db.rb +1 -1
- data/lib/wee/snapshot_ext.rb +4 -10
- data/lib/wee/template.rb +19 -5
- data/lib/wee/utils/helper.rb +2 -2
- metadata +90 -13
- data/examples/calculator.rb +0 -67
- data/lib/wee/context.rb +0 -2
data/lib/wee/application.rb
CHANGED
@@ -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
|
-
@
|
61
|
-
|
62
|
-
|
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
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
data/lib/wee/components.rb
CHANGED
@@ -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
|
10
|
+
r.submit_button.value('OK').callback(:answer, true)
|
11
11
|
r.space
|
12
|
-
r.submit_button.value('Cancel').callback
|
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>:
|
24
|
-
# one action callback invoked per request. When at a later point
|
25
|
-
# called component invokes #answer, this will throw a
|
26
|
-
# exception which is catched in the AnswerDecoration. The
|
27
|
-
# then jumps back to the continuation we created at the
|
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>:
|
32
|
-
# callback, and that's why only ever one is invoked. We could
|
33
|
-
# limitation without problems, but then there would be a
|
34
|
-
# those action callbacks that call other components and
|
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 :
|
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 :
|
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::
|
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
|
-
|
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
|
data/lib/wee/core.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
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'
|
data/lib/wee/core/component.rb
CHANGED
@@ -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>:
|
332
|
-
# callback invoked per request. This is not neccessary, we could
|
333
|
-
# this, but then we'd break compatibility with the implementation
|
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 :
|
328
|
+
throw :wee_abort_callback_processing, nil
|
349
329
|
end
|
350
330
|
|
351
331
|
class OnAnswer < Struct.new(:calling_component, :called_component, :delegate,
|