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.
- 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
|
@@ -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 @@
|
|
|
1
|
+
class Wee::Page < Struct.new(:snapshot, :callbacks); end
|
data/lib/wee/core/presenter.rb
CHANGED
|
@@ -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() @
|
|
40
|
+
def renderer() @__renderer end
|
|
41
41
|
|
|
42
42
|
# Short cut for #renderer.
|
|
43
|
-
def r() @
|
|
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
|
-
|
|
52
|
-
renderer.current_component = self
|
|
53
|
-
old_renderer = @renderer
|
|
51
|
+
old_renderer = @__renderer
|
|
54
52
|
begin
|
|
55
|
-
|
|
56
|
-
yield
|
|
53
|
+
renderer_class.new(rendering_context, self) {|@__renderer| yield }
|
|
57
54
|
ensure
|
|
58
|
-
@
|
|
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
|
-
|
|
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
|
data/lib/wee/core_ext.rb
ADDED
|
@@ -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
|
|
@@ -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
|