opal-browser 0.1.0.beta1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +95 -0
- data/.gitignore +3 -0
- data/.yardopts +1 -1
- data/Gemfile +22 -3
- data/LICENSE +20 -0
- data/README.md +200 -20
- data/Rakefile +29 -1
- data/config.ru +20 -2
- data/docs/polyfills.md +24 -0
- data/examples/2048/Gemfile +6 -0
- data/examples/2048/README.md +13 -0
- data/examples/2048/app/application.rb +169 -0
- data/examples/2048/config.ru +9 -0
- data/examples/canvas/Gemfile +6 -0
- data/examples/canvas/README.md +9 -0
- data/examples/canvas/app/application.rb +55 -0
- data/examples/canvas/config.ru +9 -0
- data/examples/component/Gemfile +6 -0
- data/examples/component/README.md +10 -0
- data/examples/component/app/application.rb +66 -0
- data/examples/component/config.ru +9 -0
- data/examples/integrations/README.md +24 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/Gemfile +6 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/README.md +16 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/app/application.rb +6 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/config.ru +9 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/.gitignore +1 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/Gemfile +7 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/README.md +22 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/Rakefile +4 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/app/application.rb +6 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/app.rb +32 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/config.ru +3 -0
- data/examples/integrations/dynamic-roda-tilt/.gitignore +1 -0
- data/examples/integrations/dynamic-roda-tilt/Gemfile +8 -0
- data/examples/integrations/dynamic-roda-tilt/README.md +17 -0
- data/examples/integrations/dynamic-roda-tilt/Rakefile +6 -0
- data/examples/integrations/dynamic-roda-tilt/app/application.rb +6 -0
- data/examples/integrations/dynamic-roda-tilt/app.rb +50 -0
- data/examples/integrations/dynamic-roda-tilt/config.ru +3 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/Gemfile +7 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/README.md +16 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/app/application.rb +6 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/config.ru +29 -0
- data/examples/integrations/static-bash/.gitignore +2 -0
- data/examples/integrations/static-bash/Gemfile +3 -0
- data/examples/integrations/static-bash/README.md +8 -0
- data/examples/integrations/static-bash/app/application.rb +6 -0
- data/examples/integrations/static-bash/build.sh +4 -0
- data/examples/integrations/static-bash/index.html +10 -0
- data/examples/integrations/static-bash-opal-parser/.gitignore +3 -0
- data/examples/integrations/static-bash-opal-parser/Gemfile +3 -0
- data/examples/integrations/static-bash-opal-parser/README.md +10 -0
- data/examples/integrations/static-bash-opal-parser/build.sh +4 -0
- data/examples/integrations/static-bash-opal-parser/index.html +19 -0
- data/examples/integrations/static-rake/.gitignore +1 -0
- data/examples/integrations/static-rake/Gemfile +4 -0
- data/examples/integrations/static-rake/README.md +7 -0
- data/examples/integrations/static-rake/Rakefile +10 -0
- data/examples/integrations/static-rake/app/application.rb +6 -0
- data/examples/integrations/static-rake/index.html +9 -0
- data/examples/integrations/static-rake-guard/.gitignore +1 -0
- data/examples/integrations/static-rake-guard/Gemfile +6 -0
- data/examples/integrations/static-rake-guard/Guardfile +3 -0
- data/examples/integrations/static-rake-guard/README.md +10 -0
- data/examples/integrations/static-rake-guard/Rakefile +10 -0
- data/examples/integrations/static-rake-guard/app/application.rb +6 -0
- data/examples/integrations/static-rake-guard/index.html +9 -0
- data/examples/svg/.gitignore +1 -0
- data/examples/svg/Gemfile +4 -0
- data/examples/svg/README.md +7 -0
- data/examples/svg/Rakefile +10 -0
- data/examples/svg/app/application.rb +11 -0
- data/examples/svg/index.html +17 -0
- data/examples/svg/index.svg +6 -0
- data/index.html.erb +24 -0
- data/lib/opal-browser.rb +1 -0
- data/opal/browser/animation_frame.rb +92 -10
- data/opal/browser/audio/node.rb +121 -0
- data/opal/browser/audio/param_schedule.rb +43 -0
- data/opal/browser/audio.rb +66 -0
- data/opal/browser/blob.rb +94 -0
- data/opal/browser/canvas/data.rb +2 -12
- data/opal/browser/canvas/gradient.rb +1 -11
- data/opal/browser/canvas/style.rb +3 -11
- data/opal/browser/canvas/text.rb +1 -11
- data/opal/browser/canvas.rb +86 -28
- data/opal/browser/console.rb +6 -38
- data/opal/browser/cookies.rb +90 -27
- data/opal/browser/crypto.rb +79 -0
- data/opal/browser/css/declaration.rb +1 -6
- data/opal/browser/css/rule.rb +1 -1
- data/opal/browser/css/style_sheet.rb +2 -2
- data/opal/browser/css.rb +23 -7
- data/opal/browser/database/sql.rb +193 -0
- data/opal/browser/delay.rb +94 -0
- data/opal/browser/dom/attribute.rb +16 -9
- data/opal/browser/dom/builder.rb +35 -25
- data/opal/browser/dom/character_data.rb +43 -7
- data/opal/browser/dom/document.rb +171 -37
- data/opal/browser/dom/document_fragment.rb +18 -0
- data/opal/browser/dom/document_or_shadow_root.rb +19 -0
- data/opal/browser/dom/element/attributes.rb +111 -0
- data/opal/browser/dom/element/button.rb +31 -0
- data/opal/browser/dom/element/custom.rb +177 -0
- data/opal/browser/dom/element/data.rb +82 -0
- data/opal/browser/dom/element/editable.rb +47 -0
- data/opal/browser/dom/element/form.rb +38 -0
- data/opal/browser/dom/element/iframe.rb +37 -0
- data/opal/browser/dom/element/image.rb +25 -0
- data/opal/browser/dom/element/input.rb +48 -1
- data/opal/browser/dom/element/media.rb +17 -0
- data/opal/browser/dom/element/offset.rb +32 -10
- data/opal/browser/dom/element/position.rb +11 -2
- data/opal/browser/dom/element/scroll.rb +139 -20
- data/opal/browser/dom/element/select.rb +42 -0
- data/opal/browser/dom/element/size.rb +46 -0
- data/opal/browser/dom/element/template.rb +11 -0
- data/opal/browser/dom/element/textarea.rb +26 -0
- data/opal/browser/dom/element.rb +496 -168
- data/opal/browser/dom/mutation_observer.rb +69 -9
- data/opal/browser/dom/node.rb +270 -83
- data/opal/browser/dom/node_set.rb +74 -41
- data/opal/browser/dom/shadow_root.rb +12 -0
- data/opal/browser/dom/text.rb +18 -3
- data/opal/browser/dom.rb +40 -18
- data/opal/browser/effects.rb +180 -3
- data/opal/browser/event/all.rb +26 -0
- data/opal/browser/event/animation.rb +40 -0
- data/opal/browser/{dom/event → event}/audio_processing.rb +10 -6
- data/opal/browser/event/base.rb +461 -0
- data/opal/browser/event/before_unload.rb +17 -0
- data/opal/browser/event/clipboard.rb +37 -0
- data/opal/browser/event/close.rb +49 -0
- data/opal/browser/event/composition.rb +52 -0
- data/opal/browser/event/custom.rb +65 -0
- data/opal/browser/event/data_transfer.rb +95 -0
- data/opal/browser/event/device_light.rb +25 -0
- data/opal/browser/{dom/event → event}/device_motion.rb +21 -6
- data/opal/browser/event/device_orientation.rb +50 -0
- data/opal/browser/{dom/event → event}/device_proximity.rb +10 -6
- data/opal/browser/event/drag.rb +123 -0
- data/opal/browser/event/focus.rb +41 -0
- data/opal/browser/event/gamepad.rb +62 -0
- data/opal/browser/{dom/event → event}/hash_change.rb +10 -6
- data/opal/browser/event/keyboard.rb +128 -0
- data/opal/browser/event/message.rb +72 -0
- data/opal/browser/{dom/event → event}/mouse.rb +37 -32
- data/opal/browser/event/page_transition.rb +25 -0
- data/opal/browser/event/pop_state.rb +35 -0
- data/opal/browser/event/progress.rb +45 -0
- data/opal/browser/event/sensor.rb +17 -0
- data/opal/browser/{dom/event → event}/storage.rb +10 -6
- data/opal/browser/{dom/event → event}/touch.rb +14 -21
- data/opal/browser/event/ui.rb +38 -0
- data/opal/browser/{dom/event → event}/wheel.rb +6 -4
- data/opal/browser/event.rb +163 -0
- data/opal/browser/event_source.rb +7 -4
- data/opal/browser/form_data.rb +225 -0
- data/opal/browser/history.rb +53 -21
- data/opal/browser/http/binary.rb +1 -0
- data/opal/browser/http/headers.rb +21 -2
- data/opal/browser/http/request.rb +83 -55
- data/opal/browser/http/response.rb +5 -1
- data/opal/browser/http.rb +47 -9
- data/opal/browser/immediate.rb +128 -10
- data/opal/browser/interval.rb +41 -23
- data/opal/browser/location.rb +20 -4
- data/opal/browser/navigator.rb +136 -13
- data/opal/browser/polyfill/visual_viewport.rb +216 -0
- data/opal/browser/screen.rb +34 -8
- data/opal/browser/setup/base.rb +6 -0
- data/opal/browser/setup/full.rb +13 -0
- data/opal/browser/setup/large.rb +17 -0
- data/opal/browser/setup/mini.rb +8 -0
- data/opal/browser/setup/traditional.rb +10 -0
- data/opal/browser/socket.rb +16 -8
- data/opal/browser/storage.rb +155 -52
- data/opal/browser/support.rb +299 -0
- data/opal/browser/utils.rb +116 -18
- data/opal/browser/version.rb +1 -1
- data/opal/browser/visual_viewport.rb +39 -0
- data/opal/browser/window/size.rb +47 -9
- data/opal/browser/window/view.rb +37 -4
- data/opal/browser/window.rb +46 -26
- data/opal/browser.rb +1 -10
- data/opal/opal-browser.rb +1 -0
- data/opal-browser.gemspec +10 -12
- data/spec/database/sql_spec.rb +139 -0
- data/spec/delay_spec.rb +41 -0
- data/spec/dom/attribute_spec.rb +49 -0
- data/spec/dom/builder_spec.rb +36 -19
- data/spec/dom/document_spec.rb +28 -6
- data/spec/dom/element/attributes_spec.rb +52 -0
- data/spec/dom/element/custom_spec.rb +106 -0
- data/spec/dom/element/subclass_spec.rb +144 -0
- data/spec/dom/element_spec.rb +184 -7
- data/spec/dom/mutation_observer_spec.rb +13 -9
- data/spec/dom/node_set_spec.rb +44 -0
- data/spec/dom/node_spec.rb +87 -27
- data/spec/dom_spec.rb +19 -9
- data/spec/event_source_spec.rb +18 -15
- data/spec/{dom/event_spec.rb → event_spec.rb} +55 -26
- data/spec/history_spec.rb +32 -19
- data/spec/http_spec.rb +25 -36
- data/spec/immediate_spec.rb +10 -7
- data/spec/interval_spec.rb +59 -0
- data/spec/native_cached_wrapper_spec.rb +46 -0
- data/spec/runner.rb +107 -0
- data/spec/socket_spec.rb +18 -14
- data/spec/spec_helper.rb +2 -4
- data/spec/spec_helper_promise.rb.erb +25 -0
- data/spec/storage_spec.rb +7 -7
- data/spec/wgxpath.install.js +49 -0
- data/spec/window_spec.rb +2 -2
- metadata +181 -93
- data/opal/browser/compatibility/animation_frame.rb +0 -93
- data/opal/browser/compatibility/dom/document/window.rb +0 -15
- data/opal/browser/compatibility/dom/element/css.rb +0 -15
- data/opal/browser/compatibility/dom/element/matches.rb +0 -31
- data/opal/browser/compatibility/dom/element/offset.rb +0 -20
- data/opal/browser/compatibility/dom/element/scroll.rb +0 -25
- data/opal/browser/compatibility/dom/element/style.rb +0 -15
- data/opal/browser/compatibility/dom/mutation_observer.rb +0 -47
- data/opal/browser/compatibility/http/request.rb +0 -15
- data/opal/browser/compatibility/immediate.rb +0 -107
- data/opal/browser/compatibility/window/scroll.rb +0 -27
- data/opal/browser/compatibility/window/size.rb +0 -13
- data/opal/browser/compatibility/window/view.rb +0 -13
- data/opal/browser/compatibility.rb +0 -59
- data/opal/browser/dom/compatibility.rb +0 -8
- data/opal/browser/dom/event/animation.rb +0 -26
- data/opal/browser/dom/event/base.rb +0 -207
- data/opal/browser/dom/event/before_unload.rb +0 -13
- data/opal/browser/dom/event/clipboard.rb +0 -26
- data/opal/browser/dom/event/close.rb +0 -35
- data/opal/browser/dom/event/composition.rb +0 -38
- data/opal/browser/dom/event/custom.rb +0 -30
- data/opal/browser/dom/event/device_light.rb +0 -21
- data/opal/browser/dom/event/device_orientation.rb +0 -36
- data/opal/browser/dom/event/drag.rb +0 -113
- data/opal/browser/dom/event/focus.rb +0 -23
- data/opal/browser/dom/event/gamepad.rb +0 -47
- data/opal/browser/dom/event/keyboard.rb +0 -93
- data/opal/browser/dom/event/message.rb +0 -50
- data/opal/browser/dom/event/page_transition.rb +0 -21
- data/opal/browser/dom/event/pop_state.rb +0 -21
- data/opal/browser/dom/event/progress.rb +0 -31
- data/opal/browser/dom/event/sensor.rb +0 -13
- data/opal/browser/dom/event/ui.rb +0 -22
- data/opal/browser/dom/event.rb +0 -240
- data/opal/browser/http/compatibility.rb +0 -1
- data/opal/browser/http/parameters.rb +0 -8
- data/opal/browser/timeout.rb +0 -60
- data/opal/browser/window/compatibility.rb +0 -3
- data/opal/browser/window/scroll.rb +0 -49
data/spec/delay_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'browser/delay'
|
3
|
+
|
4
|
+
describe Browser::Window do
|
5
|
+
describe '#after' do
|
6
|
+
it 'calls the block after the given time' do
|
7
|
+
promise = Browser::Promise.new
|
8
|
+
$window.after 0.3 do
|
9
|
+
expect(true).to be_truthy
|
10
|
+
promise.resolve
|
11
|
+
end
|
12
|
+
promise.for_rspec
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Kernel do
|
18
|
+
describe '#after' do
|
19
|
+
it 'calls the block after the given time' do
|
20
|
+
promise = Browser::Promise.new
|
21
|
+
after 0.3 do
|
22
|
+
expect(true).to be_truthy
|
23
|
+
promise.resolve
|
24
|
+
end
|
25
|
+
promise.for_rspec
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Proc do
|
31
|
+
describe '#after' do
|
32
|
+
it 'calls the block after the given time' do
|
33
|
+
promise = Browser::Promise.new
|
34
|
+
-> {
|
35
|
+
expect(true).to be_truthy
|
36
|
+
promise.resolve
|
37
|
+
}.after 0.3
|
38
|
+
promise.for_rspec
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Browser::DOM::Attribute do
|
4
|
+
html <<-HTML
|
5
|
+
<div id="lol" class="hue" something="wat"></div>
|
6
|
+
HTML
|
7
|
+
|
8
|
+
describe '#name' do
|
9
|
+
it 'gets the right name' do
|
10
|
+
attr = $document['lol'].attribute_nodes.find { |a| a.name == :id }
|
11
|
+
|
12
|
+
expect(attr.name).to eq(:id)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#value' do
|
17
|
+
it 'gets the right value' do
|
18
|
+
attr = $document['lol'].attribute_nodes.find { |a| a.name == :id }
|
19
|
+
|
20
|
+
expect(attr.name).to eq(:id)
|
21
|
+
expect(attr.value).to eq(:lol)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#value=' do
|
26
|
+
it 'sets the value' do
|
27
|
+
attr = $document['lol'].attribute_nodes.find { |a| a.name == :id }
|
28
|
+
|
29
|
+
expect(attr.name).to eq(:id)
|
30
|
+
expect(attr.value).to eq(:lol)
|
31
|
+
attr.value = :omg
|
32
|
+
expect(attr.value).to eq(:omg)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#id?' do
|
37
|
+
it 'is true for an id attribute' do
|
38
|
+
attr = $document['lol'].attribute_nodes.find { |a| a.name == :id }
|
39
|
+
|
40
|
+
expect(attr.id?).to be_truthy
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is false for any other attribute' do
|
44
|
+
attr = $document['lol'].attribute_nodes.find { |a| a.name == :class }
|
45
|
+
|
46
|
+
expect(attr.id?).to be_falsy
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/dom/builder_spec.rb
CHANGED
@@ -2,27 +2,35 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Browser::DOM::Builder do
|
4
4
|
it 'builds an element' do
|
5
|
-
DOM {
|
5
|
+
res = DOM {
|
6
6
|
div
|
7
|
-
}
|
7
|
+
}
|
8
|
+
|
9
|
+
expect(res.name).to eq('DIV')
|
8
10
|
end
|
9
11
|
|
10
12
|
it 'builds an element with text content' do
|
11
|
-
DOM {
|
13
|
+
res = DOM {
|
12
14
|
div "foo bar"
|
13
|
-
}
|
15
|
+
}
|
14
16
|
|
15
|
-
|
17
|
+
expect(res.text).to eq('foo bar')
|
18
|
+
|
19
|
+
res = DOM {
|
16
20
|
div {
|
17
21
|
"foo bar"
|
18
22
|
}
|
19
|
-
}
|
23
|
+
}
|
24
|
+
|
25
|
+
expect(res.text).to eq('foo bar')
|
20
26
|
end
|
21
27
|
|
22
28
|
it 'builds an element with attributes' do
|
23
|
-
DOM {
|
29
|
+
res = DOM {
|
24
30
|
div class: :wut
|
25
|
-
}
|
31
|
+
}
|
32
|
+
|
33
|
+
expect(res.class_name).to eq(:wut)
|
26
34
|
end
|
27
35
|
|
28
36
|
it 'builds deeper trees' do
|
@@ -34,15 +42,15 @@ describe Browser::DOM::Builder do
|
|
34
42
|
}
|
35
43
|
}
|
36
44
|
|
37
|
-
res.name.
|
38
|
-
res.child.name.
|
39
|
-
res.child.text.
|
45
|
+
expect(res.name).to eq('DIV')
|
46
|
+
expect(res.child.name).to eq('SPAN')
|
47
|
+
expect(res.child.text).to eq('wut')
|
40
48
|
end
|
41
49
|
|
42
50
|
it 'sets classes with methods' do
|
43
|
-
DOM {
|
51
|
+
expect(DOM {
|
44
52
|
div.nice.element
|
45
|
-
}.class_names.
|
53
|
+
}.class_names).to eq(%w[nice element])
|
46
54
|
end
|
47
55
|
|
48
56
|
it 'nests when setting classes' do
|
@@ -52,10 +60,10 @@ describe Browser::DOM::Builder do
|
|
52
60
|
}
|
53
61
|
}
|
54
62
|
|
55
|
-
res.name.
|
56
|
-
res.class_names.
|
57
|
-
res.child.name.
|
58
|
-
res.child.class_names.
|
63
|
+
expect(res.name).to eq('DIV')
|
64
|
+
expect(res.class_names).to eq(%w[nice element])
|
65
|
+
expect(res.child.name).to eq('SPAN')
|
66
|
+
expect(res.child.class_names).to eq(%w[nicer])
|
59
67
|
end
|
60
68
|
|
61
69
|
it 'joins class name properly' do
|
@@ -63,7 +71,16 @@ describe Browser::DOM::Builder do
|
|
63
71
|
i.icon[:legal]
|
64
72
|
}
|
65
73
|
|
66
|
-
res.name.
|
67
|
-
res.class_names.
|
74
|
+
expect(res.name).to eq('I')
|
75
|
+
expect(res.class_names).to eq(%w[icon-legal])
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'sets the id' do
|
79
|
+
res = DOM {
|
80
|
+
div.omg!
|
81
|
+
}
|
82
|
+
|
83
|
+
expect(res.name).to eq('DIV')
|
84
|
+
expect(res.id).to eq('omg')
|
68
85
|
end
|
69
86
|
end
|
data/spec/dom/document_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Browser::DOM::Document do
|
4
4
|
describe '#title' do
|
5
5
|
it 'should get the document title' do
|
6
|
-
$document.title.
|
6
|
+
expect($document.title).to be_a(String)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -11,7 +11,7 @@ describe Browser::DOM::Document do
|
|
11
11
|
it 'should set the document title' do
|
12
12
|
old = $document.title
|
13
13
|
$document.title = 'lol'
|
14
|
-
$document.title.
|
14
|
+
expect($document.title).to eq('lol')
|
15
15
|
$document.title = old
|
16
16
|
end
|
17
17
|
end
|
@@ -22,19 +22,41 @@ describe Browser::DOM::Document do
|
|
22
22
|
HTML
|
23
23
|
|
24
24
|
it "should get element by id" do
|
25
|
-
$document["lol"].
|
25
|
+
expect($document["lol"]).to eq(`document.getElementById('lol')`)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should get element by css" do
|
29
|
-
$document["lol"].
|
29
|
+
expect($document["#lol"]).to eq(`document.getElementById('lol')`)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should get element by xpath" do
|
33
|
-
$document["//*[@id='lol']"].
|
33
|
+
expect($document["//*[@id='lol']"]).to eq(`document.getElementById('lol')`)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should return nil if it can't find anything" do
|
37
|
-
$document["doo-dah"].
|
37
|
+
expect($document["doo-dah"]).to be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#ready" do
|
42
|
+
it "calls the block when the document is ready" do
|
43
|
+
promise = Browser::Promise.new
|
44
|
+
$document.ready do
|
45
|
+
expect(true).to be_truthy
|
46
|
+
promise.resolve
|
47
|
+
end
|
48
|
+
promise.for_rspec
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#ready?" do
|
53
|
+
it "is true inside a #ready block" do
|
54
|
+
promise = Browser::Promise.new
|
55
|
+
$document.ready do
|
56
|
+
expect($document.ready?).to be_truthy
|
57
|
+
promise.resolve
|
58
|
+
end
|
59
|
+
promise.for_rspec
|
38
60
|
end
|
39
61
|
end
|
40
62
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Browser::DOM::Element::Attributes do
|
4
|
+
html <<-HTML
|
5
|
+
<label id="lol" class="name" for="hue"></label>
|
6
|
+
HTML
|
7
|
+
|
8
|
+
describe '#[]' do
|
9
|
+
it 'gets an attribute' do
|
10
|
+
expect($document[:lol].attributes[:id]).to eq(:lol)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'gets the class attribute' do
|
14
|
+
expect($document[:lol].attributes[:class]).to eq(:name)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'gets the for attribute' do
|
18
|
+
expect($document[:lol].attributes[:for]).to eq(:hue)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#[]=' do
|
23
|
+
it 'sets an attribute' do
|
24
|
+
$document[:lol].attributes[:a] = :foo
|
25
|
+
|
26
|
+
expect($document[:lol].attributes[:a]).to eq(:foo)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets the class attribute' do
|
30
|
+
$document[:lol].attributes[:class] = :bar
|
31
|
+
|
32
|
+
expect($document[:lol].attributes[:class]).to eq(:bar)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sets the for attribute' do
|
36
|
+
$document[:lol].attributes[:for] = :baz
|
37
|
+
|
38
|
+
expect($document[:lol].attributes[:for]).to eq(:baz)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#each' do
|
43
|
+
it 'enumerates over the attributes' do
|
44
|
+
attributes = $document[:lol].attributes.select {|name, _|
|
45
|
+
%w[class for id].include?(name)
|
46
|
+
}
|
47
|
+
|
48
|
+
expect(attributes.sort).to eq \
|
49
|
+
[[:class, :name], [:for, :hue], [:id, :lol]]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'browser/dom/element/custom'
|
3
|
+
|
4
|
+
describe Browser::DOM::Element::Custom do
|
5
|
+
before(:each) do
|
6
|
+
$scratchpad = Hash.new { false }
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_custom_class(name, observed_attrs = [])
|
10
|
+
Class.new(Browser::DOM::Element::Custom) do
|
11
|
+
def initialize(node)
|
12
|
+
super
|
13
|
+
$scratchpad[:initialized] = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def attached
|
17
|
+
$scratchpad[:attached] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def detached
|
21
|
+
$scratchpad[:detached] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def adopted
|
25
|
+
$scratchpad[:adopted] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def attribute_changed(attr, from, to)
|
29
|
+
$scratchpad[:attribute_changed] = [attr, from, to]
|
30
|
+
end
|
31
|
+
|
32
|
+
self.observed_attributes = observed_attrs
|
33
|
+
|
34
|
+
def_custom name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "upgrades" do
|
39
|
+
html <<-HTML
|
40
|
+
<app-ex1></app-ex1>
|
41
|
+
<app-ex2></app-ex2>
|
42
|
+
<app-ex7 prop="true"></app-ex7>
|
43
|
+
HTML
|
44
|
+
|
45
|
+
it "existing elements when they have been initialized before" do
|
46
|
+
expect($document.at_css("app-ex1").class).to eq(Browser::DOM::Element)
|
47
|
+
klass = create_custom_class("app-ex1")
|
48
|
+
expect($document.at_css("app-ex1").class).to eq(klass)
|
49
|
+
expect($scratchpad[:initialized]).to be(true)
|
50
|
+
expect($scratchpad[:attached]).to be(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "existing elements when they have not been initialized before" do
|
54
|
+
klass = create_custom_class("app-ex2")
|
55
|
+
expect($scratchpad[:initialized]).to be(true)
|
56
|
+
expect($scratchpad[:attached]).to be(true)
|
57
|
+
expect($document.at_css("app-ex2").class).to eq(klass)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "and fires property update events when upgraded" do
|
61
|
+
klass = create_custom_class("app-ex7", ["prop"])
|
62
|
+
expect($scratchpad[:attribute_changed]).to eq([:prop, nil, "true"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "creates and handles new elements correctly" do
|
67
|
+
klass = create_custom_class("app-ex3")
|
68
|
+
elem = klass.new
|
69
|
+
expect($scratchpad[:initialized]).to be(true)
|
70
|
+
expect($scratchpad[:attached]).to be(false)
|
71
|
+
$document.body << elem
|
72
|
+
expect($scratchpad[:detached]).to be(false)
|
73
|
+
expect($scratchpad[:attached]).to be(true)
|
74
|
+
elem.remove
|
75
|
+
expect($scratchpad[:detached]).to be(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "correctly tracks updated properties" do
|
79
|
+
klass = create_custom_class("app-ex4")
|
80
|
+
elem = klass.new
|
81
|
+
expect($scratchpad[:attribute_changed]).to be(false)
|
82
|
+
elem[:untracked] = "test"
|
83
|
+
expect($scratchpad[:attribute_changed]).to be(false)
|
84
|
+
|
85
|
+
klass = create_custom_class("app-ex5", ["tracked"])
|
86
|
+
elem = klass.new
|
87
|
+
expect($scratchpad[:attribute_changed]).to be(false)
|
88
|
+
elem[:untracked] = "test"
|
89
|
+
expect($scratchpad[:attribute_changed]).to be(false)
|
90
|
+
elem[:tracked] = "test"
|
91
|
+
expect($scratchpad[:attribute_changed]).to eq([:tracked, nil, "test"])
|
92
|
+
end
|
93
|
+
|
94
|
+
it "allows creation of custom elements in various ways" do
|
95
|
+
klass = create_custom_class("app-ex6")
|
96
|
+
|
97
|
+
elem = klass.new
|
98
|
+
expect(elem).to be_a(klass)
|
99
|
+
elem = $document.create_element("app-ex6")
|
100
|
+
expect(elem).to be_a(klass)
|
101
|
+
elem = DOM("<app-ex6>")
|
102
|
+
expect(elem).to be_a(klass)
|
103
|
+
elem = DOM { e("app-ex6") }
|
104
|
+
expect(elem).to be_a(klass)
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Browser::DOM::Element subclassing" do
|
4
|
+
class1 = Class.new(Browser::DOM::Element) do
|
5
|
+
def_selector ".class1"
|
6
|
+
|
7
|
+
def hello
|
8
|
+
"world"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class2 = Class.new(Browser::DOM::Element::Input) do
|
13
|
+
def_selector "input.class2[type='text']"
|
14
|
+
|
15
|
+
def hello
|
16
|
+
"goodbye"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class3 = Class.new(class2) do
|
21
|
+
def_selector "input.class2.class3[type='text']"
|
22
|
+
|
23
|
+
def self.create(value)
|
24
|
+
super().tap { |elem| elem.value = value }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class4 = Class.new(Browser::DOM::Element) do
|
29
|
+
def_selector "custom-element"
|
30
|
+
|
31
|
+
def hello
|
32
|
+
text
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
html <<-HTML
|
37
|
+
<div class='class1' id='hiho'></div>
|
38
|
+
<input class='class2' type='text' id='hoho'></div>
|
39
|
+
<input class='class2' type='hidden' id='hehe'></div>
|
40
|
+
<custom-element id='class4'>value</custom-element>
|
41
|
+
HTML
|
42
|
+
|
43
|
+
it 'dispatches from DOM correctly' do
|
44
|
+
elem = $document.at_css('#hiho')
|
45
|
+
expect(elem.class).to eq(class1)
|
46
|
+
expect(elem.hello).to eq('world')
|
47
|
+
|
48
|
+
elem = $document.at_css('#hoho')
|
49
|
+
expect(elem.class).to eq(class2)
|
50
|
+
expect(elem.hello).to eq('goodbye')
|
51
|
+
|
52
|
+
elem = $document.at_css('#hehe')
|
53
|
+
expect(elem.class).to eq(Browser::DOM::Element::Input)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'supports creating elements correctly' do
|
57
|
+
elem = class1.create
|
58
|
+
expect(elem.class).to eq(class1)
|
59
|
+
expect(elem.class_name).to eq('class1')
|
60
|
+
expect(elem.name).to eq('DIV')
|
61
|
+
expect(elem.hello).to eq('world')
|
62
|
+
|
63
|
+
elem = class2.create
|
64
|
+
expect(elem.class).to eq(class2)
|
65
|
+
expect(elem.class_name).to eq('class2')
|
66
|
+
expect(elem.name).to eq('INPUT')
|
67
|
+
expect(elem.hello).to eq('goodbye')
|
68
|
+
expect(elem.type).to eq('text')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'supports nested subclassing and .create overloading' do
|
72
|
+
elem = class3.create('well')
|
73
|
+
expect(elem.class).to eq(class3)
|
74
|
+
expect(elem.class_name).to eq('class2 class3')
|
75
|
+
expect(elem.value).to eq('well')
|
76
|
+
expect(elem.hello).to eq('goodbye')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'supports custom elements' do
|
80
|
+
elem = $document.at_css('#class4')
|
81
|
+
expect(elem.class).to eq(class4)
|
82
|
+
expect(elem.name).to eq('CUSTOM-ELEMENT')
|
83
|
+
expect(elem.hello).to eq('value')
|
84
|
+
|
85
|
+
elem = class4.create
|
86
|
+
expect(elem.class).to eq(class4)
|
87
|
+
expect(elem.name).to eq('CUSTOM-ELEMENT')
|
88
|
+
expect(elem.hello).to eq('')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'works with Paggio' do
|
92
|
+
elem = DOM { div.class1 }
|
93
|
+
expect(elem.class).to eq(class1)
|
94
|
+
expect(elem.hello).to eq('world')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'works with Paggio with a .create/.new intializer' do
|
98
|
+
elems = DOM {
|
99
|
+
class1.create(self)
|
100
|
+
class1.new(self, attrs: { x: :y })
|
101
|
+
class1.new(self)
|
102
|
+
}
|
103
|
+
expect(elems.class).to eq(Browser::DOM::NodeSet)
|
104
|
+
expect(elems.length).to eq(3)
|
105
|
+
expect(elems[1][:x]).to eq(:y)
|
106
|
+
expect(elems.to_ary.map(&:class)).to eq([class1] * 3)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'works with Paggio, .create/.new and nested blocks' do
|
110
|
+
elem = DOM { |d|
|
111
|
+
class1.new(d) {
|
112
|
+
d.div.noticeme
|
113
|
+
class1.new(d) {
|
114
|
+
d.div.noticeme3
|
115
|
+
}
|
116
|
+
d.div.noticeme2
|
117
|
+
}
|
118
|
+
}
|
119
|
+
expect(elem.class).to eq(class1)
|
120
|
+
expect(elem.children.length).to eq(3)
|
121
|
+
expect(elem.children[1].class).to eq(class1)
|
122
|
+
expect(elem.children[1].children.length).to eq(1)
|
123
|
+
expect(elem.children[0].class).to eq(Browser::DOM::Element)
|
124
|
+
expect(elem.children[2].class).to eq(Browser::DOM::Element)
|
125
|
+
expect(elem.children[1].children[0].class).to eq(Browser::DOM::Element)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'works with Paggio, .create/.new, nested blocks and without DOM{}' do
|
129
|
+
elem = class1.new {
|
130
|
+
div.noticeme
|
131
|
+
class1.new(self) {
|
132
|
+
div.noticeme3
|
133
|
+
}
|
134
|
+
div.noticeme2
|
135
|
+
}
|
136
|
+
expect(elem.class).to eq(class1)
|
137
|
+
expect(elem.children.length).to eq(3)
|
138
|
+
expect(elem.children[1].class).to eq(class1)
|
139
|
+
expect(elem.children[1].children.length).to eq(1)
|
140
|
+
expect(elem.children[0].class).to eq(Browser::DOM::Element)
|
141
|
+
expect(elem.children[2].class).to eq(Browser::DOM::Element)
|
142
|
+
expect(elem.children[1].children[0].class).to eq(Browser::DOM::Element)
|
143
|
+
end
|
144
|
+
end
|