fron 0.1.4 → 0.2.0rc1
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/.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
data/spec/dom/element_spec.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DOM::Element do
|
4
|
-
|
5
4
|
subject { described_class.new 'div' }
|
6
|
-
let(:el) { subject.instance_variable_get(
|
5
|
+
let(:el) { subject.instance_variable_get('@el') }
|
7
6
|
let(:a) { described_class.new 'a' }
|
7
|
+
let(:a2) { described_class.new 'a' }
|
8
8
|
|
9
|
-
describe
|
10
|
-
context
|
9
|
+
describe '#initailize' do
|
10
|
+
context 'string argument' do
|
11
11
|
it 'should create an element with tagname' do
|
12
12
|
described_class.new('div').tag.should eq 'div'
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should add classes' do
|
16
16
|
el = described_class.new('div.test.help')
|
17
|
-
el.
|
18
|
-
el.
|
17
|
+
el.has_class('test').should be true
|
18
|
+
el.has_class('help').should be true
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should set the id' do
|
@@ -30,16 +30,16 @@ describe DOM::Element do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
33
|
+
context 'node argument' do
|
34
34
|
it 'should link given node' do
|
35
35
|
el = described_class.new `document.body`
|
36
36
|
el.tag.should eq 'body'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
41
|
-
it
|
42
|
-
expect(
|
40
|
+
context 'other argument' do
|
41
|
+
it 'should throw error' do
|
42
|
+
expect(proc { described_class.new({}) }).to raise_error
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -54,6 +54,20 @@ describe DOM::Element do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
describe '#disabled' do
|
58
|
+
it 'should return the disabled state of the element' do
|
59
|
+
`#{el}.disabled = true`
|
60
|
+
subject.disabled.should eq true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#disabled=' do
|
65
|
+
it 'should set the disabled state of the element' do
|
66
|
+
subject.disabled = true
|
67
|
+
`#{el}.disabled`.should eq true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
57
71
|
describe '#hide' do
|
58
72
|
it 'should hide the element' do
|
59
73
|
subject.hide
|
@@ -64,7 +78,7 @@ describe DOM::Element do
|
|
64
78
|
describe '#show' do
|
65
79
|
it 'should show the element' do
|
66
80
|
subject.show
|
67
|
-
subject.style.display.should eq '
|
81
|
+
subject.style.display.should eq ''
|
68
82
|
end
|
69
83
|
end
|
70
84
|
|
@@ -82,6 +96,30 @@ describe DOM::Element do
|
|
82
96
|
end
|
83
97
|
end
|
84
98
|
|
99
|
+
describe '#attribute?' do
|
100
|
+
it 'should return true if there is an attribute flase if not' do
|
101
|
+
subject['test'] = 'data'
|
102
|
+
subject.attribute?(:test).should eq true
|
103
|
+
subject.attribute?(:some).should eq false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#remove_attribute' do
|
108
|
+
it 'should remove attribute' do
|
109
|
+
subject[:test] = 'data'
|
110
|
+
expect {
|
111
|
+
subject.remove_attribute(:test)
|
112
|
+
}.to change { subject.attribute?(:test) }.from(true).to(false)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#files' do
|
117
|
+
it 'sohuld return the files' do
|
118
|
+
`#{el}.files = []`
|
119
|
+
subject.files.should be_an Array
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
85
123
|
describe '#find' do
|
86
124
|
it 'should find a descendant element' do
|
87
125
|
a >> subject
|
@@ -93,7 +131,53 @@ describe DOM::Element do
|
|
93
131
|
end
|
94
132
|
end
|
95
133
|
|
96
|
-
describe
|
134
|
+
describe '#next' do
|
135
|
+
it 'should find the next element' do
|
136
|
+
a >> subject
|
137
|
+
a2 >> subject
|
138
|
+
a.next.should eq a2
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should return nil if no element is found' do
|
142
|
+
subject.next.should eq nil
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#previous' do
|
147
|
+
it 'should find the previous element' do
|
148
|
+
a >> subject
|
149
|
+
a2 >> subject
|
150
|
+
a2.previous.should eq a
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should return nil if no element is found' do
|
154
|
+
subject.previous.should eq nil
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#find_all' do
|
159
|
+
it 'should find all descendant elements' do
|
160
|
+
a >> subject
|
161
|
+
a2 >> subject
|
162
|
+
subject.find_all('a').count.should eq 2
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#include?' do
|
167
|
+
it 'should return true' do
|
168
|
+
a >> subject
|
169
|
+
subject.include?(a).should eq true
|
170
|
+
subject.include?(a2).should eq false
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#blur' do
|
175
|
+
it 'should blur the element' do
|
176
|
+
subject.blur
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#html' do
|
97
181
|
it 'should get the html of the element' do
|
98
182
|
`#{el}.innerHTML = 'test'`
|
99
183
|
subject.html.should eq 'test'
|
@@ -112,11 +196,11 @@ describe DOM::Element do
|
|
112
196
|
subject << a
|
113
197
|
subject.empty
|
114
198
|
subject.children.length.should eq 0
|
115
|
-
subject.html.should eq
|
199
|
+
subject.html.should eq nil
|
116
200
|
end
|
117
201
|
end
|
118
202
|
|
119
|
-
describe
|
203
|
+
describe '#value' do
|
120
204
|
it 'should get the value of the element' do
|
121
205
|
`#{el}.value = 'test'`
|
122
206
|
subject.value.should eq 'test'
|
@@ -161,4 +245,11 @@ describe DOM::Element do
|
|
161
245
|
subject.id.should eq 'test'
|
162
246
|
end
|
163
247
|
end
|
248
|
+
|
249
|
+
describe '#path' do
|
250
|
+
it 'should return the path' do
|
251
|
+
a >> subject
|
252
|
+
a.path.should eq 'div a'
|
253
|
+
end
|
254
|
+
end
|
164
255
|
end
|
data/spec/dom/event_spec.rb
CHANGED
@@ -1,120 +1,160 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
describe DOM::Event do
|
4
|
+
subject { described_class.new data }
|
5
|
+
let(:target) { DOM::Element.new('div') }
|
6
|
+
|
7
|
+
let(:data) {
|
8
|
+
%x{
|
9
|
+
return {
|
10
|
+
charCode: 1,
|
11
|
+
keyCode: 2,
|
12
|
+
pageX: 3,
|
13
|
+
pageY: 4,
|
14
|
+
screenX: 5,
|
15
|
+
screenY: 6,
|
16
|
+
clientX: 7,
|
17
|
+
clientY: 8,
|
18
|
+
button: 3,
|
19
|
+
altKey: true,
|
20
|
+
shiftKey: false,
|
21
|
+
ctrlKey: true,
|
22
|
+
metaKey: false,
|
23
|
+
dataTransfer: [],
|
24
|
+
missing: 'missing',
|
25
|
+
defaultPrevented: true,
|
26
|
+
preventDefault: function(){return 1},
|
27
|
+
stopPropagation: function(){return 2},
|
28
|
+
stopImmediatePropagation: function(){ return 3 },
|
29
|
+
target: #{target.instance_variable_get('@el')}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
23
33
|
|
24
34
|
describe '#stop' do
|
25
|
-
it
|
26
|
-
expect(subject).to receive(:
|
27
|
-
expect(subject).to receive(:
|
35
|
+
it 'should call stop_propagation and prevent_default' do
|
36
|
+
expect(subject).to receive(:stop_propagation).once
|
37
|
+
expect(subject).to receive(:prevent_default).once
|
38
|
+
expect(subject).to receive(:stop_immediate_propagation).once
|
28
39
|
subject.stop
|
29
40
|
end
|
30
41
|
end
|
31
42
|
|
32
|
-
describe
|
33
|
-
it 'should
|
34
|
-
subject.
|
43
|
+
describe '#data_transfer' do
|
44
|
+
it 'should return data_transfer' do
|
45
|
+
subject.data_transfer.should be_an Array
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#button' do
|
50
|
+
it 'should return button' do
|
51
|
+
subject.button.should eq 3
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#default_prevented?' do
|
56
|
+
it 'should return default_prevented?' do
|
57
|
+
subject.default_prevented?.should eq true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#stop_immediate_propagation' do
|
62
|
+
it 'should call stop_immediate_propagation of the event' do
|
63
|
+
subject.stop_immediate_propagation.should eq 3
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#method_missing' do
|
68
|
+
it 'should return the given attribute of the event' do
|
69
|
+
subject.missing.should eq 'missing'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#stop_propagation' do
|
74
|
+
it 'should call stop_propagation of the event' do
|
75
|
+
subject.stop_propagation.should eq 2
|
35
76
|
end
|
36
77
|
end
|
37
78
|
|
38
|
-
describe
|
39
|
-
it 'should call
|
40
|
-
subject.
|
79
|
+
describe '#prevent_default' do
|
80
|
+
it 'should call prevent_default of the event' do
|
81
|
+
subject.prevent_default.should eq 1
|
41
82
|
end
|
42
83
|
end
|
43
84
|
|
44
|
-
describe
|
85
|
+
describe '#target' do
|
45
86
|
it 'should return the target' do
|
46
|
-
subject.target
|
47
|
-
subject.target.class.should eq Hash
|
87
|
+
subject.target.should equal target
|
48
88
|
end
|
49
89
|
end
|
50
90
|
|
51
|
-
describe
|
52
|
-
it 'should return the
|
53
|
-
subject.
|
91
|
+
describe '#char_code' do
|
92
|
+
it 'should return the char_code' do
|
93
|
+
subject.char_code.should eq 1
|
54
94
|
end
|
55
95
|
end
|
56
96
|
|
57
|
-
describe
|
58
|
-
it 'should return the
|
59
|
-
subject.
|
97
|
+
describe '#key_code' do
|
98
|
+
it 'should return the key_code' do
|
99
|
+
subject.key_code.should eq 2
|
60
100
|
end
|
61
101
|
end
|
62
102
|
|
63
|
-
describe
|
64
|
-
it 'should return the
|
65
|
-
subject.
|
103
|
+
describe '#page_x' do
|
104
|
+
it 'should return the page_x' do
|
105
|
+
subject.page_x.should eq 3
|
66
106
|
end
|
67
107
|
end
|
68
108
|
|
69
|
-
describe
|
70
|
-
it 'should return the
|
71
|
-
subject.
|
109
|
+
describe '#page_y' do
|
110
|
+
it 'should return the page_y' do
|
111
|
+
subject.page_y.should eq 4
|
72
112
|
end
|
73
113
|
end
|
74
114
|
|
75
|
-
describe
|
76
|
-
it 'should return the
|
77
|
-
subject.
|
115
|
+
describe '#screen_x' do
|
116
|
+
it 'should return the screen_x' do
|
117
|
+
subject.screen_x.should eq 5
|
78
118
|
end
|
79
119
|
end
|
80
120
|
|
81
|
-
describe
|
82
|
-
it 'should return the
|
83
|
-
subject.
|
121
|
+
describe '#screen_y' do
|
122
|
+
it 'should return the screen_y' do
|
123
|
+
subject.screen_y.should eq 6
|
84
124
|
end
|
85
125
|
end
|
86
126
|
|
87
|
-
describe
|
88
|
-
it 'should return the
|
89
|
-
subject.
|
127
|
+
describe '#client_x' do
|
128
|
+
it 'should return the client_x' do
|
129
|
+
subject.client_x.should eq 7
|
90
130
|
end
|
91
131
|
end
|
92
132
|
|
93
|
-
describe
|
94
|
-
it 'should return the
|
95
|
-
subject.
|
133
|
+
describe '#client_y' do
|
134
|
+
it 'should return the client_y' do
|
135
|
+
subject.client_y.should eq 8
|
96
136
|
end
|
97
137
|
end
|
98
138
|
|
99
|
-
describe
|
139
|
+
describe '#alt' do
|
100
140
|
it 'should return the alt?' do
|
101
141
|
subject.alt?.should eq true
|
102
142
|
end
|
103
143
|
end
|
104
144
|
|
105
|
-
describe
|
145
|
+
describe '#shift' do
|
106
146
|
it 'should return the shift?' do
|
107
147
|
subject.shift?.should eq false
|
108
148
|
end
|
109
149
|
end
|
110
150
|
|
111
|
-
describe
|
151
|
+
describe '#ctrl' do
|
112
152
|
it 'should return the ctrl?' do
|
113
153
|
subject.ctrl?.should eq true
|
114
154
|
end
|
115
155
|
end
|
116
156
|
|
117
|
-
describe
|
157
|
+
describe '#meta' do
|
118
158
|
it 'should return the meta?' do
|
119
159
|
subject.meta?.should eq false
|
120
160
|
end
|
data/spec/dom/fragment_spec.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DOM::Fragment do
|
4
|
-
|
5
4
|
subject { described_class.new }
|
6
5
|
|
7
6
|
describe '#initailize' do
|
8
7
|
it 'should create a document fragment' do
|
9
|
-
el = subject.instance_variable_get(
|
10
|
-
|
8
|
+
el = subject.instance_variable_get('@el')
|
9
|
+
`#{el} instanceof DocumentFragment`.should be true
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DOM::NODE do
|
4
|
+
let(:el) { `document.createElement('div')` }
|
5
|
+
subject { described_class.new el }
|
6
|
+
|
7
|
+
describe '#from_node' do
|
8
|
+
it 'should return the same instance if present' do
|
9
|
+
subject
|
10
|
+
described_class.from_node(el).should equal subject
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should create new instance if no instance present' do
|
14
|
+
described_class.from_node(el).should be_a DOM::NODE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Test Component
|
20
|
+
class RetainingComponent < Fron::Component
|
21
|
+
tag 'retaining'
|
22
|
+
|
23
|
+
component :test, 'test'
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'Intance retaining' do
|
27
|
+
let(:el) { RetainingComponent.new }
|
28
|
+
|
29
|
+
describe 'find' do
|
30
|
+
it 'should return component' do
|
31
|
+
DOM::Document.body << el
|
32
|
+
el1 = DOM::Document.body.find('retaining')
|
33
|
+
el1.should equal el
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'parent' do
|
38
|
+
it 'should return the component' do
|
39
|
+
el.test.parent.should equal el
|
40
|
+
el.test.parent_node.should equal el
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'children' do
|
45
|
+
it 'should contain the sub component' do
|
46
|
+
el.children[0].should equal el.test
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'event' do
|
51
|
+
it 'target should be the same instance' do
|
52
|
+
el.on 'click' do |event|
|
53
|
+
event.target.should equal el
|
54
|
+
end
|
55
|
+
el.trigger 'click'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|