wee 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +132 -0
- data/INSTALL +13 -3
- data/README +3 -3
- data/Rakefile +5 -1
- data/bin/wee +100 -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/Main.html +265 -0
- data/doc/rdoc/classes/Object.html +12 -12
- data/doc/rdoc/classes/OgApplication.html +2 -2
- data/doc/rdoc/classes/OgScaffolder.html +444 -64
- data/doc/rdoc/classes/OgScaffolder/Editor.html +490 -0
- data/doc/rdoc/classes/OgSession.html +4 -4
- data/doc/rdoc/classes/Recipe.html +113 -0
- data/doc/rdoc/classes/String.html +12 -12
- data/doc/rdoc/classes/Struct.html +12 -12
- data/doc/rdoc/classes/Wee.html +10 -1
- data/doc/rdoc/classes/Wee/AnswerDecoration.html +9 -9
- data/doc/rdoc/classes/Wee/Application.html +48 -47
- data/doc/rdoc/classes/Wee/Brush.html +19 -23
- data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +17 -14
- data/doc/rdoc/classes/Wee/Brush/FileUploadTag.html +20 -14
- data/doc/rdoc/classes/Wee/Brush/FormTag.html +25 -21
- 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 +234 -100
- data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +12 -12
- data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +28 -22
- data/doc/rdoc/classes/Wee/Brush/ImageTag.html +23 -24
- 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/SelectListTag.html +33 -57
- data/doc/rdoc/classes/Wee/Brush/SelectListTag/SelectListCallback.html +154 -0
- data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +7 -7
- data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +20 -14
- 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 +27 -21
- data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +20 -14
- data/doc/rdoc/classes/Wee/CallbackRegistry.html +64 -36
- data/doc/rdoc/classes/Wee/CallbackStream.html +21 -21
- data/doc/rdoc/classes/Wee/Canvas.html +24 -24
- data/doc/rdoc/classes/Wee/Component.html +179 -151
- data/doc/rdoc/classes/Wee/Component/OnAnswer.html +12 -12
- 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 +14 -14
- data/doc/rdoc/classes/Wee/FormDecoration.html +6 -6
- data/doc/rdoc/classes/Wee/GenericResponse.html +7 -7
- data/doc/rdoc/classes/Wee/HtmlCanvas.html +326 -219
- data/doc/rdoc/classes/Wee/HtmlWriter.html +40 -40
- data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +19 -19
- data/doc/rdoc/classes/Wee/Md5IdGenerator.html +181 -0
- data/doc/rdoc/classes/Wee/MessageBox.html +12 -12
- data/doc/rdoc/classes/Wee/PageDecoration.html +18 -18
- data/doc/rdoc/classes/Wee/PagelessApplication.html +152 -0
- data/doc/rdoc/classes/Wee/PagelessRequest.html +177 -0
- data/doc/rdoc/classes/Wee/PagelessSession.html +320 -0
- data/doc/rdoc/classes/Wee/Presenter.html +145 -89
- data/doc/rdoc/classes/Wee/RedirectResponse.html +7 -7
- data/doc/rdoc/classes/Wee/RefreshResponse.html +7 -7
- data/doc/rdoc/classes/Wee/Request.html +116 -50
- data/doc/rdoc/classes/Wee/RequestHandler.html +31 -31
- data/doc/rdoc/classes/Wee/Response.html +76 -28
- data/doc/rdoc/classes/Wee/Session.html +129 -506
- data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +22 -40
- data/doc/rdoc/classes/Wee/Snapshot.html +19 -19
- data/doc/rdoc/classes/Wee/Utils.html +70 -17
- data/doc/rdoc/classes/Wee/Utils/LRUCache.html +6 -6
- data/doc/rdoc/classes/Wee/ValueHolder.html +18 -18
- data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +82 -49
- data/doc/rdoc/classes/Wee/WrapperDecoration.html +6 -6
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/INSTALL.html +17 -5
- data/doc/rdoc/files/README.html +9 -11
- 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/page_decoration_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/continuation/session_rb.html +1 -3
- 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_rb.html +3 -3
- data/doc/rdoc/files/lib/wee/databases/og/application_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/databases/og/old_scaffolder_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/databases/og/scaffolder_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/databases/og/session_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/databases/og_rb.html +4 -1
- data/doc/rdoc/files/lib/wee/idgen/md5_rb.html +115 -0
- data/doc/rdoc/files/lib/wee/idgen/simple_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/pageless/application_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/pageless/request_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/pageless/session_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/pageless_rb.html +110 -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 +8 -1
- data/doc/rdoc/files/lib/wee/request_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/response_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/session_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/skeleton/og/components/main_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/skeleton/og/conf/db_rb.html +114 -0
- data/doc/rdoc/files/lib/wee/skeleton/og/models/recipe_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/skeleton/og/run_rb.html +115 -0
- data/doc/rdoc/files/lib/wee/skeleton/simple/components/main_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/skeleton/simple/run_rb.html +111 -0
- data/doc/rdoc/files/lib/wee/template_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/utils/autoreload_rb.html +1 -1
- data/doc/rdoc/files/lib/wee/utils/helper_rb.html +1 -1
- data/doc/rdoc/files/lib/wee_rb.html +4 -2
- data/doc/rdoc/fr_class_index.html +8 -4
- data/doc/rdoc/fr_file_index.html +17 -1
- data/doc/rdoc/fr_method_index.html +312 -267
- data/examples/live-update.rb +1 -1
- data/install.rb +14 -0
- data/lib/wee.rb +6 -2
- data/lib/wee/adaptors/webrick.rb +17 -5
- data/lib/wee/application.rb +2 -1
- data/lib/wee/continuation/session.rb +1 -146
- data/lib/wee/core/callback.rb +11 -5
- data/lib/wee/core/component.rb +14 -10
- data/lib/wee/databases/og.rb +3 -113
- data/lib/wee/databases/og/application.rb +3 -0
- data/lib/wee/databases/og/old_scaffolder.rb +98 -0
- data/lib/wee/databases/og/scaffolder.rb +174 -0
- data/lib/wee/databases/og/session.rb +9 -0
- data/lib/wee/idgen/md5.rb +21 -0
- data/lib/wee/{idgen.rb → idgen/simple.rb} +2 -4
- data/lib/wee/pageless.rb +3 -0
- data/lib/wee/pageless/application.rb +9 -0
- data/lib/wee/pageless/request.rb +15 -0
- data/lib/wee/pageless/session.rb +89 -0
- data/lib/wee/renderer/html/brushes.rb +100 -115
- data/lib/wee/renderer/html/canvas.rb +32 -2
- data/lib/wee/request.rb +36 -24
- data/lib/wee/response.rb +8 -1
- data/lib/wee/session.rb +13 -7
- data/lib/wee/skeleton/og/README +38 -0
- data/lib/wee/skeleton/og/components/main.rb +16 -0
- data/lib/wee/skeleton/og/conf/db.rb +8 -0
- data/lib/wee/skeleton/og/models/recipe.rb +5 -0
- data/lib/wee/skeleton/og/run.rb +23 -0
- data/lib/wee/skeleton/simple/README +32 -0
- data/lib/wee/skeleton/simple/components/main.rb +25 -0
- data/lib/wee/skeleton/simple/run.rb +12 -0
- data/lib/wee/template.rb +28 -0
- data/lib/wee/utils/autoreload.rb +29 -0
- data/lib/wee/utils/helper.rb +9 -5
- data/test/test_request.rb +4 -3
- data/wee.gemspec +3 -1
- metadata +91 -22
data/examples/live-update.rb
CHANGED
@@ -30,7 +30,7 @@ class LiveUpdateTest < Wee::Component
|
|
30
30
|
# simply omit this and just return the response with some html/xml filled
|
31
31
|
# in.
|
32
32
|
rendering_context = Wee::RenderingContext.new(context.request,
|
33
|
-
context.response, session.
|
33
|
+
context.response, session.current_callbacks,
|
34
34
|
Wee::HtmlWriter.new(response.content))
|
35
35
|
|
36
36
|
with_renderer_for(rendering_context) do
|
data/install.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'ftools'
|
3
|
+
|
4
|
+
# Install lib
|
5
|
+
dst_dir = Config::CONFIG['sitelibdir']
|
6
|
+
Dir.chdir('lib') {
|
7
|
+
Dir['**/*'].reject {|f| f =~ /\.svn($|\/)/ or not File.file?(f) }.each {|file|
|
8
|
+
File.mkpath File.join(dst_dir, File.dirname(file)), true
|
9
|
+
File.install file, File.join(dst_dir, file), 0644, true
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
# Install bin
|
14
|
+
File.install 'bin/wee', File.join(Config::CONFIG['bindir'], 'wee'), 0755, true
|
data/lib/wee.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Wee
|
2
|
-
Version = "0.
|
2
|
+
Version = "0.6.0"
|
3
|
+
LibPath = File.dirname(__FILE__)
|
3
4
|
end
|
4
5
|
|
5
6
|
require 'wee/core'
|
@@ -14,9 +15,12 @@ require 'wee/session'
|
|
14
15
|
require 'wee/components'
|
15
16
|
require 'wee/snapshot_ext'
|
16
17
|
|
18
|
+
require 'wee/template'
|
19
|
+
|
17
20
|
require 'wee/renderer/html/writer'
|
18
21
|
require 'wee/renderer/html/brushes'
|
19
22
|
require 'wee/renderer/html/canvas'
|
20
23
|
Wee::DefaultRenderer = Wee::HtmlCanvas
|
21
24
|
|
22
|
-
require 'wee/idgen'
|
25
|
+
require 'wee/idgen/simple'
|
26
|
+
require 'wee/idgen/md5'
|
data/lib/wee/adaptors/webrick.rb
CHANGED
@@ -13,6 +13,7 @@ require 'webrick'
|
|
13
13
|
#
|
14
14
|
# require 'wee/adaptors/webrick'
|
15
15
|
# Wee::WEBrickAdaptor.
|
16
|
+
# request_class(Wee::Request). # this is the default!
|
16
17
|
# register('/app' => application).
|
17
18
|
# register('/cnt' => application2).
|
18
19
|
# mount('/', WEBrick::HTTPServlet::FileHandler, '.').
|
@@ -28,8 +29,8 @@ class Wee::WEBrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
|
|
28
29
|
server = WEBrick::HTTPServer.new({:Port => 2000}.update(options))
|
29
30
|
trap("INT") { server.shutdown }
|
30
31
|
|
31
|
-
(@apps||[]).each do |path, app|
|
32
|
-
server.mount(path, self, path, app)
|
32
|
+
(@apps||[]).each do |path, app, request_class|
|
33
|
+
server.mount(path, self, path, app, request_class)
|
33
34
|
end
|
34
35
|
|
35
36
|
(@mounts||[]).each do |args, block|
|
@@ -42,11 +43,18 @@ class Wee::WEBrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
|
|
42
43
|
server
|
43
44
|
end
|
44
45
|
|
46
|
+
# Sets the used request_class for all following calls to #register
|
47
|
+
|
48
|
+
def self.request_class(request_class)
|
49
|
+
@request_class = request_class
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
45
53
|
# Convenience method
|
46
54
|
def self.register(hash)
|
47
55
|
@apps ||= []
|
48
56
|
hash.each do |path, application|
|
49
|
-
@apps << [path, application]
|
57
|
+
@apps << [path, application, @request_class]
|
50
58
|
end
|
51
59
|
self
|
52
60
|
end
|
@@ -58,18 +66,22 @@ class Wee::WEBrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
|
|
58
66
|
self
|
59
67
|
end
|
60
68
|
|
61
|
-
def initialize(server, mount_path, application)
|
69
|
+
def initialize(server, mount_path, application, request_class=Wee::Request)
|
62
70
|
super(server)
|
63
71
|
@mount_path = mount_path
|
64
72
|
@application = application
|
73
|
+
@request_class = request_class || Wee::Request
|
65
74
|
end
|
66
75
|
|
67
76
|
def handle_request(req, res)
|
68
|
-
context = Wee::Context.new(
|
77
|
+
context = Wee::Context.new(@request_class.new(@mount_path, req.path, req.header, req.query, req.cookies))
|
69
78
|
@application.handle_request(context)
|
70
79
|
res.status = context.response.status
|
71
80
|
res.body = context.response.content
|
72
81
|
context.response.header.each { |k,v| res.header[k] = v }
|
82
|
+
if context.response.cookies?
|
83
|
+
context.response.cookies.each {|c| res.cookies << c }
|
84
|
+
end
|
73
85
|
end
|
74
86
|
|
75
87
|
alias do_GET handle_request
|
data/lib/wee/application.rb
CHANGED
@@ -76,7 +76,8 @@ class Wee::Application
|
|
76
76
|
@request_handlers[request_handler_id] = request_handler
|
77
77
|
}
|
78
78
|
|
79
|
-
context.
|
79
|
+
context.request.request_handler_id = request_handler_id
|
80
|
+
handle_request(context)
|
80
81
|
return
|
81
82
|
|
82
83
|
elsif request_handler.nil?
|
@@ -1,16 +1,6 @@
|
|
1
|
-
require 'wee/page'
|
2
|
-
require 'thread'
|
3
1
|
require 'timeout'
|
4
2
|
|
5
|
-
class Wee::Session
|
6
|
-
attr_accessor :root_component, :page_store
|
7
|
-
|
8
|
-
def self.current
|
9
|
-
sess = Thread.current[:wee_session]
|
10
|
-
raise "not in session" if sess.nil?
|
11
|
-
return sess
|
12
|
-
end
|
13
|
-
|
3
|
+
class Wee::Session
|
14
4
|
def initialize(&block)
|
15
5
|
Thread.current[:wee_session] = self
|
16
6
|
|
@@ -30,11 +20,6 @@ class Wee::Session < Wee::RequestHandler
|
|
30
20
|
Thread.current[:wee_session] = nil
|
31
21
|
end
|
32
22
|
|
33
|
-
def snapshot
|
34
|
-
@root_component.backtrack_state_chain(snap = Wee::Snapshot.new)
|
35
|
-
return snap.freeze
|
36
|
-
end
|
37
|
-
|
38
23
|
# called by application to send the session a request
|
39
24
|
def handle_request(context)
|
40
25
|
super
|
@@ -84,134 +69,4 @@ class Wee::Session < Wee::RequestHandler
|
|
84
69
|
}
|
85
70
|
end
|
86
71
|
|
87
|
-
def create_page(snapshot)
|
88
|
-
idgen = Wee::SimpleIdGenerator.new
|
89
|
-
page = Wee::Page.new(snapshot, Wee::CallbackRegistry.new(idgen))
|
90
|
-
end
|
91
|
-
|
92
|
-
# Is called before process_request is invoked
|
93
|
-
# Can be used to setup e.g. a database connection.
|
94
|
-
def awake
|
95
|
-
end
|
96
|
-
|
97
|
-
# Is called after process_request is run
|
98
|
-
# Can be used to release e.g. a database connection.
|
99
|
-
def sleep
|
100
|
-
end
|
101
|
-
|
102
|
-
def process_request
|
103
|
-
if @context.request.page_id.nil?
|
104
|
-
|
105
|
-
# No page_id was specified in the URL. This means that we start with a
|
106
|
-
# fresh component and a fresh page_id, then redirect to render itself.
|
107
|
-
|
108
|
-
handle_new_page_view(@context, @initial_snapshot)
|
109
|
-
|
110
|
-
elsif @page = @page_store.fetch(@context.request.page_id, false)
|
111
|
-
|
112
|
-
# A valid page_id was specified and the corresponding page exists.
|
113
|
-
|
114
|
-
@page.snapshot.restore
|
115
|
-
|
116
|
-
p @context.request.fields if $DEBUG
|
117
|
-
|
118
|
-
if @context.request.fields.empty?
|
119
|
-
|
120
|
-
# No action/inputs were specified -> render page
|
121
|
-
#
|
122
|
-
# 1. Reset the action/input fields (as they are regenerated in the
|
123
|
-
# rendering process).
|
124
|
-
# 2. Render the page (respond).
|
125
|
-
# 3. Store the page back into the store
|
126
|
-
|
127
|
-
@page = create_page(@page.snapshot) # remove all action/input handlers
|
128
|
-
respond(@context, @page.callbacks) # render
|
129
|
-
@page_store[@context.request.page_id] = @page # store
|
130
|
-
|
131
|
-
else
|
132
|
-
|
133
|
-
# Actions/inputs were specified.
|
134
|
-
#
|
135
|
-
# We process the request and invoke actions/inputs. Then we generate a
|
136
|
-
# new page view.
|
137
|
-
|
138
|
-
callback_stream = Wee::CallbackStream.new(@page.callbacks, @context.request.fields)
|
139
|
-
|
140
|
-
if callback_stream.all_of_type(:action).size > 1
|
141
|
-
raise "Not allowed to specify more than one action callback"
|
142
|
-
end
|
143
|
-
|
144
|
-
live_update_response = catch(:wee_live_update) {
|
145
|
-
catch(:wee_back_to_session) {
|
146
|
-
@root_component.process_callbacks_chain(callback_stream)
|
147
|
-
}
|
148
|
-
nil
|
149
|
-
}
|
150
|
-
|
151
|
-
if live_update_response
|
152
|
-
# replace existing page with new snapshot
|
153
|
-
@page.snapshot = self.snapshot
|
154
|
-
@page_store[@context.request.page_id] = @page
|
155
|
-
@context.response = live_update_response
|
156
|
-
else
|
157
|
-
handle_new_page_view(@context)
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
else
|
163
|
-
|
164
|
-
# A page_id was specified in the URL, but there's no page for it in the
|
165
|
-
# page store. Either the page has timed out, or an invalid page_id was
|
166
|
-
# specified.
|
167
|
-
#
|
168
|
-
# TODO:: Display an "invalid page or page timed out" message, which
|
169
|
-
# forwards to /app/session-id
|
170
|
-
|
171
|
-
raise "Not yet implemented"
|
172
|
-
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def current_context
|
177
|
-
@context
|
178
|
-
end
|
179
|
-
|
180
|
-
def current_page
|
181
|
-
@page
|
182
|
-
end
|
183
|
-
|
184
|
-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
185
|
-
# :section: Properties
|
186
|
-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
187
|
-
|
188
|
-
attr_accessor :properties
|
189
|
-
|
190
|
-
# Returns an "owned" property for the given +klass+.
|
191
|
-
|
192
|
-
def get_property(prop, klass)
|
193
|
-
if @properties
|
194
|
-
@properties.fetch(klass, {})[prop]
|
195
|
-
else
|
196
|
-
nil
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
private
|
201
|
-
|
202
|
-
def handle_new_page_view(context, snapshot=nil)
|
203
|
-
new_page_id = @idgen.next.to_s
|
204
|
-
new_page = create_page(snapshot || self.snapshot())
|
205
|
-
@page_store[new_page_id] = new_page
|
206
|
-
redirect_url = context.request.build_url(context.request.request_handler_id, new_page_id)
|
207
|
-
context.response = Wee::RedirectResponse.new(redirect_url)
|
208
|
-
end
|
209
|
-
|
210
|
-
def respond(context, callbacks)
|
211
|
-
context.response = Wee::GenericResponse.new('text/html', '')
|
212
|
-
|
213
|
-
rctx = Wee::RenderingContext.new(context.request, context.response, callbacks, Wee::HtmlWriter.new(context.response.content))
|
214
|
-
@root_component.do_render_chain(rctx)
|
215
|
-
end
|
216
|
-
|
217
72
|
end
|
data/lib/wee/core/callback.rb
CHANGED
@@ -17,9 +17,15 @@ class Wee::CallbackRegistry
|
|
17
17
|
# Register +callback+ for +object+ under +type+ and return a unique callback id.
|
18
18
|
|
19
19
|
def register_for(object, type, callback)
|
20
|
+
register_named_for(object, type, callback, @idgen.next)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Register +callback+ for +object+ under +type+ with the id +named_id+.
|
24
|
+
|
25
|
+
def register_named_for(object, type, callback, named_id)
|
26
|
+
cid = named_id.to_s
|
20
27
|
c = (@callbacks[type] ||= Hash.new)
|
21
28
|
o = (@obj_to_id_map[type] ||= Hash.new)
|
22
|
-
cid = @idgen.next.to_s
|
23
29
|
raise "duplicate callback id" if c.has_key?(cid)
|
24
30
|
c[cid] = callback
|
25
31
|
(o[object] ||= []) << cid
|
@@ -98,14 +104,14 @@ end
|
|
98
104
|
|
99
105
|
# A serializable callback.
|
100
106
|
class Wee::LiteralMethodCallback
|
101
|
-
def initialize(obj, method_id=:call, *
|
107
|
+
def initialize(obj, method_id=:call, *args)
|
102
108
|
@obj, @method_id = obj, method_id
|
103
|
-
@
|
109
|
+
@args = args unless args.empty?
|
104
110
|
end
|
105
111
|
|
106
112
|
def call(*args)
|
107
|
-
if @
|
108
|
-
@obj.send(@method_id, *(args
|
113
|
+
if @args
|
114
|
+
@obj.send(@method_id, *(@args+args))
|
109
115
|
else
|
110
116
|
@obj.send(@method_id, *args)
|
111
117
|
end
|
data/lib/wee/core/component.rb
CHANGED
@@ -152,6 +152,8 @@ class Wee::Component < Wee::Presenter
|
|
152
152
|
# A global decoration is added in front of the decoration chain, a local
|
153
153
|
# decoration is added in front of all other local decorations but after all
|
154
154
|
# global decorations.
|
155
|
+
#
|
156
|
+
# Returns: +self+
|
155
157
|
|
156
158
|
def add_decoration(d)
|
157
159
|
if d.global?
|
@@ -176,6 +178,8 @@ class Wee::Component < Wee::Presenter
|
|
176
178
|
last_global.owner = d
|
177
179
|
end
|
178
180
|
end
|
181
|
+
|
182
|
+
return self
|
179
183
|
end
|
180
184
|
|
181
185
|
# Remove decoration +d+ from the decoration chain.
|
@@ -288,13 +292,12 @@ class Wee::Component < Wee::Presenter
|
|
288
292
|
# Either a symbol or any object that responds to #call. If it's a symbol,
|
289
293
|
# then the corresponding method of the current component will be called.
|
290
294
|
#
|
291
|
-
# [+
|
292
|
-
#
|
293
|
-
#
|
295
|
+
# [+args+]
|
296
|
+
# Arguments that are passed to the +return_callback+ before the 'onanswer'
|
297
|
+
# arguments.
|
294
298
|
#
|
295
299
|
# <b>How it works</b>
|
296
300
|
#
|
297
|
-
|
298
301
|
# The component to be called is wrapped with an AnswerDecoration and the
|
299
302
|
# +return_callback+ parameter is assigned to it's +on_answer+ attribute (not
|
300
303
|
# directly as there are cleanup actions to be taken before the
|
@@ -313,26 +316,27 @@ class Wee::Component < Wee::Presenter
|
|
313
316
|
# AnswerDecoration. The AnswerDecoration then invokes the +on_answer+
|
314
317
|
# callback which cleans up the decorations we added during #call, and finally
|
315
318
|
# passes control to the +return_callback+.
|
319
|
+
#
|
316
320
|
|
317
|
-
def call(component, return_callback=nil, *
|
321
|
+
def call(component, return_callback=nil, *args)
|
318
322
|
add_decoration(delegate = Wee::Delegate.new(component))
|
319
323
|
component.add_decoration(answer = Wee::AnswerDecoration.new)
|
320
324
|
answer.on_answer = OnAnswer.new(self, component, delegate, answer,
|
321
|
-
return_callback,
|
325
|
+
return_callback, args)
|
322
326
|
throw :wee_back_to_session
|
323
327
|
end
|
324
328
|
|
325
329
|
class OnAnswer < Struct.new(:calling_component, :called_component, :delegate,
|
326
|
-
:answer, :return_callback, :
|
330
|
+
:answer, :return_callback, :args)
|
327
331
|
|
328
|
-
def call(*
|
332
|
+
def call(*answer_args)
|
329
333
|
calling_component.remove_decoration(delegate)
|
330
334
|
called_component.remove_decoration(answer)
|
331
335
|
return if return_callback.nil?
|
332
336
|
if return_callback.respond_to?(:call)
|
333
|
-
return_callback.call(*(args +
|
337
|
+
return_callback.call(*(args + answer_args))
|
334
338
|
else
|
335
|
-
calling_component.send(return_callback, *(args +
|
339
|
+
calling_component.send(return_callback, *(args + answer_args))
|
336
340
|
end
|
337
341
|
end
|
338
342
|
end
|
data/lib/wee/databases/og.rb
CHANGED
@@ -1,114 +1,4 @@
|
|
1
1
|
require 'og'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
class OgSession < Wee::Session
|
8
|
-
def awake
|
9
|
-
application.db.get_connection
|
10
|
-
end
|
11
|
-
|
12
|
-
def sleep
|
13
|
-
application.db.put_connection
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class OgScaffolder < Wee::Component
|
18
|
-
def initialize(domain_class)
|
19
|
-
super()
|
20
|
-
@domain_class = domain_class
|
21
|
-
@attributes = domain_class.__props.map {|a| a.name}.reject {|a| a == 'oid'}
|
22
|
-
end
|
23
|
-
|
24
|
-
def delete(obj)
|
25
|
-
call Wee::MessageBox.new('Really delete?'), :confirm_delete, obj
|
26
|
-
end
|
27
|
-
|
28
|
-
def confirm_delete(confirmed, obj)
|
29
|
-
if confirmed
|
30
|
-
@objs.delete(obj)
|
31
|
-
obj.delete!
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def edit(obj)
|
36
|
-
@edit = obj
|
37
|
-
end
|
38
|
-
|
39
|
-
def save(obj)
|
40
|
-
obj.save!
|
41
|
-
@edit = nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def cancel
|
45
|
-
@objs.delete(@edit) if @edit and @edit.oid.nil?
|
46
|
-
@edit = nil
|
47
|
-
end
|
48
|
-
|
49
|
-
def refresh
|
50
|
-
@objs = @domain_class.all || []
|
51
|
-
end
|
52
|
-
|
53
|
-
def create
|
54
|
-
@objs << (@edit = @domain_class.new)
|
55
|
-
end
|
56
|
-
|
57
|
-
def render
|
58
|
-
refresh if @objs.nil?
|
59
|
-
|
60
|
-
r.h1 "#{ @domain_class } List"
|
61
|
-
r.anchor.callback { refresh }.with("Refresh")
|
62
|
-
|
63
|
-
r.form do
|
64
|
-
r.table.border(1).with {
|
65
|
-
|
66
|
-
r.table_row.with {
|
67
|
-
@attributes.each {|a|
|
68
|
-
r.table_header.with {
|
69
|
-
r.bold(a.capitalize)
|
70
|
-
}
|
71
|
-
}
|
72
|
-
r.table_header.with(" ")
|
73
|
-
}
|
74
|
-
|
75
|
-
@objs.each {|o|
|
76
|
-
r.table_row.with do
|
77
|
-
if @edit == o
|
78
|
-
|
79
|
-
@attributes.each { |attr|
|
80
|
-
r.table_data.with { r.text_input.callback {|v| o.send(attr+"=",v) }.value(o.send(attr)) }
|
81
|
-
}
|
82
|
-
|
83
|
-
r.table_data.with {
|
84
|
-
r.submit_button.callback { save(o) }.value("Save")
|
85
|
-
r.space
|
86
|
-
r.submit_button.callback { cancel() }.value("Cancel")
|
87
|
-
r.space
|
88
|
-
r.anchor.callback { delete(o) }.with("Delete")
|
89
|
-
}
|
90
|
-
|
91
|
-
else
|
92
|
-
|
93
|
-
@attributes.each { |attr|
|
94
|
-
r.table_data(o.send(attr))
|
95
|
-
}
|
96
|
-
|
97
|
-
r.table_data.with {
|
98
|
-
r.anchor.callback { edit(o) }.with("Edit")
|
99
|
-
r.space
|
100
|
-
r.anchor.callback { delete(o) }.with("Delete")
|
101
|
-
}
|
102
|
-
|
103
|
-
end
|
104
|
-
end
|
105
|
-
}
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
r.anchor.callback { create() }.with("Add new #{ @domain_class }")
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
2
|
+
require 'wee/databases/og/application'
|
3
|
+
require 'wee/databases/og/session'
|
4
|
+
require 'wee/databases/og/scaffolder'
|