fron 0.1.4 → 0.2.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.reek +11 -0
- data/.rubocop.yml +54 -0
- data/.travis.yml +11 -0
- data/.yardopts +4 -0
- data/Changelog.md +7 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +106 -15
- data/Rakefile +19 -15
- data/Readme.md +23 -0
- data/fron.gemspec +2 -2
- data/lib/fron/version.rb +2 -1
- data/opal/fron.rb +5 -5
- data/opal/fron/core.rb +3 -10
- data/opal/fron/core/behaviors/components.rb +42 -0
- data/opal/fron/core/behaviors/events.rb +27 -0
- data/opal/fron/core/behaviors/routes.rb +59 -0
- data/opal/fron/core/component.rb +64 -90
- data/opal/fron/core/eventable.rb +18 -0
- data/opal/fron/core/logger.rb +10 -1
- data/opal/fron/core_ext.rb +9 -0
- data/opal/fron/core_ext/array.rb +12 -0
- data/opal/fron/core_ext/date.rb +57 -0
- data/opal/fron/core_ext/hash.rb +52 -0
- data/opal/fron/core_ext/kernel.rb +57 -0
- data/opal/fron/core_ext/nil.rb +7 -0
- data/opal/fron/core_ext/numeric.rb +19 -0
- data/opal/fron/core_ext/object.rb +11 -0
- data/opal/fron/core_ext/proc.rb +19 -0
- data/opal/fron/{core-ext → core_ext}/string.rb +4 -0
- data/opal/fron/dom.rb +15 -13
- data/opal/fron/dom/document.rb +22 -6
- data/opal/fron/dom/element.rb +105 -67
- data/opal/fron/dom/event.rb +110 -40
- data/opal/fron/dom/{file-reader.rb → file_reader.rb} +6 -1
- data/opal/fron/dom/fragment.rb +2 -0
- data/opal/fron/dom/modules/attributes.rb +43 -0
- data/opal/fron/dom/modules/classlist.rb +26 -13
- data/opal/fron/dom/modules/dimensions.rb +79 -9
- data/opal/fron/dom/modules/element_accessor.rb +35 -0
- data/opal/fron/dom/modules/events.rb +67 -20
- data/opal/fron/dom/node.rb +98 -39
- data/opal/fron/dom/nodelist.rb +9 -2
- data/opal/fron/dom/style.rb +23 -2
- data/opal/fron/dom/text.rb +4 -0
- data/opal/fron/dom/window.rb +31 -2
- data/opal/fron/event_mock.rb +54 -0
- data/opal/fron/js/syntetic_event.js +16 -0
- data/opal/fron/request.rb +2 -2
- data/opal/fron/request/request.rb +77 -14
- data/opal/fron/request/response.rb +33 -6
- data/opal/fron/storage.rb +1 -1
- data/opal/fron/storage/local_storage.rb +54 -0
- data/opal/fron/utils/drag.rb +135 -0
- data/opal/fron/utils/keyboard.rb +70 -0
- data/opal/fron/utils/point.rb +78 -0
- data/opal/fron/utils/render_proc.rb +27 -0
- data/spec/core-ext/array_spec.rb +15 -0
- data/spec/core-ext/date_spec.rb +54 -0
- data/spec/core-ext/hash_spec.rb +18 -2
- data/spec/core-ext/kernel_spec.rb +57 -0
- data/spec/core-ext/nil_spec.rb +9 -0
- data/spec/core-ext/numeric_spec.rb +25 -0
- data/spec/core-ext/proc_spec.rb +15 -0
- data/spec/core-ext/string_spec.rb +11 -0
- data/spec/core/behaviors/events_spec.rb +25 -0
- data/spec/core/behaviors/routes_spec.rb +59 -0
- data/spec/core/component_inheritance_spec.rb +26 -16
- data/spec/core/component_spec.rb +25 -29
- data/spec/core/eventable_spec.rb +19 -19
- data/spec/core/logger_spec.rb +5 -6
- data/spec/dom/document_spec.rb +4 -5
- data/spec/dom/element_spec.rb +106 -15
- data/spec/dom/event_spec.rb +101 -61
- data/spec/dom/file_reader_spec.rb +11 -0
- data/spec/dom/fragment_spec.rb +3 -4
- data/spec/dom/instance_retaining_spec.rb +58 -0
- data/spec/dom/modules/classlist_spec.rb +18 -19
- data/spec/dom/modules/dimensions_spec.rb +87 -22
- data/spec/dom/modules/events_spec.rb +22 -8
- data/spec/dom/node_spec.rb +25 -17
- data/spec/dom/nodelist_spec.rb +2 -3
- data/spec/dom/style_spec.rb +6 -5
- data/spec/dom/text_spec.rb +4 -3
- data/spec/dom/window_spec.rb +24 -9
- data/spec/js/mocks.js +14 -0
- data/spec/request/request_spec.rb +34 -15
- data/spec/request/response_spec.rb +9 -10
- data/spec/spec_helper.rb +11 -0
- data/spec/storage/{local-storage_spec.rb → local_storage_spec.rb} +6 -7
- data/spec/utils/drag_spec.rb +136 -0
- data/spec/utils/keyboard_spec.rb +75 -0
- data/spec/utils/point_spec.rb +55 -0
- data/spec/utils/render_proc_spec.rb +18 -0
- metadata +58 -36
- data/docs/application.md +0 -7
- data/docs/configuration.md +0 -29
- data/docs/controllers.md +0 -35
- data/docs/routing.md +0 -63
- data/opal/fron/core-ext.rb +0 -5
- data/opal/fron/core-ext/hash.rb +0 -31
- data/opal/fron/core-ext/kernel.rb +0 -10
- data/opal/fron/core-ext/numeric.rb +0 -9
- data/opal/fron/core-ext/proc.rb +0 -9
- data/opal/fron/core/adapters/local.rb +0 -43
- data/opal/fron/core/adapters/rails.rb +0 -65
- data/opal/fron/core/application.rb +0 -42
- data/opal/fron/core/configuration.rb +0 -29
- data/opal/fron/core/controller.rb +0 -41
- data/opal/fron/core/model.rb +0 -90
- data/opal/fron/core/router.rb +0 -86
- data/opal/fron/storage/local-storage.rb +0 -34
- data/spec/core/adapter/local_spec.rb +0 -65
- data/spec/core/adapter/rails_spec.rb +0 -77
- data/spec/core/application_spec.rb +0 -35
- data/spec/core/configuration_spec.rb +0 -20
- data/spec/core/controlller_spec.rb +0 -68
- data/spec/core/model_spec.rb +0 -125
- data/spec/core/router_spec.rb +0 -124
@@ -1,72 +1,71 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DOM::ClassList do
|
4
|
-
|
5
4
|
let(:element) { DOM::Element.new 'div' }
|
6
5
|
subject { element['class'] }
|
7
6
|
|
8
|
-
describe '#
|
7
|
+
describe '#add_class' do
|
9
8
|
it 'should add a class' do
|
10
|
-
element.
|
9
|
+
element.add_class 'test'
|
11
10
|
subject.should eq 'test'
|
12
11
|
end
|
13
12
|
|
14
13
|
it 'should add multiple classes' do
|
15
|
-
element.
|
14
|
+
element.add_class 'test', 'help'
|
16
15
|
subject.should eq 'test help'
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
describe '#
|
19
|
+
describe '#remove_class' do
|
21
20
|
before do
|
22
21
|
element['class'] = 'test help'
|
23
22
|
end
|
24
23
|
|
25
24
|
it 'should add a class' do
|
26
|
-
element.
|
25
|
+
element.remove_class 'test'
|
27
26
|
subject.should eq 'help'
|
28
27
|
end
|
29
28
|
|
30
29
|
it 'should add multiple classes' do
|
31
|
-
element.
|
32
|
-
subject.should eq
|
30
|
+
element.remove_class 'test', 'help'
|
31
|
+
subject.should eq nil
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
36
|
-
describe '#
|
35
|
+
describe '#has_class' do
|
37
36
|
it 'should return true if the element has given class' do
|
38
37
|
element['class'] = 'test'
|
39
|
-
element.
|
38
|
+
element.has_class('test').should eq true
|
40
39
|
end
|
41
40
|
|
42
41
|
it 'should return flase if the element does not have the given class' do
|
43
|
-
element.
|
42
|
+
element.has_class('test').should eq false
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
describe '#
|
46
|
+
describe '#toggle_class' do
|
48
47
|
before do
|
49
48
|
element['class'] = 'test'
|
50
49
|
end
|
51
50
|
|
52
51
|
it 'should remove class if the element has the given class' do
|
53
|
-
element.
|
54
|
-
subject.should eq
|
52
|
+
element.toggle_class 'test'
|
53
|
+
subject.should eq nil
|
55
54
|
end
|
56
55
|
|
57
56
|
it 'should add class if the element does not have the given class' do
|
58
|
-
element.
|
57
|
+
element.toggle_class 'help'
|
59
58
|
subject.should eq 'test help'
|
60
59
|
end
|
61
60
|
|
62
61
|
it 'should add class if the second argument is true' do
|
63
|
-
element.
|
62
|
+
element.toggle_class 'help', true
|
64
63
|
subject.should eq 'test help'
|
65
64
|
end
|
66
65
|
|
67
66
|
it 'should remove class if the second argument if false' do
|
68
|
-
element.
|
69
|
-
subject.should eq
|
67
|
+
element.toggle_class 'test', false
|
68
|
+
subject.should eq nil
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
@@ -1,55 +1,120 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DOM::Dimensions do
|
4
|
-
|
5
|
-
let(:element) { DOM::Element.new 'div' }
|
4
|
+
subject { DOM::Element.new 'div' }
|
6
5
|
|
7
6
|
before do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
subject >> DOM::Document.body
|
8
|
+
subject.style.position = 'absolute'
|
9
|
+
subject.style.width = '100px'
|
10
|
+
subject.style.top = '40px'
|
11
|
+
subject.style.left = '60px'
|
12
|
+
subject.style.height = '80px'
|
14
13
|
end
|
15
14
|
|
16
15
|
after do
|
17
|
-
|
16
|
+
subject.remove!
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#scroll_top' do
|
20
|
+
it 'should return the scroll position' do
|
21
|
+
subject.scroll_top.should eq 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#scroll_left' do
|
26
|
+
it 'should return the scroll position' do
|
27
|
+
subject.scroll_left.should eq 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#cover?' do
|
32
|
+
let(:pos) { double x: 62, y: 82 }
|
33
|
+
it 'should return the true if it covers' do
|
34
|
+
subject.cover?(pos).should eq true
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
20
38
|
describe '#top' do
|
21
|
-
it 'should return the top position
|
22
|
-
|
39
|
+
it 'should return the top position' do
|
40
|
+
subject.top.should eq 40
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
26
44
|
describe '#left' do
|
27
|
-
it 'should return the left position
|
28
|
-
|
45
|
+
it 'should return the left position' do
|
46
|
+
subject.left.should eq 60
|
29
47
|
end
|
30
48
|
end
|
31
49
|
|
32
50
|
describe '#right' do
|
33
|
-
it 'should return the right position
|
34
|
-
|
51
|
+
it 'should return the right position' do
|
52
|
+
subject.right.should eq 160
|
35
53
|
end
|
36
54
|
end
|
37
55
|
|
38
56
|
describe '#bottom' do
|
39
|
-
it 'should return the bottom position
|
40
|
-
|
57
|
+
it 'should return the bottom position' do
|
58
|
+
subject.bottom.should eq 120
|
41
59
|
end
|
42
60
|
end
|
43
61
|
|
44
62
|
describe '#width' do
|
45
|
-
it 'should return the width
|
46
|
-
|
63
|
+
it 'should return the width' do
|
64
|
+
subject.width.should eq 100
|
47
65
|
end
|
48
66
|
end
|
49
67
|
|
50
68
|
describe '#height' do
|
51
|
-
it 'should return the height
|
52
|
-
|
69
|
+
it 'should return the height' do
|
70
|
+
subject.height.should eq 80
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#visible?' do
|
75
|
+
context 'display: none' do
|
76
|
+
it 'should return false' do
|
77
|
+
expect {
|
78
|
+
subject.style.display = 'none'
|
79
|
+
}.to change { subject.visible? }.from(true).to(false)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'not in viewport' do
|
84
|
+
height, width = `window.innerHeight`, `window.innerWidth`
|
85
|
+
[
|
86
|
+
[-80, -100], # Top Left
|
87
|
+
[-80, 0], # Top
|
88
|
+
[0, -100], # Left
|
89
|
+
[height, width], # Bottom Right
|
90
|
+
[height, 0], # Bottom
|
91
|
+
[0, width] # Right
|
92
|
+
].each do |item|
|
93
|
+
it "should return false for #{item}" do
|
94
|
+
top, left = item
|
95
|
+
expect {
|
96
|
+
subject.style.top = "#{top}px"
|
97
|
+
subject.style.left = "#{left}px"
|
98
|
+
}.to change { subject.visible? }.from(true).to(false)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context '0 size' do
|
104
|
+
it 'should return false' do
|
105
|
+
expect {
|
106
|
+
subject.style.width = 0
|
107
|
+
subject.style.height = 0
|
108
|
+
}.to change { subject.visible? }.from(true).to(false)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'not in dom' do
|
113
|
+
it 'should return false' do
|
114
|
+
expect {
|
115
|
+
subject.remove!
|
116
|
+
}.to change { subject.visible? }.from(true).to(false)
|
117
|
+
end
|
53
118
|
end
|
54
119
|
end
|
55
120
|
end
|
@@ -1,13 +1,27 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DOM::Events do
|
4
|
-
|
5
4
|
let(:element) { DOM::Element.new 'div' }
|
6
|
-
subject { element.instance_variable_get
|
5
|
+
subject { element.instance_variable_get '@listeners' }
|
7
6
|
|
8
7
|
describe '#on' do
|
9
8
|
async 'should register for event' do
|
10
|
-
listener = element.on 'click' do
|
9
|
+
listener = element.on 'click' do
|
10
|
+
run_async do
|
11
|
+
subject.should_not be nil
|
12
|
+
subject[:click].should_not be nil
|
13
|
+
subject[:click].length.should eq 1
|
14
|
+
subject[:click].include?(listener).should eq true
|
15
|
+
element.off 'click'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
element.trigger 'click'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#on!' do
|
23
|
+
async 'should register for event' do
|
24
|
+
listener = element.on! 'click' do
|
11
25
|
run_async do
|
12
26
|
subject.should_not be nil
|
13
27
|
subject[:click].should_not be nil
|
@@ -21,7 +35,7 @@ describe DOM::Events do
|
|
21
35
|
end
|
22
36
|
|
23
37
|
describe '#off' do
|
24
|
-
context
|
38
|
+
context 'two arguments' do
|
25
39
|
it 'should unregister for event' do
|
26
40
|
listener = element.on 'click' do end
|
27
41
|
subject[:click].include?(listener).should eq true
|
@@ -30,7 +44,7 @@ describe DOM::Events do
|
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
33
|
-
context
|
47
|
+
context 'one argument' do
|
34
48
|
it 'should unregister all events for type' do
|
35
49
|
listener = element.on 'click' do end
|
36
50
|
subject[:click].include?(listener).should eq true
|
@@ -39,7 +53,7 @@ describe DOM::Events do
|
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
context
|
56
|
+
context 'no argument' do
|
43
57
|
it 'should unregister all events' do
|
44
58
|
listener = element.on 'click' do end
|
45
59
|
subject[:click].include?(listener).should eq true
|
@@ -62,7 +76,7 @@ describe DOM::Events do
|
|
62
76
|
|
63
77
|
describe '#trigger' do
|
64
78
|
async 'should trigger the event' do
|
65
|
-
element.on 'click' do
|
79
|
+
element.on 'click' do
|
66
80
|
run_async do
|
67
81
|
element.off 'click'
|
68
82
|
end
|
data/spec/dom/node_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
+
# Test Node
|
3
4
|
class TestNode < DOM::NODE
|
4
5
|
attr_reader :el
|
5
6
|
end
|
6
7
|
|
7
8
|
describe TestNode do
|
8
|
-
|
9
9
|
let(:el) { DOM::Element.new('div') }
|
10
10
|
let(:body) { DOM::Document.body }
|
11
11
|
subject { described_class.new `document.createElement('div')` }
|
@@ -15,8 +15,7 @@ describe TestNode do
|
|
15
15
|
el.remove!
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
|
18
|
+
describe '#dup' do
|
20
19
|
let(:node) { subject.dup }
|
21
20
|
|
22
21
|
it 'should clone the node' do
|
@@ -28,7 +27,7 @@ describe TestNode do
|
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
describe
|
30
|
+
describe '#dup!' do
|
32
31
|
it 'should clone with children' do
|
33
32
|
subject << el
|
34
33
|
subject.children.length.should eq 1
|
@@ -44,18 +43,27 @@ describe TestNode do
|
|
44
43
|
|
45
44
|
it 'should return a new NODE' do
|
46
45
|
subject >> body
|
47
|
-
subject.parent.
|
46
|
+
subject.parent.should be_a DOM::NODE
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
describe
|
50
|
+
describe '#parent_node' do
|
52
51
|
it 'should return nil if there is no parent node' do
|
53
|
-
subject.
|
52
|
+
subject.parent_node.should eq nil
|
54
53
|
end
|
55
54
|
|
56
55
|
it 'should return a new NODE' do
|
57
56
|
subject >> body
|
58
|
-
subject.
|
57
|
+
subject.parent_node.should be_a DOM::NODE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#empty' do
|
62
|
+
it 'should remove all children' do
|
63
|
+
subject << el
|
64
|
+
expect {
|
65
|
+
subject.empty
|
66
|
+
}.to change { el.parent }.from(subject).to nil
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
@@ -114,25 +122,25 @@ describe TestNode do
|
|
114
122
|
end
|
115
123
|
end
|
116
124
|
|
117
|
-
describe '#
|
125
|
+
describe '#insert_before' do
|
118
126
|
let(:otherEl) { DOM::Element.new 'div' }
|
119
127
|
|
120
128
|
it 'should insert given node before the other given node' do
|
121
129
|
subject << el
|
122
130
|
subject << otherEl
|
123
|
-
el.should
|
131
|
+
(el > otherEl).should eq true
|
124
132
|
otherEl.should < el
|
125
133
|
end
|
126
134
|
end
|
127
135
|
|
128
|
-
describe
|
136
|
+
describe '#text' do
|
129
137
|
it 'should return the nodes textContent' do
|
130
138
|
`#{subject.el}.textContent = 'Test'`
|
131
139
|
subject.text.should eq 'Test'
|
132
140
|
end
|
133
141
|
end
|
134
142
|
|
135
|
-
describe
|
143
|
+
describe '#text=' do
|
136
144
|
it 'should set the nodes textContent' do
|
137
145
|
subject.text = 'Asd'
|
138
146
|
`#{subject.el}.textContent`.should eq 'Asd'
|
@@ -160,7 +168,7 @@ describe TestNode do
|
|
160
168
|
end
|
161
169
|
end
|
162
170
|
|
163
|
-
describe
|
171
|
+
describe '<=>' do
|
164
172
|
it 'should return 0 if nodes are the same' do
|
165
173
|
subject >> el
|
166
174
|
expect(el.children[0] <=> subject).to eq 0
|
@@ -168,20 +176,20 @@ describe TestNode do
|
|
168
176
|
|
169
177
|
it 'should throw if the nodes are not in the same parent' do
|
170
178
|
subject >> body
|
171
|
-
expect(
|
179
|
+
expect(proc { el <=> subject }).to raise_error
|
172
180
|
end
|
173
181
|
|
174
182
|
it 'should compare indexes if the nodes are in the same parent' do
|
175
183
|
subject >> body
|
176
184
|
el >> body
|
177
|
-
expect(el <=> subject).to eq
|
185
|
+
expect(el <=> subject).to eq(-1)
|
178
186
|
expect(subject <=> el).to eq 1
|
179
187
|
end
|
180
188
|
end
|
181
189
|
|
182
190
|
describe 'index' do
|
183
191
|
it 'should return index (position) of the node' do
|
184
|
-
el << DOM::
|
192
|
+
el << DOM::Element.new('test')
|
185
193
|
subject >> el
|
186
194
|
subject.index.should eq 1
|
187
195
|
end
|
data/spec/dom/nodelist_spec.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DOM::NodeList do
|
4
|
-
|
5
4
|
describe '#initialize' do
|
6
5
|
it 'should map nodes to elements' do
|
7
6
|
DOM::Document.body.children.each do |node|
|
8
|
-
node.
|
7
|
+
node.should be_a DOM::NODE
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
data/spec/dom/style_spec.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
+
describe DOM::Style do
|
3
4
|
subject { DOM::Element.new 'div' }
|
4
|
-
let(:el) { subject.instance_variable_get(
|
5
|
+
let(:el) { subject.instance_variable_get('@el') }
|
5
6
|
|
6
|
-
describe
|
7
|
+
describe 'method_missing' do
|
7
8
|
it 'should call []= if the methods ends with =' do
|
8
9
|
expect(subject.style).to receive(:[]=).with 'display', 'none'
|
9
10
|
subject.style.display = 'none'
|
@@ -15,14 +16,14 @@ describe DOM::Style do
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
describe
|
19
|
+
describe '[]=' do
|
19
20
|
it 'should set the given style' do
|
20
21
|
subject.style['display'] = 'none'
|
21
22
|
`#{el}.style.display`.should eq 'none'
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
describe
|
26
|
+
describe '[]'do
|
26
27
|
it 'should return with the value of the given style' do
|
27
28
|
`#{el}.style.display = 'block'`
|
28
29
|
subject.style['display'].should eq 'block'
|