fron 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/Rakefile +18 -0
- data/docs/configuration.md +8 -8
- data/lib/fron/version.rb +1 -1
- data/opal/fron/core.rb +1 -1
- data/opal/fron/core/adapters/{local-storage.rb → local.rb} +7 -6
- data/opal/fron/core/application.rb +13 -11
- data/opal/fron/core/configuration.rb +3 -4
- data/opal/fron/core/controller.rb +2 -2
- data/opal/fron/core/eventable.rb +5 -2
- data/opal/fron/core/logger.rb +7 -0
- data/opal/fron/core/model.rb +10 -8
- data/opal/fron/core/router.rb +1 -1
- data/opal/fron/dom.rb +1 -0
- data/opal/fron/dom/document.rb +4 -0
- data/opal/fron/dom/element.rb +22 -6
- data/opal/fron/dom/event.rb +71 -68
- data/opal/fron/dom/fragment.rb +1 -3
- data/opal/fron/dom/modules/classlist.rb +2 -2
- data/opal/fron/dom/modules/dimensions.rb +7 -8
- data/opal/fron/dom/modules/events.rb +57 -12
- data/opal/fron/dom/node.rb +45 -11
- data/opal/fron/dom/nodelist.rb +14 -0
- data/opal/fron/dom/style.rb +17 -15
- data/opal/fron/dom/text.rb +2 -4
- data/opal/fron/dom/window.rb +2 -3
- data/opal/fron/request/request.rb +17 -14
- data/opal/fron/storage/local-storage.rb +29 -13
- data/spec/core-ext/hash_spec.rb +18 -0
- data/spec/core/adapter/local_spec.rb +65 -0
- data/spec/core/adapter/rails_spec.rb +72 -0
- data/spec/core/application_spec.rb +35 -0
- data/spec/core/component_spec.rb +107 -0
- data/spec/core/configuration_spec.rb +20 -0
- data/spec/core/controlller_spec.rb +68 -0
- data/spec/core/eventable_spec.rb +74 -0
- data/spec/core/logger_spec.rb +28 -0
- data/spec/core/model_spec.rb +125 -0
- data/spec/core/router_spec.rb +127 -0
- data/spec/dom/document_spec.rb +41 -0
- data/spec/dom/element_spec.rb +164 -0
- data/spec/dom/event_spec.rb +121 -0
- data/spec/dom/fragment_spec.rb +13 -0
- data/spec/dom/modules/classlist_spec.rb +72 -0
- data/spec/dom/modules/dimensions_spec.rb +55 -0
- data/spec/dom/modules/events_spec.rb +73 -0
- data/spec/dom/node_spec.rb +189 -0
- data/spec/dom/nodelist_spec.rb +12 -0
- data/spec/dom/style_spec.rb +31 -0
- data/spec/dom/text_spec.rb +12 -0
- data/spec/dom/window_spec.rb +30 -0
- data/spec/request/request_spec.rb +71 -0
- data/spec/request/response_spec.rb +46 -0
- data/spec/storage/local-storage_spec.rb +58 -0
- metadata +36 -4
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'fron/dom'
|
2
|
+
|
3
|
+
describe DOM::Fragment do
|
4
|
+
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
describe '#initailize' do
|
8
|
+
it 'should create a document fragment' do
|
9
|
+
el = subject.instance_variable_get("@el")
|
10
|
+
`el instanceof DocumentFragment`.should be true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'fron/dom'
|
2
|
+
|
3
|
+
describe DOM::ClassList do
|
4
|
+
|
5
|
+
let(:element) { DOM::Element.new 'div' }
|
6
|
+
subject { element['class'] }
|
7
|
+
|
8
|
+
describe '#addClass' do
|
9
|
+
it 'should add a class' do
|
10
|
+
element.addClass 'test'
|
11
|
+
subject.should eq 'test'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should add multiple classes' do
|
15
|
+
element.addClass 'test', 'help'
|
16
|
+
subject.should eq 'test help'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#removeClass' do
|
21
|
+
before do
|
22
|
+
element['class'] = 'test help'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should add a class' do
|
26
|
+
element.removeClass 'test'
|
27
|
+
subject.should eq 'help'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should add multiple classes' do
|
31
|
+
element.removeClass 'test', 'help'
|
32
|
+
subject.should eq ''
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#hasClass' do
|
37
|
+
it 'should return true if the element has given class' do
|
38
|
+
element['class'] = 'test'
|
39
|
+
element.hasClass('test').should eq true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return flase if the element does not have the given class' do
|
43
|
+
element.hasClass('test').should eq false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#toggleClass' do
|
48
|
+
before do
|
49
|
+
element['class'] = 'test'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should remove class if the element has the given class' do
|
53
|
+
element.toggleClass 'test'
|
54
|
+
subject.should eq ''
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should add class if the element does not have the given class' do
|
58
|
+
element.toggleClass 'help'
|
59
|
+
subject.should eq 'test help'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should add class if the second argument is true' do
|
63
|
+
element.toggleClass 'help', true
|
64
|
+
subject.should eq 'test help'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should remove class if the second argument if false' do
|
68
|
+
element.toggleClass 'test', false
|
69
|
+
subject.should eq ''
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'fron/dom'
|
2
|
+
|
3
|
+
describe DOM::Dimensions do
|
4
|
+
|
5
|
+
let(:element) { DOM::Element.new 'div' }
|
6
|
+
|
7
|
+
before do
|
8
|
+
element >> DOM::Document.body
|
9
|
+
element.style.position = 'absolute'
|
10
|
+
element.style.width = '100px'
|
11
|
+
element.style.top = '40px'
|
12
|
+
element.style.left = '60px'
|
13
|
+
element.style.height = '80px'
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
element.remove!
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#top' do
|
21
|
+
it 'should return the top position of the element' do
|
22
|
+
element.top.should eq 40
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#left' do
|
27
|
+
it 'should return the left position of the element' do
|
28
|
+
element.left.should eq 60
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#right' do
|
33
|
+
it 'should return the right position of the element' do
|
34
|
+
element.right.should eq 160
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#bottom' do
|
39
|
+
it 'should return the bottom position of the element' do
|
40
|
+
element.bottom.should eq 120
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#width' do
|
45
|
+
it 'should return the width of the element' do
|
46
|
+
element.width.should eq 100
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#height' do
|
51
|
+
it 'should return the height of the element' do
|
52
|
+
element.height.should eq 80
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'fron/dom'
|
2
|
+
|
3
|
+
describe DOM::Events do
|
4
|
+
|
5
|
+
let(:element) { DOM::Element.new 'div' }
|
6
|
+
subject { element.instance_variable_get("@listeners") }
|
7
|
+
|
8
|
+
describe '#on' do
|
9
|
+
async 'should register for event' do
|
10
|
+
listener = element.on 'click' do |event|
|
11
|
+
run_async do
|
12
|
+
subject.should_not be nil
|
13
|
+
subject[:click].should_not be nil
|
14
|
+
subject[:click].length.should eq 1
|
15
|
+
subject[:click].include?(listener).should eq true
|
16
|
+
element.off 'click'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
element.trigger 'click'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#off' do
|
24
|
+
context "two arguments" do
|
25
|
+
it 'should unregister for event' do
|
26
|
+
listener = element.on 'click' do end
|
27
|
+
subject[:click].include?(listener).should eq true
|
28
|
+
element.off 'click', listener
|
29
|
+
subject[:click].include?(listener).should eq false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "one argument" do
|
34
|
+
it 'should unregister all events for type' do
|
35
|
+
listener = element.on 'click' do end
|
36
|
+
subject[:click].include?(listener).should eq true
|
37
|
+
element.off 'click'
|
38
|
+
subject[:click].include?(listener).should eq false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "no argument" do
|
43
|
+
it 'should unregister all events' do
|
44
|
+
listener = element.on 'click' do end
|
45
|
+
subject[:click].include?(listener).should eq true
|
46
|
+
element.off
|
47
|
+
subject[:click].include?(listener).should eq false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#delegate' do
|
53
|
+
async 'should call the listener if the element matches the selector' do
|
54
|
+
element.delegate 'click', 'div' do
|
55
|
+
run_async do
|
56
|
+
element.off 'click'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
element.trigger 'click'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#trigger' do
|
64
|
+
async 'should trigger the event' do
|
65
|
+
element.on 'click' do |event|
|
66
|
+
run_async do
|
67
|
+
element.off 'click'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
element.trigger 'click'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'fron/dom'
|
2
|
+
|
3
|
+
class TestNode < DOM::NODE
|
4
|
+
attr_reader :el
|
5
|
+
end
|
6
|
+
|
7
|
+
describe TestNode do
|
8
|
+
|
9
|
+
let(:el) { DOM::Element.new('div') }
|
10
|
+
let(:body) { DOM::Document.body }
|
11
|
+
subject { described_class.new `document.createElement('div')` }
|
12
|
+
|
13
|
+
after do
|
14
|
+
subject.remove!
|
15
|
+
el.remove!
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#dup" do
|
19
|
+
|
20
|
+
let(:node) { subject.dup }
|
21
|
+
|
22
|
+
it 'should clone the node' do
|
23
|
+
node.should_not eq subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have the same class' do
|
27
|
+
node.class.should eq TestNode
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#dup!" do
|
32
|
+
it 'should clone with children' do
|
33
|
+
subject << el
|
34
|
+
subject.children.length.should eq 1
|
35
|
+
node = subject.dup!
|
36
|
+
node.children.length.should eq 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#parent' do
|
41
|
+
it 'should return nil if there is no parent node' do
|
42
|
+
subject.parent.should eq nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return a new NODE' do
|
46
|
+
subject >> body
|
47
|
+
subject.parent.class.should eq DOM::NODE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#parentNode" do
|
52
|
+
it 'should return nil if there is no parent node' do
|
53
|
+
subject.parentNode.should eq nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return a new NODE' do
|
57
|
+
subject >> body
|
58
|
+
subject.parentNode.class.should eq DOM::NODE
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#empty?' do
|
63
|
+
it 'should return true for no children' do
|
64
|
+
subject.empty?.should be true
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return false for children' do
|
68
|
+
subject << el
|
69
|
+
subject.empty?.should be false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#children' do
|
74
|
+
it 'should return a list of children' do
|
75
|
+
subject << el
|
76
|
+
subject.children.length.should be 1
|
77
|
+
subject.children.class.should eq DOM::NodeList
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#remove' do
|
82
|
+
it 'should remove the given node from this node' do
|
83
|
+
subject << el
|
84
|
+
el.parent.should_not eq nil
|
85
|
+
subject.remove el
|
86
|
+
el.parent.should eq nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#remove!' do
|
91
|
+
it 'should remove the node for its parent node' do
|
92
|
+
subject >> body
|
93
|
+
subject.parent.should_not eq nil
|
94
|
+
subject.remove!
|
95
|
+
subject.parent.should eq nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#<<' do
|
100
|
+
it 'should append given node to the node' do
|
101
|
+
subject << el
|
102
|
+
subject.children.length.should eq 1
|
103
|
+
el.parent.should_not be nil
|
104
|
+
el.parent.should eq subject
|
105
|
+
subject.children.include?(el).should be true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#>>' do
|
110
|
+
it 'should append the node to the given node' do
|
111
|
+
subject >> body
|
112
|
+
subject.parent.should_not be nil
|
113
|
+
subject.parent.should eq body
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#insertBefore' do
|
118
|
+
let(:otherEl) { DOM::Element.new 'div' }
|
119
|
+
|
120
|
+
it 'should insert given node before the other given node' do
|
121
|
+
subject << el
|
122
|
+
subject << otherEl
|
123
|
+
el.should > otherEl
|
124
|
+
otherEl.should < el
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#text" do
|
129
|
+
it 'should return the nodes textContent' do
|
130
|
+
`#{subject.el}.textContent = 'Test'`
|
131
|
+
subject.text.should eq 'Test'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#text=" do
|
136
|
+
it 'should set the nodes textContent' do
|
137
|
+
subject.text = 'Asd'
|
138
|
+
`#{subject.el}.textContent`.should eq 'Asd'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#normalize!' do
|
143
|
+
it 'should normalize the node' do
|
144
|
+
subject << DOM::Text.new('a')
|
145
|
+
subject << DOM::Text.new('b')
|
146
|
+
subject.children.length.should eq 2
|
147
|
+
subject.normalize!
|
148
|
+
subject.children.length.should eq 1
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#==' do
|
153
|
+
it 'should return true for same el' do
|
154
|
+
subject >> el
|
155
|
+
subject.should == el.children[0]
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should return false for not same el' do
|
159
|
+
expect(subject != el).to eq true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "<=>" do
|
164
|
+
it 'should return 0 if nodes are the same' do
|
165
|
+
subject >> el
|
166
|
+
expect(el.children[0] <=> subject).to eq 0
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should throw if the nodes are not in the same parent' do
|
170
|
+
subject >> body
|
171
|
+
expect(Proc.new { el <=> subject } ).to raise_error
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should compare indexes if the nodes are in the same parent' do
|
175
|
+
subject >> body
|
176
|
+
el >> body
|
177
|
+
expect(el <=> subject).to eq -1
|
178
|
+
expect(subject <=> el).to eq 1
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe 'index' do
|
183
|
+
it 'should return index (position) of the node' do
|
184
|
+
el << DOM::Text.new('Test')
|
185
|
+
subject >> el
|
186
|
+
subject.index.should eq 1
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
describe DOM::Style do
|
2
|
+
|
3
|
+
subject { DOM::Element.new 'div' }
|
4
|
+
let(:el) { subject.instance_variable_get("@el") }
|
5
|
+
|
6
|
+
describe "method_missing" do
|
7
|
+
it 'should call []= if the methods ends with =' do
|
8
|
+
expect(subject.style).to receive(:[]=).with 'display', 'none'
|
9
|
+
subject.style.display = 'none'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should call [] if the method does not end with =' do
|
13
|
+
expect(subject.style).to receive(:[]).with 'display'
|
14
|
+
subject.style.display
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "[]=" do
|
19
|
+
it 'should set the given style' do
|
20
|
+
subject.style['display'] = 'none'
|
21
|
+
`#{el}.style.display`.should eq 'none'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "[]" do
|
26
|
+
it 'should return with the value of the given style' do
|
27
|
+
`#{el}.style.display = 'block'`
|
28
|
+
subject.style['display'].should eq 'block'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|