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
@@ -1,22 +0,0 @@
|
|
1
|
-
class Wee::Delegate
|
2
|
-
attr_accessor :next # next decoration in chain
|
3
|
-
|
4
|
-
def initialize(component)
|
5
|
-
@component = component
|
6
|
-
end
|
7
|
-
|
8
|
-
def process_request(context)
|
9
|
-
@component.decoration.process_request(context)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Creates a new renderer for this component and renders it.
|
13
|
-
def render_with_context(rendering_context)
|
14
|
-
r = renderer_class.new(rendering_context)
|
15
|
-
r.current_component = self
|
16
|
-
r.render(@component)
|
17
|
-
end
|
18
|
-
|
19
|
-
def renderer_class
|
20
|
-
Wee::HtmlCanvas
|
21
|
-
end
|
22
|
-
end
|
data/lib/wee/handler_registry.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
class Wee::ActionHandler
|
2
|
-
attr_accessor :obj, :meth, :args
|
3
|
-
|
4
|
-
def self.[](obj, meth, *args)
|
5
|
-
new(obj, meth, *args)
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(obj, meth, *args)
|
9
|
-
@obj, @meth, @args = obj, meth.to_s, args
|
10
|
-
end
|
11
|
-
|
12
|
-
def invoke
|
13
|
-
@obj.send(@meth, *@args)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Wee::ResourceHandler
|
18
|
-
attr_accessor :content, :content_type
|
19
|
-
def initialize(content, content_type)
|
20
|
-
@content, @content_type = content, content_type
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Wee::HandlerRegistry
|
25
|
-
def initialize
|
26
|
-
@next_handler_id = 1
|
27
|
-
@action_registry = Hash.new
|
28
|
-
@input_registry = Hash.new
|
29
|
-
@resource_registry = Hash.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def handler_id_for_action(action_handler)
|
33
|
-
hid = get_next_handler_id()
|
34
|
-
raise if @action_registry.has_key?(hid)
|
35
|
-
@action_registry[hid] = action_handler
|
36
|
-
return hid
|
37
|
-
end
|
38
|
-
|
39
|
-
def handler_id_for_input(obj, input)
|
40
|
-
hid = get_next_handler_id()
|
41
|
-
raise if @input_registry.has_key?(hid)
|
42
|
-
@input_registry[hid] = [obj, input.to_s]
|
43
|
-
return hid
|
44
|
-
end
|
45
|
-
|
46
|
-
def handler_id_for_resource(resource)
|
47
|
-
hid = get_next_handler_id()
|
48
|
-
raise if @resource_registry.has_key?(hid)
|
49
|
-
@resource_registry[hid] = resource
|
50
|
-
return hid
|
51
|
-
end
|
52
|
-
|
53
|
-
def get_action(handler_id, obj)
|
54
|
-
action_handler = @action_registry[handler_id]
|
55
|
-
return nil unless action_handler
|
56
|
-
|
57
|
-
if action_handler.obj == obj
|
58
|
-
action_handler
|
59
|
-
else
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def get_input(handler_id, obj)
|
65
|
-
return nil unless @input_registry.has_key?(handler_id)
|
66
|
-
|
67
|
-
component, input = @input_registry[handler_id]
|
68
|
-
|
69
|
-
if component == obj
|
70
|
-
input
|
71
|
-
else
|
72
|
-
nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def get_resource(handler_id)
|
77
|
-
return @resource_registry[handler_id]
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
# TODO: randomize
|
83
|
-
def get_next_handler_id
|
84
|
-
@next_handler_id.to_s
|
85
|
-
ensure
|
86
|
-
@next_handler_id += 1
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/lib/wee/holder.rb
DELETED
data/lib/wee/html_canvas.rb
DELETED
@@ -1,379 +0,0 @@
|
|
1
|
-
module Wee
|
2
|
-
|
3
|
-
class Canvas
|
4
|
-
def initialize
|
5
|
-
@parent_brush = nil
|
6
|
-
@current_brush = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
def set_brush(brush)
|
10
|
-
# tell previous brush to finish
|
11
|
-
@current_brush.close if @current_brush
|
12
|
-
|
13
|
-
brush.parent = @parent_brush
|
14
|
-
brush.canvas = self
|
15
|
-
@current_brush = brush
|
16
|
-
|
17
|
-
return brush
|
18
|
-
end
|
19
|
-
|
20
|
-
def nest(&block)
|
21
|
-
@parent_brush = @current_brush
|
22
|
-
@current_brush = nil
|
23
|
-
block.call
|
24
|
-
@current_brush.close if @current_brush
|
25
|
-
@parent_brush = @parent_brush.parent
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class HtmlCanvas < Canvas
|
30
|
-
attr_reader :context # the current Wee::RenderingContext
|
31
|
-
attr_reader :document
|
32
|
-
attr_accessor :current_component
|
33
|
-
|
34
|
-
def initialize(rendering_context)
|
35
|
-
@context = rendering_context
|
36
|
-
@document = rendering_context.document
|
37
|
-
end
|
38
|
-
|
39
|
-
def table(*args, &block)
|
40
|
-
handle(Brush::TableTag.new, *args, &block)
|
41
|
-
end
|
42
|
-
|
43
|
-
def table_row(*args, &block)
|
44
|
-
handle(Brush::TableRowTag.new, *args, &block)
|
45
|
-
end
|
46
|
-
|
47
|
-
def table_data(*args, &block)
|
48
|
-
handle(Brush::TableDataTag.new, *args, &block)
|
49
|
-
end
|
50
|
-
|
51
|
-
def table_header(*args, &block)
|
52
|
-
handle(Brush::TableHeaderTag.new, *args, &block)
|
53
|
-
end
|
54
|
-
|
55
|
-
def form(*args, &block)
|
56
|
-
handle(Brush::FormTag.new, *args, &block)
|
57
|
-
end
|
58
|
-
|
59
|
-
def input(*args, &block)
|
60
|
-
handle(Brush::InputTag.new, *args, &block)
|
61
|
-
end
|
62
|
-
|
63
|
-
def text_input(*args, &block)
|
64
|
-
handle(Brush::TextInputTag.new, *args, &block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def submit_button(*args, &block)
|
68
|
-
handle(Brush::SubmitButtonTag.new, *args, &block)
|
69
|
-
end
|
70
|
-
|
71
|
-
def page(*args, &block)
|
72
|
-
handle(Brush::Page.new, *args, &block)
|
73
|
-
end
|
74
|
-
|
75
|
-
def anchor(*args, &block)
|
76
|
-
handle(Brush::AnchorTag.new, *args, &block)
|
77
|
-
end
|
78
|
-
|
79
|
-
def space(n=1)
|
80
|
-
set_brush(Brush::GenericTextBrush.new(" "*n))
|
81
|
-
end
|
82
|
-
|
83
|
-
def break
|
84
|
-
set_brush(Brush::GenericTagBrush.new("br"))
|
85
|
-
end
|
86
|
-
|
87
|
-
def image
|
88
|
-
set_brush(Brush::GenericTagBrush.new("img"))
|
89
|
-
end
|
90
|
-
|
91
|
-
def text(str)
|
92
|
-
set_brush(Brush::GenericTextBrush.new(str))
|
93
|
-
end
|
94
|
-
alias << text
|
95
|
-
|
96
|
-
def render(obj)
|
97
|
-
obj.render_on(self)
|
98
|
-
nil
|
99
|
-
end
|
100
|
-
|
101
|
-
private
|
102
|
-
|
103
|
-
def handle(brush, *args, &block)
|
104
|
-
set_brush(brush)
|
105
|
-
if not args.empty? or block
|
106
|
-
brush.with(*args, &block)
|
107
|
-
else
|
108
|
-
brush
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class Brush
|
114
|
-
attr_accessor :parent, :canvas
|
115
|
-
|
116
|
-
def with(*args, &block)
|
117
|
-
raise "either args or block, but not both" if block and not args.empty?
|
118
|
-
|
119
|
-
@canvas.nest(&block) if block
|
120
|
-
@closed = true
|
121
|
-
end
|
122
|
-
|
123
|
-
def close
|
124
|
-
with unless @closed
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class Brush::GenericTextBrush < Brush
|
129
|
-
def initialize(text)
|
130
|
-
@text = text
|
131
|
-
end
|
132
|
-
|
133
|
-
def with
|
134
|
-
doc = @canvas.document
|
135
|
-
doc << @text
|
136
|
-
super
|
137
|
-
nil
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
class Brush::GenericTagBrush < Brush
|
142
|
-
def initialize(tag)
|
143
|
-
@tag = tag
|
144
|
-
@attributes = Hash.new
|
145
|
-
end
|
146
|
-
|
147
|
-
def id(x)
|
148
|
-
@attributes["id"] = x
|
149
|
-
self
|
150
|
-
end
|
151
|
-
|
152
|
-
def method_missing(m, arg)
|
153
|
-
@attributes[m.to_s] = arg.to_s
|
154
|
-
self
|
155
|
-
end
|
156
|
-
|
157
|
-
def with(text=nil, &block)
|
158
|
-
doc = @canvas.document
|
159
|
-
doc.start_tag(@tag, @attributes)
|
160
|
-
if text
|
161
|
-
doc.text(text)
|
162
|
-
super(text, &block)
|
163
|
-
else
|
164
|
-
super(&block)
|
165
|
-
end
|
166
|
-
doc.end_tag(@tag)
|
167
|
-
nil
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
class Brush::TableTag < Brush::GenericTagBrush
|
172
|
-
def initialize
|
173
|
-
super('table')
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
class Brush::TableRowTag < Brush::GenericTagBrush
|
178
|
-
def initialize
|
179
|
-
super('tr')
|
180
|
-
end
|
181
|
-
|
182
|
-
def align_top
|
183
|
-
@attributes['align'] = 'top'
|
184
|
-
self
|
185
|
-
end
|
186
|
-
|
187
|
-
def columns(*cols)
|
188
|
-
with {
|
189
|
-
cols.each {|col| @canvas.table_data(col) }
|
190
|
-
}
|
191
|
-
end
|
192
|
-
|
193
|
-
def headings(*headers)
|
194
|
-
with {
|
195
|
-
headers.each {|head| @canvas.table_heading(head) }
|
196
|
-
}
|
197
|
-
end
|
198
|
-
|
199
|
-
def spanning_column(str, colspan)
|
200
|
-
with {
|
201
|
-
@canvas.table_data.col_span(colspan).with(str)
|
202
|
-
}
|
203
|
-
end
|
204
|
-
|
205
|
-
def spacer
|
206
|
-
with {
|
207
|
-
@canvas.table_data { @canvas.space }
|
208
|
-
}
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
class Brush::InputTag < Brush::GenericTagBrush
|
214
|
-
def initialize
|
215
|
-
super('input')
|
216
|
-
end
|
217
|
-
|
218
|
-
%w(type name value size maxlength checked src).each do |meth|
|
219
|
-
eval %[
|
220
|
-
def #{ meth }(arg)
|
221
|
-
@attributes['#{ meth }'] = arg
|
222
|
-
self
|
223
|
-
end
|
224
|
-
]
|
225
|
-
end
|
226
|
-
|
227
|
-
def with
|
228
|
-
super
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
class Brush::TextInputTag < Brush::InputTag
|
233
|
-
def initialize
|
234
|
-
super
|
235
|
-
type('text')
|
236
|
-
end
|
237
|
-
|
238
|
-
def attr(attr_name)
|
239
|
-
assign(attr_name.to_s + "=")
|
240
|
-
value(@canvas.current_component.send(attr_name))
|
241
|
-
self
|
242
|
-
end
|
243
|
-
|
244
|
-
def assign(act, obj=nil)
|
245
|
-
ctx = @canvas.context.context
|
246
|
-
obj ||= @canvas.current_component
|
247
|
-
|
248
|
-
name(ctx.handler_registry.handler_id_for_input(obj, act))
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
class Brush::SubmitButtonTag < Brush::InputTag
|
253
|
-
def initialize
|
254
|
-
super
|
255
|
-
type('submit')
|
256
|
-
end
|
257
|
-
|
258
|
-
# TODO: action for another object
|
259
|
-
def action(act, *args)
|
260
|
-
ctx = @canvas.context.context
|
261
|
-
obj = @canvas.current_component
|
262
|
-
|
263
|
-
name(ctx.handler_registry.handler_id_for_action(Wee::ActionHandler[obj, act, *args]))
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
class Brush::TableDataTag < Brush::GenericTagBrush
|
268
|
-
def initialize
|
269
|
-
super('td')
|
270
|
-
end
|
271
|
-
|
272
|
-
def align_top
|
273
|
-
@attributes['align'] = 'top'
|
274
|
-
self
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
class Brush::TableHeaderTag < Brush::GenericTagBrush
|
279
|
-
def initialize
|
280
|
-
super('th')
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
module Brush::ActionMixin
|
285
|
-
# TODO: action for another object
|
286
|
-
def action(act, *args)
|
287
|
-
ctx = @canvas.context.context
|
288
|
-
obj = @canvas.current_component
|
289
|
-
href = ctx.application.gen_handler_url(ctx.session_id, ctx.page_id,
|
290
|
-
act ? ctx.handler_registry.handler_id_for_action(Wee::ActionHandler[obj, act, *args]) : '')
|
291
|
-
__action(href)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
class Brush::FormTag < Brush::GenericTagBrush
|
296
|
-
include Brush::ActionMixin
|
297
|
-
|
298
|
-
def initialize
|
299
|
-
super('form')
|
300
|
-
@attributes['method'] = 'POST'
|
301
|
-
end
|
302
|
-
|
303
|
-
def __action(href)
|
304
|
-
@attributes['action'] = href
|
305
|
-
self
|
306
|
-
end
|
307
|
-
|
308
|
-
def with(*args, &block)
|
309
|
-
action(nil) unless @attributes.has_key?('action')
|
310
|
-
super
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
class Brush::AnchorTag < Brush::GenericTagBrush
|
315
|
-
include Brush::ActionMixin
|
316
|
-
|
317
|
-
def initialize
|
318
|
-
super('a')
|
319
|
-
end
|
320
|
-
|
321
|
-
def url(href)
|
322
|
-
@attributes['href'] = href
|
323
|
-
self
|
324
|
-
end
|
325
|
-
|
326
|
-
alias __action url
|
327
|
-
end
|
328
|
-
|
329
|
-
|
330
|
-
class Brush::Page < Brush
|
331
|
-
def title(str)
|
332
|
-
@title = str
|
333
|
-
self
|
334
|
-
end
|
335
|
-
|
336
|
-
def with(text=nil, &block)
|
337
|
-
doc = @canvas.document
|
338
|
-
doc.start_tag("html")
|
339
|
-
|
340
|
-
if @title
|
341
|
-
doc.start_tag("head")
|
342
|
-
doc.start_tag("title")
|
343
|
-
doc.text(@title)
|
344
|
-
doc.end_tag("title")
|
345
|
-
doc.end_tag("head")
|
346
|
-
end
|
347
|
-
|
348
|
-
doc.start_tag("body")
|
349
|
-
|
350
|
-
if text
|
351
|
-
doc.text(text)
|
352
|
-
super(text, &block)
|
353
|
-
else
|
354
|
-
super(&block)
|
355
|
-
end
|
356
|
-
|
357
|
-
doc.end_tag("body")
|
358
|
-
doc.end_tag("html")
|
359
|
-
nil
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
end # module Wee
|
364
|
-
|
365
|
-
if __FILE__ == $0
|
366
|
-
require 'html_writer'
|
367
|
-
|
368
|
-
doc = Wee::HtmlWriter.new('')
|
369
|
-
c = Wee::HtmlCanvas.new(nil, doc)
|
370
|
-
c.form.url("foo").with {
|
371
|
-
c.table {
|
372
|
-
c.table_row.id("myrow").with {
|
373
|
-
c.table_data.align_top.with("Hello world")
|
374
|
-
}
|
375
|
-
}
|
376
|
-
c.space
|
377
|
-
}
|
378
|
-
puts doc.port
|
379
|
-
end
|