flok 0.0.102 → 0.0.103
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.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/app/drivers/chrome/pipe.rb +66 -51
- data/app/drivers/chrome/src/controller.js +20 -1
- data/app/drivers/chrome/src/hook.js +10 -12
- data/app/drivers/chrome/src/net.js +4 -4
- data/app/drivers/chrome/src/sockio.js +2 -2
- data/app/drivers/chrome/src/ui.js +18 -15
- data/app/kern/mod/event.js +3 -1
- data/app/kern/mod/hook.js +13 -1
- data/app/kern/mod/ui.js +71 -0
- data/docs/controllers.md +14 -0
- data/docs/dispatch.md +4 -2
- data/docs/kernel_api.md +1 -0
- data/docs/kernel_handbook/find_view.md +34 -0
- data/docs/kernel_handbook/hooks.md +12 -1
- data/docs/mod/controller.md +5 -2
- data/docs/mod/hook.md +4 -3
- data/docs/mod/persist.md +1 -1
- data/docs/mod/ui.md +1 -0
- data/docs/user_handbook/hooks.md +38 -14
- data/flok.gemspec +2 -0
- data/lib/flok/user_compiler.rb +18 -2
- data/lib/flok/user_compiler_templates/ctable.js.erb +1 -0
- data/lib/flok/user_hook_generators/goto.rb +32 -4
- data/lib/flok/version.rb +1 -1
- data/spec/env/iface.rb +38 -0
- data/spec/env/kern.rb +4 -0
- data/spec/iface/driver/controller_spec.rb +25 -6
- data/spec/iface/driver/dispatch_spec.rb +7 -0
- data/spec/iface/driver/hook_spec.rb +83 -7
- data/spec/iface/driver/net_spec.rb +50 -41
- data/spec/iface/driver/persist_spec.rb +47 -4
- data/spec/iface/driver/ping_spec.rb +1 -1
- data/spec/iface/driver/rtc_spec.rb +2 -2
- data/spec/iface/driver/sockio_spec.rb +4 -3
- data/spec/iface/driver/timer_spec.rb +20 -0
- data/spec/iface/driver/ui_spec.rb +27 -4
- data/spec/kern/assets/find_view/controller0.rb +24 -0
- data/spec/kern/assets/find_view/controller1.rb +35 -0
- data/spec/kern/assets/find_view/controller1a.rb +37 -0
- data/spec/kern/assets/find_view/controller2.rb +23 -0
- data/spec/kern/assets/find_view/controller3.rb +38 -0
- data/spec/kern/assets/find_view/controller4.rb +38 -0
- data/spec/kern/assets/find_view/controller5.rb +52 -0
- data/spec/kern/assets/find_view/controller6.rb +37 -0
- data/spec/kern/assets/find_view/controller7.rb +37 -0
- data/spec/kern/assets/find_view/controller8.rb +53 -0
- data/spec/kern/assets/find_view/controller9.rb +67 -0
- data/spec/kern/assets/hook_entry_points/controller0.rb +13 -1
- data/spec/kern/assets/push_count.rb +42 -0
- data/spec/kern/controller_spec.rb +34 -0
- data/spec/kern/find_view_spec.rb +269 -0
- data/spec/kern/hook_entry_points_and_manifest_spec.rb +60 -0
- data/spec/kern/hook_user_generators_spec.rb +100 -0
- data/spec/lib/helpers.rb +1 -2
- metadata +58 -2
@@ -14,13 +14,17 @@ controller :my_controller do
|
|
14
14
|
}
|
15
15
|
|
16
16
|
on "hello", %{
|
17
|
-
|
17
|
+
Goto("other");
|
18
18
|
}
|
19
19
|
|
20
20
|
my_macro
|
21
21
|
end
|
22
22
|
|
23
23
|
action :other do
|
24
|
+
on_entry %{
|
25
|
+
Embed("new_controller", "hello", {});
|
26
|
+
}
|
27
|
+
|
24
28
|
on "test", %{
|
25
29
|
}
|
26
30
|
end
|
@@ -56,3 +60,11 @@ controller :my_other_controller do
|
|
56
60
|
}
|
57
61
|
end
|
58
62
|
end
|
63
|
+
|
64
|
+
controller :new_controller do
|
65
|
+
action :index do
|
66
|
+
on_entry %{
|
67
|
+
new_controller_base = __base__;
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#1. If we're in home, we should just raise back_clicked
|
2
|
+
#2. If we're in home, and push about, then we should pop
|
3
|
+
#3. If we're in about (start), then we should raise back_clicked
|
4
|
+
controller :my_controller do
|
5
|
+
macro :nav do
|
6
|
+
on "back_clicked", %{
|
7
|
+
if (push_count === 0) {
|
8
|
+
raised_back = true;
|
9
|
+
} else {
|
10
|
+
did_pop = true;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
choose_action do
|
16
|
+
on_entry %{
|
17
|
+
if (context.starts_in_about) {
|
18
|
+
Goto("about");
|
19
|
+
} else {
|
20
|
+
Goto("home");
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
action :home do
|
26
|
+
on "about_clicked", %{
|
27
|
+
Push("about");
|
28
|
+
}
|
29
|
+
nav
|
30
|
+
end
|
31
|
+
|
32
|
+
#Don't use macro here to test inside of a function
|
33
|
+
action :about do
|
34
|
+
on "back_clicked", %{
|
35
|
+
if (push_count === 0) {
|
36
|
+
raised_back = true;
|
37
|
+
} else {
|
38
|
+
did_pop = true;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
@@ -1001,4 +1001,38 @@ RSpec.describe "kern:controller_spec" do
|
|
1001
1001
|
@driver.mexpect("if_event", [Integer, "action", {"from" => "home", "to" => "about"}])
|
1002
1002
|
@driver.mexpect("if_event", [Integer, "action", {"from" => "about", "to" => "home"}])
|
1003
1003
|
end
|
1004
|
+
|
1005
|
+
it "Does support using an action & macro that contains push_count" do
|
1006
|
+
#1. If we're in home, we should just raise back_clicked
|
1007
|
+
ctx = flok_new_user File.read('./spec/kern/assets/push_count.rb')
|
1008
|
+
dump = ctx.evald %{
|
1009
|
+
base = _embed("my_controller", 0, {}, null);
|
1010
|
+
|
1011
|
+
int_dispatch([3, "int_event", base, "back_clicked", {}]);
|
1012
|
+
}
|
1013
|
+
raised_back = ctx.eval("raised_back")
|
1014
|
+
expect(raised_back).to eq(true)
|
1015
|
+
|
1016
|
+
|
1017
|
+
#2. If we're in home, and push about, then we should pop
|
1018
|
+
ctx = flok_new_user File.read('./spec/kern/assets/push_count.rb')
|
1019
|
+
dump = ctx.evald %{
|
1020
|
+
base = _embed("my_controller", 0, {}, null);
|
1021
|
+
|
1022
|
+
int_dispatch([3, "int_event", base, "about_clicked", {}]);
|
1023
|
+
int_dispatch([3, "int_event", base, "back_clicked", {}]);
|
1024
|
+
}
|
1025
|
+
did_pop = ctx.eval("did_pop")
|
1026
|
+
expect(did_pop).to eq(true)
|
1027
|
+
|
1028
|
+
#3. If we're in about (start), then we should raise back_clicked
|
1029
|
+
ctx = flok_new_user File.read('./spec/kern/assets/push_count.rb')
|
1030
|
+
dump = ctx.evald %{
|
1031
|
+
base = _embed("my_controller", 0, {starts_in_about: true}, null);
|
1032
|
+
|
1033
|
+
int_dispatch([3, "int_event", base, "back_clicked", {}]);
|
1034
|
+
}
|
1035
|
+
raised_back = ctx.eval("raised_back")
|
1036
|
+
expect(raised_back).to eq(true)
|
1037
|
+
end
|
1004
1038
|
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
#Specifically about the find_view releated (selector) functions
|
2
|
+
|
3
|
+
Dir.chdir File.join File.dirname(__FILE__), '../../'
|
4
|
+
require './spec/env/kern.rb'
|
5
|
+
require './spec/lib/helpers.rb'
|
6
|
+
require './spec/lib/io_extensions.rb'
|
7
|
+
require './spec/lib/rspec_extensions.rb'
|
8
|
+
|
9
|
+
RSpec.describe "kern:find_view_spec" do
|
10
|
+
include_context "kern"
|
11
|
+
|
12
|
+
it "Can call the find_view function" do
|
13
|
+
#Compile the controller
|
14
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller0.rb')
|
15
|
+
|
16
|
+
#Run the embed function
|
17
|
+
ctx.eval %{
|
18
|
+
//Call embed on main root view
|
19
|
+
base = _embed("my_controller", 0, {}, null);
|
20
|
+
|
21
|
+
//Drain queue
|
22
|
+
int_dispatch([]);
|
23
|
+
}
|
24
|
+
|
25
|
+
base = ctx.eval("base")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "The find_view returns the sub-controller's named basepointer" do
|
29
|
+
#Compile the controller
|
30
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller0.rb')
|
31
|
+
|
32
|
+
#Run the embed function
|
33
|
+
ctx.eval %{
|
34
|
+
//Call embed on main root view
|
35
|
+
base = _embed("my_controller", 0, {}, null);
|
36
|
+
|
37
|
+
//Drain queue
|
38
|
+
int_dispatch([]);
|
39
|
+
}
|
40
|
+
|
41
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
42
|
+
my_controller2_base = ctx.eval("JSON.stringify(my_controller2_base)")
|
43
|
+
|
44
|
+
expect(find_view_res).to eq({
|
45
|
+
"foo" => my_controller2_base.to_i
|
46
|
+
}.to_json)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "The find_view can return two subviews of different spots" do
|
50
|
+
#Compile the controller
|
51
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller1.rb')
|
52
|
+
|
53
|
+
#Run the embed function
|
54
|
+
ctx.eval %{
|
55
|
+
//Call embed on main root view
|
56
|
+
base = _embed("my_controller", 0, {}, null);
|
57
|
+
|
58
|
+
//Drain queue
|
59
|
+
int_dispatch([]);
|
60
|
+
}
|
61
|
+
|
62
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
63
|
+
my_controller2_base = ctx.eval("JSON.stringify(my_controller2_base)")
|
64
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
65
|
+
|
66
|
+
expect(find_view_res).to eq({
|
67
|
+
"foo" => my_controller2_base.to_i,
|
68
|
+
"foo2" => my_controller3_base.to_i
|
69
|
+
}.to_json)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "The find_view can return two subviews of different spots at different points in the hierarchy" do
|
73
|
+
#Compile the controller
|
74
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller1a.rb')
|
75
|
+
|
76
|
+
#Run the embed function
|
77
|
+
ctx.eval %{
|
78
|
+
//Call embed on main root view
|
79
|
+
base = _embed("my_controller", 0, {}, null);
|
80
|
+
|
81
|
+
//Drain queue
|
82
|
+
int_dispatch([]);
|
83
|
+
}
|
84
|
+
|
85
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
86
|
+
my_controller2_base = ctx.eval("JSON.stringify(my_controller2_base)")
|
87
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
88
|
+
|
89
|
+
expect(find_view_res).to eq({
|
90
|
+
"foo" => my_controller2_base.to_i,
|
91
|
+
"foo2" => my_controller3_base.to_i
|
92
|
+
}.to_json)
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
it "The find_view can return an immediate ." do
|
97
|
+
#Compile the controller
|
98
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller2.rb')
|
99
|
+
|
100
|
+
#Run the embed function
|
101
|
+
ctx.eval %{
|
102
|
+
//Call embed on main root view
|
103
|
+
base = _embed("my_controller", 0, {}, null);
|
104
|
+
|
105
|
+
//Drain queue
|
106
|
+
int_dispatch([]);
|
107
|
+
}
|
108
|
+
|
109
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
110
|
+
my_controller2_base = ctx.eval("JSON.stringify(my_controller2_base)")
|
111
|
+
|
112
|
+
expect(find_view_res).to eq({
|
113
|
+
"foo" => my_controller2_base.to_i,
|
114
|
+
}.to_json)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "The find_view can return a concrete nested followed by a ." do
|
118
|
+
#Compile the controller
|
119
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller3.rb')
|
120
|
+
|
121
|
+
#Run the embed function
|
122
|
+
ctx.eval %{
|
123
|
+
//Call embed on main root view
|
124
|
+
base = _embed("my_controller", 0, {}, null);
|
125
|
+
|
126
|
+
//Drain queue
|
127
|
+
int_dispatch([]);
|
128
|
+
}
|
129
|
+
|
130
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
131
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
132
|
+
|
133
|
+
expect(find_view_res).to eq({
|
134
|
+
"foo" => my_controller3_base.to_i,
|
135
|
+
}.to_json)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "The find_view can return a . followed by a concrete nested" do
|
139
|
+
#Compile the controller
|
140
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller4.rb')
|
141
|
+
|
142
|
+
#Run the embed function
|
143
|
+
ctx.eval %{
|
144
|
+
//Call embed on main root view
|
145
|
+
base = _embed("my_controller", 0, {}, null);
|
146
|
+
|
147
|
+
//Drain queue
|
148
|
+
int_dispatch([]);
|
149
|
+
}
|
150
|
+
|
151
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
152
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
153
|
+
|
154
|
+
expect(find_view_res).to eq({
|
155
|
+
"foo" => my_controller3_base.to_i,
|
156
|
+
}.to_json)
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
it "The find_view can return a + followed by a concrete nested for 4 views" do
|
161
|
+
#Compile the controller
|
162
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller5.rb')
|
163
|
+
|
164
|
+
#Run the embed function
|
165
|
+
ctx.eval %{
|
166
|
+
//Call embed on main root view
|
167
|
+
base = _embed("my_controller", 0, {}, null);
|
168
|
+
|
169
|
+
//Drain queue
|
170
|
+
int_dispatch([]);
|
171
|
+
}
|
172
|
+
|
173
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
174
|
+
my_controller4_base = ctx.eval("JSON.stringify(my_controller4_base)")
|
175
|
+
|
176
|
+
expect(find_view_res).to eq({
|
177
|
+
"foo" => my_controller4_base.to_i,
|
178
|
+
}.to_json)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "The find_view can return a + followed by a concrete nested for 3 views" do
|
182
|
+
#Compile the controller
|
183
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller6.rb')
|
184
|
+
|
185
|
+
#Run the embed function
|
186
|
+
ctx.eval %{
|
187
|
+
//Call embed on main root view
|
188
|
+
base = _embed("my_controller", 0, {}, null);
|
189
|
+
|
190
|
+
//Drain queue
|
191
|
+
int_dispatch([]);
|
192
|
+
}
|
193
|
+
|
194
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
195
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
196
|
+
|
197
|
+
expect(find_view_res).to eq({
|
198
|
+
"foo" => my_controller3_base.to_i,
|
199
|
+
}.to_json)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "The find_view can return a + followed by a . match" do
|
203
|
+
#Compile the controller
|
204
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller7.rb')
|
205
|
+
|
206
|
+
#Run the embed function
|
207
|
+
ctx.eval %{
|
208
|
+
//Call embed on main root view
|
209
|
+
base = _embed("my_controller", 0, {}, null);
|
210
|
+
|
211
|
+
//Drain queue
|
212
|
+
int_dispatch([]);
|
213
|
+
}
|
214
|
+
|
215
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
216
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
217
|
+
|
218
|
+
expect(find_view_res).to eq({
|
219
|
+
"foo" => my_controller3_base.to_i,
|
220
|
+
}.to_json)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "The find_view can return a . followed by + followed by a . match" do
|
224
|
+
#Compile the controller
|
225
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller8.rb')
|
226
|
+
|
227
|
+
#Run the embed function
|
228
|
+
ctx.eval %{
|
229
|
+
//Call embed on main root view
|
230
|
+
base = _embed("my_controller", 0, {}, null);
|
231
|
+
|
232
|
+
//Drain queue
|
233
|
+
int_dispatch([]);
|
234
|
+
}
|
235
|
+
|
236
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
237
|
+
my_controller2_base = ctx.eval("JSON.stringify(my_controller2_base)")
|
238
|
+
my_controller4_base = ctx.eval("JSON.stringify(my_controller4_base)")
|
239
|
+
|
240
|
+
expect(find_view_res).to eq({
|
241
|
+
"foo1" => my_controller2_base.to_i,
|
242
|
+
"foo2" => my_controller4_base.to_i,
|
243
|
+
}.to_json)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "The find_view can return a . . followed by + followed by a . match" do
|
247
|
+
#Compile the controller
|
248
|
+
ctx = flok_new_user File.read('./spec/kern/assets/find_view/controller9.rb')
|
249
|
+
|
250
|
+
#Run the embed function
|
251
|
+
ctx.eval %{
|
252
|
+
//Call embed on main root view
|
253
|
+
base = _embed("my_controller", 0, {}, null);
|
254
|
+
|
255
|
+
//Drain queue
|
256
|
+
int_dispatch([]);
|
257
|
+
}
|
258
|
+
|
259
|
+
find_view_res = ctx.eval("JSON.stringify(find_view_res)")
|
260
|
+
my_controller3_base = ctx.eval("JSON.stringify(my_controller3_base)")
|
261
|
+
my_controller5_base = ctx.eval("JSON.stringify(my_controller5_base)")
|
262
|
+
|
263
|
+
expect(find_view_res).to eq({
|
264
|
+
"foo1" => my_controller3_base.to_i,
|
265
|
+
"foo2" => my_controller5_base.to_i,
|
266
|
+
}.to_json)
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
@@ -152,4 +152,64 @@ eof
|
|
152
152
|
expect(dump["entry_params"]["old_action"]).to eq("choose_action")
|
153
153
|
expect(dump["entry_params"]["new_action"]).to eq("index")
|
154
154
|
end
|
155
|
+
|
156
|
+
it "Can hook the controller_did_goto event with the correct hook entry information and has the variables mentioned in the docs" do
|
157
|
+
info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0a.rb')
|
158
|
+
src = info[:src]
|
159
|
+
ctx = info[:ctx]
|
160
|
+
|
161
|
+
manifest = Flok::HooksManifest.new
|
162
|
+
will_gotos_found = 0
|
163
|
+
from_to_action_pairs_found = []
|
164
|
+
entry = Flok::HooksManifestEntry.new("controller_did_goto") do |hook_info|
|
165
|
+
will_gotos_found += 1
|
166
|
+
#Static parameters
|
167
|
+
expect(hook_info["controller_name"]).to eq("my_controller")
|
168
|
+
expect(hook_info["might_respond_to"].to_set).to eq(["foo", "hello", "test"].to_set)
|
169
|
+
from_to_action_pairs_found << {hook_info["from_action"] => hook_info["to_action"]}
|
170
|
+
|
171
|
+
#actions_responds_to looks like {"action1" => ["event_a", ..."], "action2" => }...
|
172
|
+
#where each action list contains all the events this action responds to
|
173
|
+
expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test"]})
|
174
|
+
|
175
|
+
#Variables included
|
176
|
+
next %{
|
177
|
+
entry_params = {
|
178
|
+
old_action: old_action,
|
179
|
+
new_action: __info__.action,
|
180
|
+
};
|
181
|
+
}
|
182
|
+
end
|
183
|
+
manifest << entry
|
184
|
+
|
185
|
+
#Recompile source (We do this manually as we supplied no `config/hooks.rb` file)
|
186
|
+
src = Flok::HooksCompiler.compile src, manifest
|
187
|
+
|
188
|
+
#Expect to have found two will_goto entries given that there is one Goto request
|
189
|
+
#and one implicit Goto from the entry
|
190
|
+
expect(will_gotos_found).to eq(2)
|
191
|
+
|
192
|
+
#Expect to have gotten all the goto to/from action pairs
|
193
|
+
expect(from_to_action_pairs_found.to_set).to eq([{"other" => "index"}, {"choose_action" => "index"}].to_set)
|
194
|
+
|
195
|
+
#Re-evaluate the v8 instance
|
196
|
+
ctx = v8_flok
|
197
|
+
ctx.eval src
|
198
|
+
|
199
|
+
#Now load the controller
|
200
|
+
dump = ctx.evald %{
|
201
|
+
base = _embed("my_controller", 0, {}, null);
|
202
|
+
|
203
|
+
//Drain queue
|
204
|
+
int_dispatch([]);
|
205
|
+
|
206
|
+
dump.entry_params = entry_params;
|
207
|
+
}
|
208
|
+
|
209
|
+
#Verify the parametrs were set
|
210
|
+
expect(dump["entry_params"]).not_to eq(nil)
|
211
|
+
expect(dump["entry_params"]["old_action"]).to eq("choose_action")
|
212
|
+
expect(dump["entry_params"]["new_action"]).to eq("index")
|
213
|
+
end
|
214
|
+
|
155
215
|
end
|
@@ -136,4 +136,104 @@ RSpec.describe "kern:hook_user_geenrators_spec" do
|
|
136
136
|
expect { @driver.ignore_up_to("if_hook_event", 0); @driver.get "if_hook_event", 0 }.not_to raise_error
|
137
137
|
end
|
138
138
|
|
139
|
+
it "Can use goto to embed a pre and post selectors which will be returned in the hooking response" do
|
140
|
+
#Hook source code
|
141
|
+
hooks_src = %{
|
142
|
+
hook :goto => :goto do
|
143
|
+
controller "my_controller"
|
144
|
+
to_action_responds_to? "test"
|
145
|
+
|
146
|
+
before_views({
|
147
|
+
"." => {
|
148
|
+
"__leaf__" => "foo"
|
149
|
+
}
|
150
|
+
})
|
151
|
+
|
152
|
+
after_views({
|
153
|
+
"new_controller" => {
|
154
|
+
"__leaf__" => "foo2"
|
155
|
+
}
|
156
|
+
})
|
157
|
+
|
158
|
+
end
|
159
|
+
}
|
160
|
+
|
161
|
+
#Just expect this not to blow up
|
162
|
+
info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0.rb'), nil, nil, hooks_src
|
163
|
+
ctx = info[:ctx]
|
164
|
+
|
165
|
+
#Run the embed function
|
166
|
+
ctx.evald %{
|
167
|
+
dump.base = _embed("my_controller", 0, {}, null); // Embed the controller
|
168
|
+
int_dispatch([]); // Dispatch any events the are pending
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
my_other_controller_base = ctx.eval("my_other_controller_base")
|
173
|
+
on_entry_base_pointer = ctx.eval("on_entry_base_pointer")
|
174
|
+
|
175
|
+
#Now we switch to an action and our last action contained a back click
|
176
|
+
@driver.int "int_event", [ on_entry_base_pointer, "hello", {} ]
|
177
|
+
new_controller_base = ctx.eval("new_controller_base")
|
178
|
+
|
179
|
+
@driver.ignore_up_to("if_hook_event", 0)
|
180
|
+
hook_res = @driver.get "if_hook_event", 0
|
181
|
+
|
182
|
+
expect(hook_res[1]).to eq({
|
183
|
+
"views" => {
|
184
|
+
"foo" => my_other_controller_base,
|
185
|
+
"foo2" => new_controller_base
|
186
|
+
}
|
187
|
+
})
|
188
|
+
end
|
189
|
+
|
190
|
+
it "The goto does not free views via the module until after the completion event is received" do
|
191
|
+
#Hook source code
|
192
|
+
hooks_src = %{
|
193
|
+
hook :goto => :goto do
|
194
|
+
controller "my_controller"
|
195
|
+
to_action_responds_to? "test"
|
196
|
+
end
|
197
|
+
}
|
198
|
+
|
199
|
+
#Just expect this not to blow up
|
200
|
+
info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0.rb'), nil, nil, hooks_src
|
201
|
+
ctx = info[:ctx]
|
202
|
+
|
203
|
+
#Run the embed function
|
204
|
+
ctx.evald %{
|
205
|
+
dump.base = _embed("my_controller", 0, {}, null); // Embed the controller
|
206
|
+
int_dispatch([]); // Dispatch any events the are pending
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
my_other_controller_base = ctx.eval("my_other_controller_base")
|
211
|
+
on_entry_base_pointer = ctx.eval("on_entry_base_pointer")
|
212
|
+
|
213
|
+
#Now we switch to an action and our last action contained a back click
|
214
|
+
@driver.int "int_event", [ on_entry_base_pointer, "hello", {} ]
|
215
|
+
new_controller_base = ctx.eval("new_controller_base")
|
216
|
+
|
217
|
+
#Should not receive a free view here because we have not sent the completion handler back
|
218
|
+
expect {
|
219
|
+
@driver.ignore_up_to("if_free_view", 0)
|
220
|
+
}.to raise_error /Waited/
|
221
|
+
|
222
|
+
@driver.ignore_up_to("if_hook_event", 0)
|
223
|
+
hook_res = @driver.get "if_hook_event", 0
|
224
|
+
|
225
|
+
#We need to have a 'completion' tele-pointer to signal back
|
226
|
+
cep = hook_res[1]["cep"]
|
227
|
+
expect(cep).not_to eq(nil)
|
228
|
+
|
229
|
+
#Now we send the completion event
|
230
|
+
@driver.int "int_event", [cep, "", {}]
|
231
|
+
|
232
|
+
#Now we should have received our free views
|
233
|
+
@driver.ignore_up_to("if_free_view", 0)
|
234
|
+
free_view = @driver.get "if_free_view", 0
|
235
|
+
expect(free_view).to eq([
|
236
|
+
my_other_controller_base+1
|
237
|
+
])
|
238
|
+
end
|
139
239
|
end
|