fron 0.1.4 → 0.2.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.reek +11 -0
  4. data/.rubocop.yml +54 -0
  5. data/.travis.yml +11 -0
  6. data/.yardopts +4 -0
  7. data/Changelog.md +7 -0
  8. data/Gemfile +3 -1
  9. data/Gemfile.lock +106 -15
  10. data/Rakefile +19 -15
  11. data/Readme.md +23 -0
  12. data/fron.gemspec +2 -2
  13. data/lib/fron/version.rb +2 -1
  14. data/opal/fron.rb +5 -5
  15. data/opal/fron/core.rb +3 -10
  16. data/opal/fron/core/behaviors/components.rb +42 -0
  17. data/opal/fron/core/behaviors/events.rb +27 -0
  18. data/opal/fron/core/behaviors/routes.rb +59 -0
  19. data/opal/fron/core/component.rb +64 -90
  20. data/opal/fron/core/eventable.rb +18 -0
  21. data/opal/fron/core/logger.rb +10 -1
  22. data/opal/fron/core_ext.rb +9 -0
  23. data/opal/fron/core_ext/array.rb +12 -0
  24. data/opal/fron/core_ext/date.rb +57 -0
  25. data/opal/fron/core_ext/hash.rb +52 -0
  26. data/opal/fron/core_ext/kernel.rb +57 -0
  27. data/opal/fron/core_ext/nil.rb +7 -0
  28. data/opal/fron/core_ext/numeric.rb +19 -0
  29. data/opal/fron/core_ext/object.rb +11 -0
  30. data/opal/fron/core_ext/proc.rb +19 -0
  31. data/opal/fron/{core-ext → core_ext}/string.rb +4 -0
  32. data/opal/fron/dom.rb +15 -13
  33. data/opal/fron/dom/document.rb +22 -6
  34. data/opal/fron/dom/element.rb +105 -67
  35. data/opal/fron/dom/event.rb +110 -40
  36. data/opal/fron/dom/{file-reader.rb → file_reader.rb} +6 -1
  37. data/opal/fron/dom/fragment.rb +2 -0
  38. data/opal/fron/dom/modules/attributes.rb +43 -0
  39. data/opal/fron/dom/modules/classlist.rb +26 -13
  40. data/opal/fron/dom/modules/dimensions.rb +79 -9
  41. data/opal/fron/dom/modules/element_accessor.rb +35 -0
  42. data/opal/fron/dom/modules/events.rb +67 -20
  43. data/opal/fron/dom/node.rb +98 -39
  44. data/opal/fron/dom/nodelist.rb +9 -2
  45. data/opal/fron/dom/style.rb +23 -2
  46. data/opal/fron/dom/text.rb +4 -0
  47. data/opal/fron/dom/window.rb +31 -2
  48. data/opal/fron/event_mock.rb +54 -0
  49. data/opal/fron/js/syntetic_event.js +16 -0
  50. data/opal/fron/request.rb +2 -2
  51. data/opal/fron/request/request.rb +77 -14
  52. data/opal/fron/request/response.rb +33 -6
  53. data/opal/fron/storage.rb +1 -1
  54. data/opal/fron/storage/local_storage.rb +54 -0
  55. data/opal/fron/utils/drag.rb +135 -0
  56. data/opal/fron/utils/keyboard.rb +70 -0
  57. data/opal/fron/utils/point.rb +78 -0
  58. data/opal/fron/utils/render_proc.rb +27 -0
  59. data/spec/core-ext/array_spec.rb +15 -0
  60. data/spec/core-ext/date_spec.rb +54 -0
  61. data/spec/core-ext/hash_spec.rb +18 -2
  62. data/spec/core-ext/kernel_spec.rb +57 -0
  63. data/spec/core-ext/nil_spec.rb +9 -0
  64. data/spec/core-ext/numeric_spec.rb +25 -0
  65. data/spec/core-ext/proc_spec.rb +15 -0
  66. data/spec/core-ext/string_spec.rb +11 -0
  67. data/spec/core/behaviors/events_spec.rb +25 -0
  68. data/spec/core/behaviors/routes_spec.rb +59 -0
  69. data/spec/core/component_inheritance_spec.rb +26 -16
  70. data/spec/core/component_spec.rb +25 -29
  71. data/spec/core/eventable_spec.rb +19 -19
  72. data/spec/core/logger_spec.rb +5 -6
  73. data/spec/dom/document_spec.rb +4 -5
  74. data/spec/dom/element_spec.rb +106 -15
  75. data/spec/dom/event_spec.rb +101 -61
  76. data/spec/dom/file_reader_spec.rb +11 -0
  77. data/spec/dom/fragment_spec.rb +3 -4
  78. data/spec/dom/instance_retaining_spec.rb +58 -0
  79. data/spec/dom/modules/classlist_spec.rb +18 -19
  80. data/spec/dom/modules/dimensions_spec.rb +87 -22
  81. data/spec/dom/modules/events_spec.rb +22 -8
  82. data/spec/dom/node_spec.rb +25 -17
  83. data/spec/dom/nodelist_spec.rb +2 -3
  84. data/spec/dom/style_spec.rb +6 -5
  85. data/spec/dom/text_spec.rb +4 -3
  86. data/spec/dom/window_spec.rb +24 -9
  87. data/spec/js/mocks.js +14 -0
  88. data/spec/request/request_spec.rb +34 -15
  89. data/spec/request/response_spec.rb +9 -10
  90. data/spec/spec_helper.rb +11 -0
  91. data/spec/storage/{local-storage_spec.rb → local_storage_spec.rb} +6 -7
  92. data/spec/utils/drag_spec.rb +136 -0
  93. data/spec/utils/keyboard_spec.rb +75 -0
  94. data/spec/utils/point_spec.rb +55 -0
  95. data/spec/utils/render_proc_spec.rb +18 -0
  96. metadata +58 -36
  97. data/docs/application.md +0 -7
  98. data/docs/configuration.md +0 -29
  99. data/docs/controllers.md +0 -35
  100. data/docs/routing.md +0 -63
  101. data/opal/fron/core-ext.rb +0 -5
  102. data/opal/fron/core-ext/hash.rb +0 -31
  103. data/opal/fron/core-ext/kernel.rb +0 -10
  104. data/opal/fron/core-ext/numeric.rb +0 -9
  105. data/opal/fron/core-ext/proc.rb +0 -9
  106. data/opal/fron/core/adapters/local.rb +0 -43
  107. data/opal/fron/core/adapters/rails.rb +0 -65
  108. data/opal/fron/core/application.rb +0 -42
  109. data/opal/fron/core/configuration.rb +0 -29
  110. data/opal/fron/core/controller.rb +0 -41
  111. data/opal/fron/core/model.rb +0 -90
  112. data/opal/fron/core/router.rb +0 -86
  113. data/opal/fron/storage/local-storage.rb +0 -34
  114. data/spec/core/adapter/local_spec.rb +0 -65
  115. data/spec/core/adapter/rails_spec.rb +0 -77
  116. data/spec/core/application_spec.rb +0 -35
  117. data/spec/core/configuration_spec.rb +0 -20
  118. data/spec/core/controlller_spec.rb +0 -68
  119. data/spec/core/model_spec.rb +0 -125
  120. data/spec/core/router_spec.rb +0 -124
@@ -1,21 +1,21 @@
1
- require 'fron/dom'
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("@el") }
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 "#initailize" do
10
- context "string argument" do
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.hasClass('test').should be true
18
- el.hasClass('help').should be true
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 "node argument" do
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 "other argument" do
41
- it "should throw error" do
42
- expect(Proc.new { described_class.new({}) } ).to raise_error
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 'block'
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 "#html" do
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 "#value" do
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
@@ -1,120 +1,160 @@
1
- describe DOM::Event do
1
+ require 'spec_helper'
2
2
 
3
- subject { described_class.new data, Hash }
4
-
5
- let(:data) {%x{
6
- return { charCode: 1,
7
- keyCode: 2,
8
- pageX: 3,
9
- pageY: 4,
10
- screenX: 5,
11
- screenY: 6,
12
- clientX: 7,
13
- clientY: 8,
14
- altKey: true,
15
- shiftKey: false,
16
- ctrlKey: true,
17
- metaKey: false,
18
- preventDefault: function(){return 1},
19
- stopPropagation: function(){return 2},
20
- stopImmediatePropagation: function(){},
21
- target: {test: 'data'} }
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 "should call stopPropagation and preventDefault" do
26
- expect(subject).to receive(:stopPropagation).once
27
- expect(subject).to receive(:preventDefault).once
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 "#stopPropagation" do
33
- it 'should call stopPropagation of the event' do
34
- subject.stopPropagation.should eq 2
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 "#preventDefault" do
39
- it 'should call preventDefault of the event' do
40
- subject.preventDefault.should eq 1
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 "#target" do
85
+ describe '#target' do
45
86
  it 'should return the target' do
46
- subject.target['test'].should eq 'data'
47
- subject.target.class.should eq Hash
87
+ subject.target.should equal target
48
88
  end
49
89
  end
50
90
 
51
- describe "#charCode" do
52
- it 'should return the charCode' do
53
- subject.charCode.should eq 1
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 "#keyCode" do
58
- it 'should return the keyCode' do
59
- subject.keyCode.should eq 2
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 "#pageX" do
64
- it 'should return the pageX' do
65
- subject.pageX.should eq 3
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 "#pageY" do
70
- it 'should return the pageY' do
71
- subject.pageY.should eq 4
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 "#screenX" do
76
- it 'should return the screenX' do
77
- subject.screenX.should eq 5
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 "#screenY" do
82
- it 'should return the screenY' do
83
- subject.screenY.should eq 6
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 "#clientX" do
88
- it 'should return the clientX' do
89
- subject.clientX.should eq 7
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 "#clientY" do
94
- it 'should return the clientY' do
95
- subject.clientY.should eq 8
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 "#alt?" do
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 "#shift?" do
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 "#ctrl?" do
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 "#meta?" do
157
+ describe '#meta' do
118
158
  it 'should return the meta?' do
119
159
  subject.meta?.should eq false
120
160
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe DOM::FileReader do
4
+ let(:file) { `{ native: {} }` }
5
+
6
+ describe '#read_as_data_url' do
7
+ it 'should return data url' do
8
+ subject.read_as_data_url(file).should_not be nil
9
+ end
10
+ end
11
+ end
@@ -1,13 +1,12 @@
1
- require 'fron/dom'
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("@el")
10
- `el instanceof DocumentFragment`.should be true
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