wee 0.4.0 → 0.5.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 +75 -0
- data/README +17 -9
- data/Rakefile +2 -2
- data/TODO +20 -0
- data/benchmark/Makefile +14 -9
- data/benchmark/counter.rb +11 -30
- data/benchmark/report_req.rb +12 -0
- data/doc/rdoc/classes/Array.html +12 -12
- 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/Object.html +12 -12
- data/doc/rdoc/classes/OgApplication.html +126 -0
- data/doc/rdoc/classes/OgScaffolder.html +401 -0
- data/doc/rdoc/classes/OgSession.html +172 -0
- data/doc/rdoc/classes/String.html +12 -12
- data/doc/rdoc/classes/Struct.html +12 -12
- data/doc/rdoc/classes/Wee.html +5 -62
- data/doc/rdoc/classes/Wee/AnswerDecoration.html +9 -9
- data/doc/rdoc/classes/Wee/Application.html +107 -39
- data/doc/rdoc/classes/Wee/Brush.html +22 -18
- data/doc/rdoc/classes/Wee/Brush/ActionCallbackMixin.html +17 -11
- data/doc/rdoc/classes/Wee/Brush/ActionURLCallbackMixin.html +18 -10
- data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +30 -64
- data/doc/rdoc/classes/Wee/Brush/FileUploadTag.html +8 -10
- data/doc/rdoc/classes/Wee/Brush/FormTag.html +27 -79
- data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +12 -12
- data/doc/rdoc/classes/Wee/Brush/GenericSingleTagBrush.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +179 -65
- data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +12 -12
- data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +16 -18
- data/doc/rdoc/classes/Wee/Brush/ImageTag.html +203 -0
- data/doc/rdoc/classes/Wee/Brush/InputCallbackMixin.html +17 -11
- data/doc/rdoc/classes/Wee/Brush/InputTag.html +15 -15
- data/doc/rdoc/classes/Wee/Brush/JavascriptTag.html +147 -0
- data/doc/rdoc/classes/Wee/Brush/Page.html +17 -17
- data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +25 -50
- data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +7 -38
- data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +15 -16
- data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +65 -50
- data/doc/rdoc/classes/Wee/Brush/TableTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +14 -64
- data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/ToCallback.html +146 -0
- data/doc/rdoc/classes/Wee/CallbackRegistry.html +40 -40
- data/doc/rdoc/classes/Wee/CallbackStream.html +18 -18
- data/doc/rdoc/classes/Wee/Canvas.html +24 -24
- data/doc/rdoc/classes/Wee/Component.html +232 -149
- data/doc/rdoc/classes/Wee/Component/OnAnswer.html +153 -0
- data/doc/rdoc/classes/Wee/Decoration.html +42 -42
- data/doc/rdoc/classes/Wee/Delegate.html +27 -27
- data/doc/rdoc/classes/Wee/ErrorResponse.html +12 -12
- data/doc/rdoc/classes/Wee/FormDecoration.html +148 -0
- data/doc/rdoc/classes/Wee/GenericResponse.html +6 -6
- data/doc/rdoc/classes/Wee/HtmlCanvas.html +296 -215
- data/doc/rdoc/classes/Wee/HtmlWriter.html +83 -81
- data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +21 -16
- data/doc/rdoc/classes/Wee/MessageBox.html +180 -0
- data/doc/rdoc/classes/Wee/PageDecoration.html +30 -30
- data/doc/rdoc/classes/Wee/Presenter.html +237 -69
- data/doc/rdoc/classes/Wee/RedirectResponse.html +6 -6
- data/doc/rdoc/classes/Wee/RefreshResponse.html +6 -6
- data/doc/rdoc/classes/Wee/Request.html +18 -18
- data/doc/rdoc/classes/Wee/RequestHandler.html +43 -39
- data/doc/rdoc/classes/Wee/Response.html +24 -24
- data/doc/rdoc/classes/Wee/Session.html +746 -72
- data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +18 -18
- data/doc/rdoc/classes/Wee/Snapshot.html +19 -19
- data/doc/rdoc/classes/Wee/Utils.html +138 -2
- data/doc/rdoc/classes/Wee/Utils/LRUCache.html +7 -7
- data/doc/rdoc/classes/Wee/ValueHolder.html +18 -18
- data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +43 -68
- data/doc/rdoc/classes/Wee/WrapperDecoration.html +150 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +29 -15
- 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/form_decoration_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/components/messagebox_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/components/page_decoration_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/components/wrapper_decoration_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/components_rb.html +4 -1
- data/doc/rdoc/files/lib/wee/continuation/core/component_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/continuation/session_rb.html +110 -0
- data/doc/rdoc/files/lib/wee/continuation_rb.html +116 -0
- 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/presenter_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/core_rb.html +3 -3
- data/doc/rdoc/files/lib/wee/databases/og_rb.html +108 -0
- 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/requesthandler_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/session_rb.html +1 -2
- 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 -8
- data/doc/rdoc/files/lib/wee/utils_rb.html +110 -0
- data/doc/rdoc/files/lib/wee_rb.html +1 -1
- data/doc/rdoc/fr_class_index.html +11 -1
- data/doc/rdoc/fr_file_index.html +8 -0
- data/doc/rdoc/fr_method_index.html +269 -228
- data/examples/calculator.rb +69 -0
- data/examples/calendar.rb +5 -17
- data/examples/example.rb +2 -2
- data/examples/hw.rb +17 -0
- data/examples/live-update.rb +45 -0
- data/examples/og-test.rb +51 -0
- data/lib/wee.rb +1 -1
- data/lib/wee/adaptors/webrick.rb +2 -0
- data/lib/wee/application.rb +16 -0
- data/lib/wee/components.rb +3 -0
- data/lib/wee/components/form_decoration.rb +7 -0
- data/{test → lib/wee}/components/messagebox.rb +1 -1
- data/lib/wee/components/page_decoration.rb +5 -5
- data/lib/wee/components/wrapper_decoration.rb +7 -0
- data/lib/wee/continuation.rb +5 -0
- data/lib/wee/continuation/core/component.rb +55 -0
- data/lib/wee/continuation/session.rb +217 -0
- data/lib/wee/core/callback.rb +11 -6
- data/lib/wee/core/component.rb +45 -33
- data/lib/wee/core/presenter.rb +68 -0
- data/lib/wee/databases/og.rb +114 -0
- data/lib/wee/renderer/html/brushes.rb +179 -98
- data/lib/wee/renderer/html/canvas.rb +37 -13
- data/lib/wee/renderer/html/writer.rb +34 -32
- data/lib/wee/requesthandler.rb +6 -3
- data/lib/wee/session.rb +73 -54
- data/lib/wee/utils.rb +5 -0
- data/lib/wee/utils/autoreload.rb +1 -1
- data/lib/wee/utils/cache.rb +0 -2
- data/lib/wee/utils/helper.rb +40 -8
- data/test/components/calltest-cont.rb +16 -0
- data/test/components/calltest.rb +15 -10
- data/test/stress.rb +31 -28
- data/test/stress_and_measure.rb +53 -0
- data/test/stressed_application.rb +15 -0
- data/test/test_html_writer.rb +9 -4
- metadata +236 -195
- data/benchmark/bench.sh +0 -24
|
@@ -36,27 +36,43 @@ class HtmlCanvas < Canvas
|
|
|
36
36
|
attr_reader :document
|
|
37
37
|
attr_accessor :current_component
|
|
38
38
|
|
|
39
|
+
def self.generic_tag(*attrs)
|
|
40
|
+
attrs.each { |a|
|
|
41
|
+
class_eval "
|
|
42
|
+
def #{ a }(*args, &block)
|
|
43
|
+
handle(Brush::GenericTagBrush.new('#{ a }'), *args, &block)
|
|
44
|
+
end
|
|
45
|
+
"
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.generic_single_tag(*attrs)
|
|
50
|
+
attrs.each { |a|
|
|
51
|
+
class_eval "
|
|
52
|
+
def #{ a }(*args, &block)
|
|
53
|
+
handle(Brush::GenericSingleTagBrush.new('#{ a }'), *args, &block)
|
|
54
|
+
end
|
|
55
|
+
"
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
39
59
|
def initialize(rendering_context)
|
|
40
60
|
super()
|
|
41
61
|
@rendering_context = rendering_context
|
|
42
62
|
@document = rendering_context.document
|
|
43
63
|
end
|
|
44
64
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
65
|
+
generic_tag :html, :head, :body, :title, :style, :h1, :h2, :h3, :h4, :h5, :div
|
|
66
|
+
generic_single_tag :link
|
|
48
67
|
|
|
49
|
-
def url_for_callback(
|
|
50
|
-
raise ArgumentError if symbol and block
|
|
51
|
-
block = self.current_component.method(symbol) unless block
|
|
68
|
+
def url_for_callback(callback)
|
|
52
69
|
req = self.rendering_context.request
|
|
53
|
-
url = req.build_url(req.request_handler_id, req.page_id, register_callback(:action,
|
|
70
|
+
url = req.build_url(req.request_handler_id, req.page_id, register_callback(:action, callback))
|
|
54
71
|
return url
|
|
55
72
|
end
|
|
56
73
|
|
|
57
|
-
def register_callback(type,
|
|
58
|
-
|
|
59
|
-
self.rendering_context.callbacks.register_for(self.current_component, type, &block)
|
|
74
|
+
def register_callback(type, callback)
|
|
75
|
+
self.rendering_context.callbacks.register_for(self.current_component, type, callback)
|
|
60
76
|
end
|
|
61
77
|
|
|
62
78
|
def table(*args, &block)
|
|
@@ -127,16 +143,24 @@ class HtmlCanvas < Canvas
|
|
|
127
143
|
handle(Brush::GenericTagBrush.new("b"), *args, &block)
|
|
128
144
|
end
|
|
129
145
|
|
|
146
|
+
def javascript(*args, &block)
|
|
147
|
+
handle(Brush::JavascriptTag.new, *args, &block)
|
|
148
|
+
end
|
|
149
|
+
|
|
130
150
|
def paragraph
|
|
131
|
-
set_brush(Brush::
|
|
151
|
+
set_brush(Brush::GenericSingleTagBrush.new("p"))
|
|
132
152
|
end
|
|
133
153
|
|
|
134
154
|
def break
|
|
135
|
-
set_brush(Brush::
|
|
155
|
+
set_brush(Brush::GenericSingleTagBrush.new("br"))
|
|
136
156
|
end
|
|
137
157
|
|
|
138
158
|
def image
|
|
139
|
-
|
|
159
|
+
handle(Brush::ImageTag.new)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def link_css(url)
|
|
163
|
+
link.type('text/css').rel('stylesheet').href(url)
|
|
140
164
|
end
|
|
141
165
|
|
|
142
166
|
def text(str)
|
|
@@ -13,7 +13,6 @@ require 'cgi'
|
|
|
13
13
|
# w.end_tag('body')
|
|
14
14
|
# w.end_tag('html')
|
|
15
15
|
#
|
|
16
|
-
# p w.valid? # => true
|
|
17
16
|
# p doc # => '<html><body><a href="http://...">link</a></body></html>'
|
|
18
17
|
#
|
|
19
18
|
|
|
@@ -22,46 +21,51 @@ class Wee::HtmlWriter
|
|
|
22
21
|
|
|
23
22
|
def initialize(port)
|
|
24
23
|
@port = port
|
|
25
|
-
@open_start_tag = false
|
|
26
|
-
@tag_stack = []
|
|
27
24
|
end
|
|
28
25
|
|
|
29
|
-
def start_tag(tag, attributes=
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
def start_tag(tag, attributes=nil)
|
|
27
|
+
if attributes
|
|
28
|
+
@port << "<#{ tag }"
|
|
29
|
+
attributes.each {|k, v|
|
|
30
|
+
if v
|
|
31
|
+
@port << %[ #{ k }="#{ v }"]
|
|
32
|
+
else
|
|
33
|
+
@port << %[ #{ k }]
|
|
34
|
+
end
|
|
35
|
+
}
|
|
36
|
+
@port << ">"
|
|
37
|
+
else
|
|
38
|
+
@port << "<#{ tag }>"
|
|
39
|
+
end
|
|
42
40
|
|
|
43
41
|
self
|
|
44
42
|
end
|
|
45
43
|
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
def single_tag(tag, attributes=nil)
|
|
45
|
+
if attributes
|
|
46
|
+
@port << "<#{ tag }"
|
|
47
|
+
attributes.each {|k, v|
|
|
48
|
+
if v
|
|
49
|
+
@port << %[ #{ k }="#{ v }"]
|
|
50
|
+
else
|
|
51
|
+
@port << %[ #{ k }]
|
|
52
|
+
end
|
|
53
|
+
}
|
|
54
|
+
@port << " />"
|
|
52
55
|
else
|
|
53
|
-
@port << "
|
|
56
|
+
@port << "<#{ tag } />"
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
self
|
|
57
60
|
end
|
|
58
61
|
|
|
59
|
-
def
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
def end_tag(tag)
|
|
63
|
+
@port << "</#{ tag }>"
|
|
64
|
+
|
|
65
|
+
self
|
|
66
|
+
end
|
|
64
67
|
|
|
68
|
+
def text(str)
|
|
65
69
|
@port << str.to_s
|
|
66
70
|
|
|
67
71
|
self
|
|
@@ -69,10 +73,8 @@ class Wee::HtmlWriter
|
|
|
69
73
|
alias << text
|
|
70
74
|
|
|
71
75
|
def encode_text(str)
|
|
72
|
-
|
|
73
|
-
end
|
|
76
|
+
@port << CGI.escapeHTML(str.to_s)
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
@tag_stack.empty?
|
|
78
|
+
self
|
|
77
79
|
end
|
|
78
80
|
end
|
data/lib/wee/requesthandler.rb
CHANGED
|
@@ -30,6 +30,9 @@ class Wee::RequestHandler
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
# Terminates the handler.
|
|
33
|
+
#
|
|
34
|
+
# This will usually not immediatly terminate the handler from running, but
|
|
35
|
+
# further requests will not be answered.
|
|
33
36
|
|
|
34
37
|
def teminate
|
|
35
38
|
@running = false
|
|
@@ -39,14 +42,14 @@ class Wee::RequestHandler
|
|
|
39
42
|
|
|
40
43
|
def alive?
|
|
41
44
|
return false if not @running
|
|
42
|
-
return false if @max_requests and @request_count >= @max_requests
|
|
45
|
+
return @running = false if @max_requests and @request_count >= @max_requests
|
|
43
46
|
|
|
44
47
|
now = Time.now
|
|
45
48
|
inactivity = now - @last_access
|
|
46
49
|
lifetime = now - @creation_time
|
|
47
50
|
|
|
48
|
-
return false if @expire_after and inactivity > @expire_after
|
|
49
|
-
return false if @max_lifetime and lifetime > @max_lifetime
|
|
51
|
+
return @running = false if @expire_after and inactivity > @expire_after
|
|
52
|
+
return @running = false if @max_lifetime and lifetime > @max_lifetime
|
|
50
53
|
return true
|
|
51
54
|
end
|
|
52
55
|
|
data/lib/wee/session.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require 'wee/page'
|
|
2
2
|
require 'thread'
|
|
3
|
-
require 'timeout'
|
|
4
3
|
|
|
5
4
|
class Wee::Session < Wee::RequestHandler
|
|
6
5
|
attr_accessor :root_component, :page_store
|
|
@@ -15,7 +14,9 @@ class Wee::Session < Wee::RequestHandler
|
|
|
15
14
|
Thread.current[:wee_session] = self
|
|
16
15
|
|
|
17
16
|
@idgen = Wee::SimpleIdGenerator.new
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
# to serialize the requests we need a mutex
|
|
19
|
+
@mutex = Mutex.new
|
|
19
20
|
|
|
20
21
|
block.call(self)
|
|
21
22
|
|
|
@@ -24,7 +25,6 @@ class Wee::Session < Wee::RequestHandler
|
|
|
24
25
|
|
|
25
26
|
@initial_snapshot = snapshot()
|
|
26
27
|
|
|
27
|
-
start_request_response_loop
|
|
28
28
|
super()
|
|
29
29
|
ensure
|
|
30
30
|
Thread.current[:wee_session] = nil
|
|
@@ -36,50 +36,24 @@ class Wee::Session < Wee::RequestHandler
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# called by application to send the session a request
|
|
39
|
-
def handle_request(context)
|
|
40
|
-
super
|
|
41
|
-
|
|
42
|
-
# Send a request to the session. If the session is currently busy
|
|
43
|
-
# processing another request, this will block.
|
|
44
|
-
@in_queue.push(context)
|
|
45
|
-
|
|
46
|
-
# Wait for the response.
|
|
47
|
-
return @out_queue.pop
|
|
48
|
-
end
|
|
49
39
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
def handle_request(context)
|
|
41
|
+
@mutex.synchronize do
|
|
42
|
+
begin
|
|
43
|
+
Thread.current[:wee_session] = self
|
|
44
|
+
@context = context
|
|
45
|
+
super
|
|
46
|
+
awake
|
|
47
|
+
process_request
|
|
48
|
+
sleep
|
|
49
|
+
rescue Exception => exn
|
|
50
|
+
context.response = Wee::ErrorResponse.new(exn)
|
|
51
|
+
ensure
|
|
52
|
+
Thread.current[:wee_session] = nil
|
|
55
53
|
@context = nil
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
while @context.nil?
|
|
60
|
-
begin
|
|
61
|
-
Timeout.timeout(5) {
|
|
62
|
-
@context = @in_queue.pop
|
|
63
|
-
}
|
|
64
|
-
rescue Timeout::Error
|
|
65
|
-
break unless alive?
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# abort thread if no longer alive
|
|
70
|
-
break if not alive?
|
|
71
|
-
|
|
72
|
-
raise "invalid request" if @context.nil?
|
|
73
|
-
|
|
74
|
-
begin
|
|
75
|
-
process_request
|
|
76
|
-
rescue Exception => exn
|
|
77
|
-
@context.response = Wee::ErrorResponse.new(exn)
|
|
78
|
-
end
|
|
79
|
-
@out_queue.push(@context)
|
|
80
|
-
}
|
|
81
|
-
p "session loop terminated" if $DEBUG
|
|
82
|
-
}
|
|
54
|
+
@page = nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
83
57
|
end
|
|
84
58
|
|
|
85
59
|
def create_page(snapshot)
|
|
@@ -87,6 +61,16 @@ class Wee::Session < Wee::RequestHandler
|
|
|
87
61
|
page = Wee::Page.new(snapshot, Wee::CallbackRegistry.new(idgen))
|
|
88
62
|
end
|
|
89
63
|
|
|
64
|
+
# Is called before process_request is invoked
|
|
65
|
+
# Can be used to setup e.g. a database connection.
|
|
66
|
+
def awake
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Is called after process_request is run
|
|
70
|
+
# Can be used to release e.g. a database connection.
|
|
71
|
+
def sleep
|
|
72
|
+
end
|
|
73
|
+
|
|
90
74
|
def process_request
|
|
91
75
|
if @context.request.page_id.nil?
|
|
92
76
|
|
|
@@ -95,11 +79,11 @@ class Wee::Session < Wee::RequestHandler
|
|
|
95
79
|
|
|
96
80
|
handle_new_page_view(@context, @initial_snapshot)
|
|
97
81
|
|
|
98
|
-
elsif page = @page_store.fetch(@context.request.page_id, false)
|
|
82
|
+
elsif @page = @page_store.fetch(@context.request.page_id, false)
|
|
99
83
|
|
|
100
84
|
# A valid page_id was specified and the corresponding page exists.
|
|
101
85
|
|
|
102
|
-
page.snapshot.restore
|
|
86
|
+
@page.snapshot.restore
|
|
103
87
|
|
|
104
88
|
p @context.request.fields if $DEBUG
|
|
105
89
|
|
|
@@ -112,9 +96,9 @@ class Wee::Session < Wee::RequestHandler
|
|
|
112
96
|
# 2. Render the page (respond).
|
|
113
97
|
# 3. Store the page back into the store
|
|
114
98
|
|
|
115
|
-
page = create_page(page.snapshot) # remove all action/input handlers
|
|
116
|
-
respond(@context, page.callbacks) # render
|
|
117
|
-
@page_store[@context.request.page_id] = page # store
|
|
99
|
+
@page = create_page(@page.snapshot) # remove all action/input handlers
|
|
100
|
+
respond(@context, @page.callbacks) # render
|
|
101
|
+
@page_store[@context.request.page_id] = @page # store
|
|
118
102
|
|
|
119
103
|
else
|
|
120
104
|
|
|
@@ -123,16 +107,27 @@ class Wee::Session < Wee::RequestHandler
|
|
|
123
107
|
# We process the request and invoke actions/inputs. Then we generate a
|
|
124
108
|
# new page view.
|
|
125
109
|
|
|
126
|
-
callback_stream = Wee::CallbackStream.new(page.callbacks, @context.request.fields)
|
|
110
|
+
callback_stream = Wee::CallbackStream.new(@page.callbacks, @context.request.fields)
|
|
127
111
|
|
|
128
112
|
if callback_stream.all_of_type(:action).size > 1
|
|
129
113
|
raise "Not allowed to specify more than one action callback"
|
|
130
114
|
end
|
|
131
115
|
|
|
132
|
-
catch(:
|
|
133
|
-
|
|
116
|
+
live_update_response = catch(:wee_live_update) {
|
|
117
|
+
catch(:wee_back_to_session) {
|
|
118
|
+
@root_component.process_callbacks_chain(callback_stream)
|
|
119
|
+
}
|
|
120
|
+
nil
|
|
134
121
|
}
|
|
135
|
-
|
|
122
|
+
|
|
123
|
+
if live_update_response
|
|
124
|
+
# replace existing page with new snapshot
|
|
125
|
+
@page.snapshot = self.snapshot
|
|
126
|
+
@page_store[@context.request.page_id] = @page
|
|
127
|
+
@context.response = live_update_response
|
|
128
|
+
else
|
|
129
|
+
handle_new_page_view(@context)
|
|
130
|
+
end
|
|
136
131
|
|
|
137
132
|
end
|
|
138
133
|
|
|
@@ -150,6 +145,30 @@ class Wee::Session < Wee::RequestHandler
|
|
|
150
145
|
end
|
|
151
146
|
end
|
|
152
147
|
|
|
148
|
+
def current_context
|
|
149
|
+
@context
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def current_page
|
|
153
|
+
@page
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
157
|
+
# :section: Properties
|
|
158
|
+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
159
|
+
|
|
160
|
+
attr_accessor :properties
|
|
161
|
+
|
|
162
|
+
# Returns an "owned" property for the given +klass+.
|
|
163
|
+
|
|
164
|
+
def get_property(prop, klass)
|
|
165
|
+
if @properties
|
|
166
|
+
@properties.fetch(klass, {})[prop]
|
|
167
|
+
else
|
|
168
|
+
nil
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
153
172
|
private
|
|
154
173
|
|
|
155
174
|
def handle_new_page_view(context, snapshot=nil)
|
data/lib/wee/utils.rb
ADDED
data/lib/wee/utils/autoreload.rb
CHANGED
data/lib/wee/utils/cache.rb
CHANGED
data/lib/wee/utils/helper.rb
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
module Wee::Utils
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
# [+component+]
|
|
4
|
+
# The component class for which to create an application object. If a
|
|
5
|
+
# block is given, this will be invoked to create a new component object.
|
|
6
|
+
#
|
|
7
|
+
# [+options+]
|
|
8
|
+
# A Hash. Following keys are accepted:
|
|
9
|
+
#
|
|
10
|
+
# [:application]
|
|
11
|
+
# The application class to use (default: Wee::Application)
|
|
12
|
+
#
|
|
13
|
+
# [:session]
|
|
14
|
+
# The session class to use (default: Wee::Session)
|
|
15
|
+
#
|
|
16
|
+
# [:page_cache_capacity]
|
|
17
|
+
# The size of the sessions page_store (default: 10)
|
|
18
|
+
#
|
|
19
|
+
# [:id_seed]
|
|
20
|
+
# Initial value of the SimpleIdGenerator (default: rand(1_000_000))
|
|
21
|
+
#
|
|
22
|
+
def self.app_for(component=nil, options={}, &block)
|
|
23
|
+
raise "either component or block must be given" if component.nil? and block.nil?
|
|
24
|
+
|
|
25
|
+
defaults = {
|
|
26
|
+
:application => Wee::Application,
|
|
27
|
+
:session => Wee::Session,
|
|
28
|
+
:page_cache_capacity => 10,
|
|
29
|
+
:id_seed => rand(1_000_000)
|
|
30
|
+
}
|
|
31
|
+
options = defaults.update(options)
|
|
32
|
+
|
|
33
|
+
options[:application].new {|app|
|
|
6
34
|
app.default_request_handler {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
35
|
+
options[:session].new {|sess|
|
|
36
|
+
if component
|
|
37
|
+
sess.root_component = component.new
|
|
38
|
+
else
|
|
39
|
+
sess.root_component = block.call
|
|
40
|
+
end
|
|
41
|
+
sess.page_store = Wee::Utils::LRUCache.new(options[:page_cache_capacity])
|
|
10
42
|
}
|
|
11
43
|
}
|
|
12
|
-
app.id_generator = Wee::SimpleIdGenerator.new(id_seed)
|
|
44
|
+
app.id_generator = Wee::SimpleIdGenerator.new(options[:id_seed])
|
|
13
45
|
}
|
|
14
46
|
end
|
|
15
47
|
end
|