wee 0.1.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +7 -0
- data/README +268 -0
- data/Rakefile +26 -0
- data/TODO +116 -0
- data/benchmark/Centrino1300/result.2000.counter.action +45 -0
- data/benchmark/Centrino1300/result.2000.counter.render +43 -0
- data/benchmark/Centrino1300/result.2000.filehandler +43 -0
- data/benchmark/Centrino600/result.2000.counter.action +47 -0
- data/benchmark/Centrino600/result.2000.counter.render +45 -0
- data/benchmark/Centrino600/result.2000.filehandler +43 -0
- data/benchmark/Makefile +48 -0
- data/benchmark/bench.sh +24 -0
- data/benchmark/counter.rb +96 -0
- data/benchmark/filehandler.rb +6 -0
- data/doc/rdoc/classes/Array.html +172 -0
- data/doc/rdoc/classes/Cache.html +126 -0
- data/doc/rdoc/classes/Cache/StorageCache.html +320 -0
- data/doc/rdoc/classes/Cache/Strategy.html +128 -0
- data/doc/rdoc/classes/Cache/Strategy/CapacityBounded.html +269 -0
- data/doc/rdoc/classes/Cache/Strategy/LFU.html +238 -0
- data/doc/rdoc/classes/Cache/Strategy/LFU/Item.html +111 -0
- data/doc/rdoc/classes/Cache/Strategy/LRU.html +238 -0
- data/doc/rdoc/classes/Cache/Strategy/LRU/Item.html +111 -0
- data/doc/rdoc/classes/Cache/Strategy/Unbounded.html +225 -0
- data/doc/rdoc/classes/Cache/Strategy/Unbounded/Item.html +111 -0
- data/doc/rdoc/classes/Enumerable.html +146 -0
- data/doc/rdoc/classes/LiteralMethod.html +196 -0
- data/doc/rdoc/classes/Object.html +178 -0
- data/doc/rdoc/classes/String.html +172 -0
- data/doc/rdoc/classes/Struct.html +174 -0
- data/doc/rdoc/classes/Wee.html +160 -0
- data/doc/rdoc/classes/Wee/AnswerDecoration.html +182 -0
- data/doc/rdoc/classes/Wee/Application.html +337 -0
- data/doc/rdoc/classes/Wee/Brush.html +245 -0
- data/doc/rdoc/classes/Wee/Brush/ActionCallbackMixin.html +149 -0
- data/doc/rdoc/classes/Wee/Brush/ActionMixin.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/ActionURLCallbackMixin.html +157 -0
- data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +210 -0
- data/doc/rdoc/classes/Wee/Brush/AssignMixin.html +141 -0
- data/doc/rdoc/classes/Wee/Brush/CallbackMixin.html +141 -0
- data/doc/rdoc/classes/Wee/Brush/FormTag.html +225 -0
- data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +176 -0
- data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +283 -0
- data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +176 -0
- data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +195 -0
- data/doc/rdoc/classes/Wee/Brush/InputCallbackMixin.html +149 -0
- data/doc/rdoc/classes/Wee/Brush/InputTag.html +172 -0
- data/doc/rdoc/classes/Wee/Brush/Page.html +193 -0
- data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +267 -0
- data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +177 -0
- data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +154 -0
- data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +173 -0
- data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +277 -0
- data/doc/rdoc/classes/Wee/Brush/TableTag.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +229 -0
- data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +154 -0
- data/doc/rdoc/classes/Wee/Callback.html +231 -0
- data/doc/rdoc/classes/Wee/CallbackRegistry.html +308 -0
- data/doc/rdoc/classes/Wee/CallbackStream.html +227 -0
- data/doc/rdoc/classes/Wee/Canvas.html +235 -0
- data/doc/rdoc/classes/Wee/Component.html +933 -0
- data/doc/rdoc/classes/Wee/Context.html +111 -0
- data/doc/rdoc/classes/Wee/Decoration.html +338 -0
- data/doc/rdoc/classes/Wee/Delegate.html +247 -0
- data/doc/rdoc/classes/Wee/ErrorPage.html +175 -0
- data/doc/rdoc/classes/Wee/ErrorResponse.html +180 -0
- data/doc/rdoc/classes/Wee/GenericResponse.html +162 -0
- data/doc/rdoc/classes/Wee/HtmlCanvas.html +751 -0
- data/doc/rdoc/classes/Wee/HtmlWriter.html +351 -0
- data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +180 -0
- data/doc/rdoc/classes/Wee/MethodCallback.html +193 -0
- data/doc/rdoc/classes/Wee/Page.html +111 -0
- data/doc/rdoc/classes/Wee/Presenter.html +521 -0
- data/doc/rdoc/classes/Wee/RedirectResponse.html +150 -0
- data/doc/rdoc/classes/Wee/RefreshResponse.html +157 -0
- data/doc/rdoc/classes/Wee/RenderingContext.html +111 -0
- data/doc/rdoc/classes/Wee/Request.html +268 -0
- data/doc/rdoc/classes/Wee/RequestHandler.html +336 -0
- data/doc/rdoc/classes/Wee/Response.html +260 -0
- data/doc/rdoc/classes/Wee/Session.html +469 -0
- data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +198 -0
- data/doc/rdoc/classes/Wee/Snapshot.html +211 -0
- data/doc/rdoc/classes/Wee/StateHolder.html +149 -0
- data/doc/rdoc/classes/Wee/StateRegistry.html +434 -0
- data/doc/rdoc/classes/Wee/StateRegistry/Snapshot.html +320 -0
- data/doc/rdoc/classes/Wee/StateRegistry/WithObject.html +153 -0
- data/doc/rdoc/classes/Wee/Utils.html +111 -0
- data/doc/rdoc/classes/Wee/Utils/LRUCache.html +148 -0
- data/doc/rdoc/classes/Wee/ValueHolder.html +220 -0
- data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +330 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/INSTALL.html +118 -0
- data/doc/rdoc/files/README.html +466 -0
- data/doc/rdoc/files/lib/cache/cache_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/adaptors/webrick_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/application_rb.html +112 -0
- data/doc/rdoc/files/lib/wee/callback_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/component_ext_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/component_rb.html +109 -0
- data/doc/rdoc/files/lib/wee/context_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/core/callback_rb.html +115 -0
- data/doc/rdoc/files/lib/wee/core/component_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/core/decoration_rb.html +133 -0
- data/doc/rdoc/files/lib/wee/core/presenter_rb.html +112 -0
- data/doc/rdoc/files/lib/wee/core/snapshot_rb.html +113 -0
- data/doc/rdoc/files/lib/wee/core/valueholder_rb.html +110 -0
- data/doc/rdoc/files/lib/wee/core_rb.html +131 -0
- data/doc/rdoc/files/lib/wee/decoration_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/holder_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/html_canvas_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/html_writer_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/idgen_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/page_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/presenter_rb.html +112 -0
- data/doc/rdoc/files/lib/wee/renderer/html/brushes_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/renderer/html/canvas_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/renderer/html/writer_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/rendering/html/brushes_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/rendering/html/canvas_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/rendering/html/writer_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/request_rb.html +113 -0
- data/doc/rdoc/files/lib/wee/requesthandler_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/response_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/session_rb.html +109 -0
- data/doc/rdoc/files/lib/wee/snapshot_ext_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/snapshot_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/state_registry_rb.html +110 -0
- data/doc/rdoc/files/lib/wee/stuff_rb.html +144 -0
- data/doc/rdoc/files/lib/wee/utils/cache_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/webrick_rb.html +108 -0
- data/doc/rdoc/files/lib/wee_rb.html +132 -0
- data/doc/rdoc/fr_class_index.html +93 -0
- data/doc/rdoc/fr_file_index.html +51 -0
- data/doc/rdoc/fr_method_index.html +242 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/examples/ObjectSpaceBrowser.rb +199 -0
- data/examples/calendar.rb +366 -0
- data/examples/cc.rb +94 -0
- data/examples/draw.rb +91 -0
- data/examples/example.rb +223 -0
- data/examples/test.rb +66 -0
- data/examples/window.rb +53 -0
- data/lib/cache/cache.rb +9 -0
- data/lib/wee.rb +18 -8
- data/lib/wee/adaptors/webrick.rb +73 -0
- data/lib/wee/application.rb +69 -71
- data/lib/wee/context.rb +2 -12
- data/lib/wee/core.rb +15 -0
- data/lib/wee/core/callback.rb +108 -0
- data/lib/wee/core/component.rb +314 -0
- data/lib/wee/core/decoration.rb +129 -0
- data/lib/wee/core/presenter.rb +132 -0
- data/lib/wee/core/snapshot.rb +21 -0
- data/lib/wee/core/valueholder.rb +19 -0
- data/lib/wee/idgen.rb +13 -0
- data/lib/wee/page.rb +1 -1
- data/lib/wee/renderer/html/brushes.rb +435 -0
- data/lib/wee/renderer/html/canvas.rb +148 -0
- data/lib/wee/{html_writer.rb → renderer/html/writer.rb} +31 -16
- data/lib/wee/request.rb +57 -0
- data/lib/wee/requesthandler.rb +77 -0
- data/lib/wee/response.rb +77 -0
- data/lib/wee/session.rb +70 -64
- data/lib/wee/{snapshot.rb → snapshot_ext.rb} +4 -4
- data/test/components/calltest.rb +16 -0
- data/test/components/counter.rb +17 -0
- data/test/components/messagebox.rb +15 -0
- data/test/components/page.rb +14 -0
- data/test/components/page_decoration.rb +7 -0
- data/test/stress.rb +64 -0
- data/test/test_component.rb +106 -0
- data/test/test_html_canvas.rb +25 -0
- data/test/test_html_writer.rb +27 -0
- data/test/test_request.rb +13 -0
- data/test/utils/cross.rb +65 -0
- data/test/utils/generic_plotter.rb +28 -0
- data/test/utils/gnuplot.rb +31 -0
- data/test/utils/measure_memory.rb +9 -0
- data/test/utils/memory_plotter.rb +10 -0
- data/test/utils/object_plotter.rb +10 -0
- data/test/utils/webrick_background.rb +31 -0
- data/wee.gemspec +22 -0
- metadata +222 -18
- data/lib/wee/component.rb +0 -126
- data/lib/wee/delegate_decoration.rb +0 -22
- data/lib/wee/handler_registry.rb +0 -89
- data/lib/wee/holder.rb +0 -14
- data/lib/wee/html_canvas.rb +0 -379
- data/lib/wee/state_registry.rb +0 -173
- data/lib/wee/stuff.rb +0 -29
- data/lib/wee/webrick.rb +0 -15
data/examples/cc.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
$LOAD_PATH.unshift << "../lib"
|
2
|
+
require 'wee'
|
3
|
+
require 'wee/webrick'
|
4
|
+
require 'wee/utils/cache'
|
5
|
+
|
6
|
+
|
7
|
+
class MessageBox < Wee::Component
|
8
|
+
def initialize(text)
|
9
|
+
super()
|
10
|
+
@text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
r.break
|
15
|
+
r.text(@text)
|
16
|
+
r.form do
|
17
|
+
r.submit_button.value('OK').action(:answer, true)
|
18
|
+
r.space
|
19
|
+
r.submit_button.value('Cancel').action(:answer, false)
|
20
|
+
end
|
21
|
+
r.break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class MessageBox2 < Wee::Component
|
26
|
+
def initialize(text)
|
27
|
+
super()
|
28
|
+
@text = text
|
29
|
+
end
|
30
|
+
|
31
|
+
def render
|
32
|
+
r.break
|
33
|
+
r.text(@text)
|
34
|
+
r.form do
|
35
|
+
r.submit_button.value('OK')
|
36
|
+
r.space
|
37
|
+
r.submit_button.value('Cancel')
|
38
|
+
end
|
39
|
+
r.break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class MainPage < Wee::Component
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
super()
|
47
|
+
@msgbox = MessageBox2.new("hallllo")
|
48
|
+
children << @msgbox
|
49
|
+
end
|
50
|
+
|
51
|
+
def click
|
52
|
+
if call MessageBox.new('Really quit?')
|
53
|
+
call MessageBox.new('You clicked YES')
|
54
|
+
else
|
55
|
+
call MessageBox.new('You clicked Cancel')
|
56
|
+
call MessageBox.new('super')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def render
|
61
|
+
r.page.title("Draw Test").with do
|
62
|
+
|
63
|
+
r.break
|
64
|
+
r.anchor.action(:click).with('show')
|
65
|
+
r.render @msgbox
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class MySession < Wee::Session
|
72
|
+
def initialize
|
73
|
+
super do
|
74
|
+
self.root_component = MainPage.new
|
75
|
+
self.page_store = Wee::Utils::LRUCache.new(10) # backtrack up to 10 pages
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class MyApplication < Wee::Application
|
81
|
+
def shutdown
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if __FILE__ == $0
|
86
|
+
File.open('pid', 'w+') {|f| f << $$}
|
87
|
+
MyApplication.new {|app|
|
88
|
+
app.name = 'Counter'
|
89
|
+
app.path = '/app'
|
90
|
+
app.session_class = MySession
|
91
|
+
app.session_store = Wee::Utils::LRUCache.new(100)
|
92
|
+
app.dumpfile = ''
|
93
|
+
}.start
|
94
|
+
end
|
data/examples/draw.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
$LOAD_PATH.unshift << "../lib"
|
2
|
+
require 'wee'
|
3
|
+
require 'wee/webrick'
|
4
|
+
require 'wee/utils/cache'
|
5
|
+
require 'GD'
|
6
|
+
|
7
|
+
class MainPage < Wee::Component
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@points = []
|
11
|
+
session.register_object_for_backtracking(@points)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_image(points)
|
15
|
+
im = GD::Image.newTrueColor(200,200)
|
16
|
+
|
17
|
+
white = GD::Image.trueColor(255,255,255)
|
18
|
+
black = GD::Image.trueColor(0,0,0)
|
19
|
+
red = GD::Image.trueColor(255,0,0)
|
20
|
+
|
21
|
+
im.transparent(white)
|
22
|
+
im.filledRectangle(0,0,199,199,white)
|
23
|
+
im.rectangle(0,0,199,199,black)
|
24
|
+
|
25
|
+
points.each do |x,y|
|
26
|
+
im.filledRectangle(x,y,x+10,y+10, red)
|
27
|
+
end
|
28
|
+
|
29
|
+
im.pngStr
|
30
|
+
end
|
31
|
+
|
32
|
+
def clear
|
33
|
+
@points.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_request(context)
|
37
|
+
query = context.request.unparsed_uri.split('?').last
|
38
|
+
@x, @y = query.split(",").map {|i| i.to_i} if query
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO: move the above into method point (we need the current context,
|
43
|
+
# Session.current_context)
|
44
|
+
def draw_point
|
45
|
+
@points << [@x, @y]
|
46
|
+
end
|
47
|
+
|
48
|
+
def render
|
49
|
+
r.page.title("Draw Test").with do
|
50
|
+
|
51
|
+
ctx = r.context.context
|
52
|
+
img_id = ctx.handler_registry.handler_id_for_resource(
|
53
|
+
Wee::ResourceHandler.new(create_image(@points), 'image/png'))
|
54
|
+
|
55
|
+
img_url = ctx.application.gen_resource_url(ctx.session_id, ctx.page_id, img_id)
|
56
|
+
|
57
|
+
r.anchor.action(:draw_point).with {
|
58
|
+
r.image.src(img_url).ismap("")
|
59
|
+
}
|
60
|
+
|
61
|
+
r.break
|
62
|
+
r.anchor.action(:clear).with('Clear')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
class MySession < Wee::Session
|
69
|
+
def initialize
|
70
|
+
super do
|
71
|
+
self.root_component = MainPage.new
|
72
|
+
self.page_store = Wee::Utils::LRUCache.new(10) # backtrack up to 10 pages
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class MyApplication < Wee::Application
|
78
|
+
def shutdown
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if __FILE__ == $0
|
83
|
+
raise "this example does not work with the current version of Wee"
|
84
|
+
Wee::Application.new {|app|
|
85
|
+
app.name = 'Counter'
|
86
|
+
app.path = '/app'
|
87
|
+
app.session_class = MySession
|
88
|
+
app.session_store = Wee::Utils::LRUCache.new(1000) # handle up to 1000 sessions
|
89
|
+
app.dumpfile = ''
|
90
|
+
}.start
|
91
|
+
end
|
data/examples/example.rb
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
$LOAD_PATH.unshift << "../lib"
|
2
|
+
require 'wee'
|
3
|
+
require 'wee/utils/cache'
|
4
|
+
require 'window'
|
5
|
+
|
6
|
+
class Counter < Wee::Component
|
7
|
+
def initialize(cnt)
|
8
|
+
super()
|
9
|
+
@cnt = cnt
|
10
|
+
end
|
11
|
+
|
12
|
+
def backtrack_state(snap)
|
13
|
+
super
|
14
|
+
snap.add(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def dec
|
18
|
+
@cnt -= 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def inc
|
22
|
+
@cnt += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def render
|
26
|
+
r.anchor.callback { dec }.with("--")
|
27
|
+
r.space; r.text(@cnt.to_s); r.space
|
28
|
+
r.anchor.callback { inc }.with("++")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class MessageBox < Wee::Component
|
33
|
+
def initialize(text)
|
34
|
+
super()
|
35
|
+
@text = text
|
36
|
+
end
|
37
|
+
|
38
|
+
def render
|
39
|
+
r.break
|
40
|
+
r.text(@text)
|
41
|
+
r.form do
|
42
|
+
r.submit_button.value('OK').callback { answer true }
|
43
|
+
r.space
|
44
|
+
r.submit_button.value('Cancel').callback { answer false }
|
45
|
+
end
|
46
|
+
r.break
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class RegexpValidatedInput < Wee::Component
|
51
|
+
|
52
|
+
def initialize(init_value, regexp)
|
53
|
+
super()
|
54
|
+
@regexp = regexp
|
55
|
+
self.value = init_value
|
56
|
+
@error = false
|
57
|
+
end
|
58
|
+
|
59
|
+
def backtrack_state(snap)
|
60
|
+
super
|
61
|
+
snap.add(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def value
|
65
|
+
@value
|
66
|
+
end
|
67
|
+
|
68
|
+
def value=(new_value)
|
69
|
+
raise unless new_value =~ @regexp
|
70
|
+
@input = @value = new_value
|
71
|
+
end
|
72
|
+
|
73
|
+
def render
|
74
|
+
r.form do
|
75
|
+
r.text_input.value(@input).callback(:input=)
|
76
|
+
r.text %(<div style="color: red">Invalid input</div>) if @error
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def input
|
81
|
+
@input
|
82
|
+
end
|
83
|
+
|
84
|
+
def input=(str)
|
85
|
+
@input = str
|
86
|
+
|
87
|
+
if @input =~ @regexp
|
88
|
+
@value = str
|
89
|
+
@error = false
|
90
|
+
else
|
91
|
+
@error = true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
class EditableCounter < Counter
|
98
|
+
|
99
|
+
def initialize(cnt)
|
100
|
+
super
|
101
|
+
@show_edit_field = false
|
102
|
+
end
|
103
|
+
|
104
|
+
def render
|
105
|
+
#r.form.callback{submit}.with do
|
106
|
+
r.anchor.callback { dec }.with("--")
|
107
|
+
r.space
|
108
|
+
|
109
|
+
if @show_edit_field
|
110
|
+
r.text_input.callback{|@cnt|}.value(@cnt).size(6)
|
111
|
+
r.submit_button.callback{submit}.value('S')
|
112
|
+
else
|
113
|
+
r.anchor.callback{submit}.with(@cnt)
|
114
|
+
end
|
115
|
+
|
116
|
+
r.space
|
117
|
+
r.anchor.callback{inc}.with("++")
|
118
|
+
#end
|
119
|
+
end
|
120
|
+
|
121
|
+
def submit
|
122
|
+
if @cnt.to_s !~ /^\d+$/
|
123
|
+
call MessageBox.new("You entered an invalid counter! Please try again!")
|
124
|
+
@cnt = 0
|
125
|
+
else
|
126
|
+
@show_edit_field = !@show_edit_field
|
127
|
+
end
|
128
|
+
@cnt = @cnt.to_i
|
129
|
+
end
|
130
|
+
|
131
|
+
def cnt=(val)
|
132
|
+
@cnt = val
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
class MainPage < Wee::Component
|
138
|
+
def initialize
|
139
|
+
super()
|
140
|
+
@counters = (1..10).map {|i| Wee::Window.new("Cnt #{ i }", "#{i*10}px", EditableCounter.new(i))}
|
141
|
+
children.push(*@counters)
|
142
|
+
children << (@val_inp = RegexpValidatedInput.new('Michael Neumann', /^\w+\s+\w+$/))
|
143
|
+
|
144
|
+
@arr = []
|
145
|
+
@text = ""
|
146
|
+
|
147
|
+
@list1 = (0..9).to_a
|
148
|
+
@selected1 = []
|
149
|
+
@list2 = []
|
150
|
+
@selected2 = []
|
151
|
+
end
|
152
|
+
|
153
|
+
def backtrack_state(snap)
|
154
|
+
super
|
155
|
+
snap.add(@arr)
|
156
|
+
snap.add(@text)
|
157
|
+
|
158
|
+
snap.add(@list1)
|
159
|
+
snap.add(@selected1)
|
160
|
+
snap.add(@list2)
|
161
|
+
snap.add(@selected2)
|
162
|
+
end
|
163
|
+
|
164
|
+
attr_accessor :text
|
165
|
+
|
166
|
+
def render
|
167
|
+
r.page.title("Counter Test").with do
|
168
|
+
|
169
|
+
r.form do
|
170
|
+
r.select_list(@list1).size(10).multiple.selected(@selected1).callback {|choosen| @selected1.replace(choosen)}
|
171
|
+
r.submit_button.value('->').callback { @list2.push(*@selected1); @list1.replace(@list1-@selected1); @selected1.replace([]) }
|
172
|
+
r.submit_button.value('<-').callback { @list1.push(*@selected2); @list2.replace(@list2-@selected2); @selected2.replace([]) }
|
173
|
+
r.select_list(@list2).size(10).multiple.selected(@selected2).callback {|choosen| @selected2.replace(choosen)}
|
174
|
+
end
|
175
|
+
|
176
|
+
r.form do
|
177
|
+
|
178
|
+
@counters.each { |cnt|
|
179
|
+
r.render(cnt)
|
180
|
+
}
|
181
|
+
|
182
|
+
r.render(@val_inp)
|
183
|
+
|
184
|
+
@arr.each do |a|
|
185
|
+
r.text(a)
|
186
|
+
r.break
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
r.form do
|
192
|
+
r.text_input.value(@text).callback{|@text|}
|
193
|
+
r.submit_button.callback{add}.value('add')
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def add
|
200
|
+
if call(MessageBox.new("Do you really want to add '" + @text + "'?"))
|
201
|
+
@arr << @text if call(MessageBox.new("Do you really really really want to add '" + @text + "'?"))
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class MySession < Wee::Session
|
207
|
+
def initialize
|
208
|
+
super do
|
209
|
+
self.root_component = MainPage.new
|
210
|
+
self.page_store = Wee::Utils::LRUCache.new(10) # backtrack up to 10 pages
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
if __FILE__ == $0
|
216
|
+
app = Wee::Application.new {|app|
|
217
|
+
app.default_request_handler { MySession.new }
|
218
|
+
app.id_generator = Wee::SimpleIdGenerator.new(rand(1_000_000))
|
219
|
+
}
|
220
|
+
|
221
|
+
require 'wee/adaptors/webrick'
|
222
|
+
Wee::WEBrickAdaptor.register('/app' => app).start
|
223
|
+
end
|
data/examples/test.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
$LOAD_PATH.unshift << "../lib"
|
2
|
+
require 'wee'
|
3
|
+
require 'wee/webrick'
|
4
|
+
require 'wee/utils/cache'
|
5
|
+
|
6
|
+
|
7
|
+
class Counter < Wee::Component
|
8
|
+
def initialize(cnt)
|
9
|
+
super()
|
10
|
+
@cnt = cnt
|
11
|
+
session.register_object_for_backtracking(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def dec
|
15
|
+
@cnt -= 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def inc
|
19
|
+
@cnt += 1
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
r.anchor.action(:dec).with("--")
|
24
|
+
r.space; r.text(@cnt.to_s); r.space
|
25
|
+
r.anchor.action(:inc).with("++")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class MainPage < Wee::Component
|
30
|
+
def initialize
|
31
|
+
super
|
32
|
+
@counters = (1..10).map {|i| Counter.new(i)}
|
33
|
+
children.push(*@counters)
|
34
|
+
end
|
35
|
+
|
36
|
+
def render
|
37
|
+
r.page.title("Counter Test").with do
|
38
|
+
@counters.each { |cnt| r.render(cnt); r.break }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class MySession < Wee::Session
|
44
|
+
def initialize
|
45
|
+
super do
|
46
|
+
self.root_component = MainPage.new
|
47
|
+
self.page_store = Wee::Utils::LRUCache.new(10) # backtrack up to 10 pages
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if __FILE__ == $0
|
53
|
+
DUMP = 'dump'
|
54
|
+
|
55
|
+
if File.exists?(DUMP)
|
56
|
+
Wee::Application.load_from_disk(DUMP)
|
57
|
+
else
|
58
|
+
Wee::Application.new {|app|
|
59
|
+
app.name = 'Counter'
|
60
|
+
app.path = '/app'
|
61
|
+
app.session_class = MySession
|
62
|
+
app.session_store = Wee::Utils::LRUCache.new(1000) # handle up to 1000 sessions
|
63
|
+
app.dumpfile = DUMP
|
64
|
+
}
|
65
|
+
end.start
|
66
|
+
end
|