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,72 +1,71 @@
1
- require 'fron/dom'
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 '#addClass' do
7
+ describe '#add_class' do
9
8
  it 'should add a class' do
10
- element.addClass 'test'
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.addClass 'test', 'help'
14
+ element.add_class 'test', 'help'
16
15
  subject.should eq 'test help'
17
16
  end
18
17
  end
19
18
 
20
- describe '#removeClass' do
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.removeClass 'test'
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.removeClass 'test', 'help'
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 '#hasClass' do
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.hasClass('test').should eq true
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.hasClass('test').should eq false
42
+ element.has_class('test').should eq false
44
43
  end
45
44
  end
46
45
 
47
- describe '#toggleClass' do
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.toggleClass 'test'
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.toggleClass 'help'
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.toggleClass 'help', true
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.toggleClass 'test', false
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 'fron/dom'
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
- 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'
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
- element.remove!
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 of the element' do
22
- element.top.should eq 40
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 of the element' do
28
- element.left.should eq 60
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 of the element' do
34
- element.right.should eq 160
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 of the element' do
40
- element.bottom.should eq 120
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 of the element' do
46
- element.width.should eq 100
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 of the element' do
52
- element.height.should eq 80
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 'fron/dom'
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("@listeners") }
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 |event|
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 "two arguments" do
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 "one argument" do
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 "no argument" do
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 |event|
79
+ element.on 'click' do
66
80
  run_async do
67
81
  element.off 'click'
68
82
  end
@@ -1,11 +1,11 @@
1
- require 'fron/dom'
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 "#dup" do
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 "#dup!" do
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.class.should eq DOM::NODE
46
+ subject.parent.should be_a DOM::NODE
48
47
  end
49
48
  end
50
49
 
51
- describe "#parentNode" do
50
+ describe '#parent_node' do
52
51
  it 'should return nil if there is no parent node' do
53
- subject.parentNode.should eq nil
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.parentNode.class.should eq DOM::NODE
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 '#insertBefore' do
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 > otherEl
131
+ (el > otherEl).should eq true
124
132
  otherEl.should < el
125
133
  end
126
134
  end
127
135
 
128
- describe "#text" do
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 "#text=" do
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 "<=>" do
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(Proc.new { el <=> subject } ).to raise_error
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 -1
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::Text.new('Test')
192
+ el << DOM::Element.new('test')
185
193
  subject >> el
186
194
  subject.index.should eq 1
187
195
  end
@@ -1,11 +1,10 @@
1
- require 'fron/dom'
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.class.should eq DOM::NODE
7
+ node.should be_a DOM::NODE
9
8
  end
10
9
  end
11
10
  end
@@ -1,9 +1,10 @@
1
- describe DOM::Style do
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("@el") }
5
+ let(:el) { subject.instance_variable_get('@el') }
5
6
 
6
- describe "method_missing" do
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 "[]=" do
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 "[]" do
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'