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.
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
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe NilClass do
4
+ describe '#empty?' do
5
+ it 'should return true' do
6
+ subject.empty?.should eq true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Numeric do
4
+ subject { 0.5 }
5
+
6
+ describe '#clamp' do
7
+ it 'should clamp at minimum' do
8
+ subject.clamp(1, 2).should eq 1
9
+ end
10
+
11
+ it 'should clamp at max' do
12
+ subject.clamp(-2, -1).should eq(-1)
13
+ end
14
+
15
+ it 'should return value if in range' do
16
+ subject.clamp(0, 1).should eq 0.5
17
+ end
18
+ end
19
+
20
+ describe '#px' do
21
+ it 'should return the pixel representation' do
22
+ subject.px.should eq '1px'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Proc do
4
+ describe '#debounce' do
5
+ it 'should return Proc' do
6
+ proc {}.debounce(10).should be_a Proc
7
+ end
8
+ end
9
+
10
+ describe '#throttle' do
11
+ it 'should return Proc' do
12
+ proc {}.throttle(10).should be_a Proc
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ subject { 'asd_asd-asd' }
5
+
6
+ describe '#camelize' do
7
+ it 'should camelize the string' do
8
+ subject.camelize.should eq 'asdAsdAsd'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ # Test class for testing events behavior
4
+ class BehaviorsTest < Fron::Component
5
+ on :focus, 'button', :test
6
+ on :click, :click
7
+ end
8
+
9
+ describe Fron::Behaviors::Events do
10
+ let(:event) { `{ target: document.createElement('button') }` }
11
+
12
+ subject { BehaviorsTest.new }
13
+
14
+ it 'should create events' do
15
+ subject.listeners[:focus].count.should eq 1
16
+ subject.listeners[:click].count.should eq 1
17
+ end
18
+
19
+ it 'should call events' do
20
+ subject.should receive(:test)
21
+ subject.should receive(:click)
22
+ subject.listeners[:focus][0].call event
23
+ subject.listeners[:click][0].call event
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ # Failing Test Component
4
+ class FailRouteComponent < Fron::Component
5
+ include Fron::Behaviors::Routes
6
+
7
+ route 'something', :something
8
+ end
9
+
10
+ # Failing Test Component
11
+ class RouteComponent < Fron::Component
12
+ attr_reader :id
13
+
14
+ include Fron::Behaviors::Routes
15
+
16
+ route 'something', :something
17
+ route(/cards\/(.*)/, :card)
18
+
19
+ def something
20
+ end
21
+
22
+ def card
23
+ end
24
+ end
25
+
26
+ describe FailRouteComponent do
27
+ it 'should rasie error on initialize' do
28
+ expect { subject }.to raise_error
29
+ end
30
+ end
31
+
32
+ describe RouteComponent do
33
+ before do
34
+ Fron::Behaviors::Routes.instance_variable_set('@routes', [])
35
+ end
36
+
37
+ context 'Events' do
38
+ it 'should call handle_hash_change' do
39
+ Fron::Behaviors::Routes.listen
40
+ Fron::Behaviors::Routes.should receive(:handle_hash_change)
41
+ DOM::Window.listeners[:popstate].count.should eq 1
42
+ DOM::Window.listeners[:popstate][0].call
43
+ end
44
+ end
45
+
46
+ context 'Matching hash' do
47
+ it 'should call the method' do
48
+ subject.should receive(:something)
49
+ Fron::Behaviors::Routes.handle_hash_change('something')
50
+ end
51
+ end
52
+
53
+ context 'Parameters' do
54
+ it 'should call the method with matches' do
55
+ subject.should receive(:card).with 'id'
56
+ Fron::Behaviors::Routes.handle_hash_change('cards/id')
57
+ end
58
+ end
59
+ end
@@ -1,11 +1,21 @@
1
- require 'fron/core'
1
+ require 'spec_helper'
2
2
 
3
+ # Bevahviors
4
+ module Dummy
5
+ def self.included(base)
6
+ base.register self, [:dummy]
7
+ end
8
+ end
9
+
10
+ # Base Component
3
11
  class BaseComponent < Fron::Component
4
12
  component :text, 'text'
5
13
  on :click, :render
6
- delegate :text, :text
14
+
15
+ include Dummy
7
16
  end
8
17
 
18
+ # Inherited Component
9
19
  class InheritedComponent < BaseComponent
10
20
  component :title, 'title'
11
21
  end
@@ -16,28 +26,28 @@ end
16
26
  describe SuperComponent do
17
27
  subject { described_class }
18
28
 
19
- it "should inherit components in order" do
20
- subject.components.should_not be nil
21
- subject.components[0].should eq [:text,'text',nil]
22
- subject.components[1].should eq [:title,'title',nil]
29
+ let(:components) { subject.instance_variable_get('@component') }
30
+
31
+ it 'should inherit components in order' do
32
+ components.should_not be nil
33
+ components[0].should eq [:text, 'text']
34
+ components[1].should eq [:title, 'title']
23
35
  end
24
36
  end
25
37
 
26
38
  describe InheritedComponent do
27
39
  subject { described_class }
28
40
 
29
- it "should inherit components" do
30
- subject.components.should_not be nil
31
- subject.components[0].should eq [:text,'text',nil]
32
- end
41
+ let(:components) { subject.instance_variable_get('@component') }
42
+ let(:events) { subject.instance_variable_get('@on') }
33
43
 
34
- it "should inherit events" do
35
- subject.events.should_not be nil
36
- subject.events[0].should eq [:click, :render]
44
+ it 'should inherit components' do
45
+ components.should_not be nil
46
+ components[0].should eq [:text, 'text']
37
47
  end
38
48
 
39
- it "should inherit delegates" do
40
- subject.delegates.should_not be nil
41
- subject.delegates[0].should eq [:text,:text]
49
+ it 'should inherit events' do
50
+ events.should_not be nil
51
+ events[0].should eq [:click, :render]
42
52
  end
43
53
  end
@@ -1,5 +1,6 @@
1
- require 'fron/core'
1
+ require 'spec_helper'
2
2
 
3
+ # Test Component
3
4
  class TestComponent < Fron::Component
4
5
  attr_reader :rendered
5
6
 
@@ -9,56 +10,56 @@ class TestComponent < Fron::Component
9
10
  end
10
11
 
11
12
  describe Fron::Component do
12
-
13
13
  subject { TestComponent.new }
14
- let(:listeners) { subject.instance_variable_get("@listeners") }
15
14
 
16
- describe "DSL" do
15
+ let(:listeners) { subject.instance_variable_get '@listeners' }
16
+ let(:components) { subject.instance_variable_get('@component') }
17
+ let(:events) { subject.instance_variable_get('@on') }
17
18
 
19
+ describe 'DSL' do
18
20
  subject { TestComponent }
19
21
 
20
- describe "#tag" do
22
+ describe '#create' do
23
+ it 'should create class' do
24
+ test = subject.create('test')
25
+ test.should < subject
26
+ end
27
+ end
28
+
29
+ describe '#tag' do
21
30
  it 'should set the tagname' do
22
31
  subject.tag 'td'
23
32
  subject.tagname.should eq 'td'
24
33
  end
25
34
  end
26
35
 
27
- describe "#on" do
36
+ describe '#on' do
28
37
  it 'should create events array' do
29
38
  subject.on :click, :test
30
- subject.events.should_not be nil
39
+ events.should_not be nil
31
40
  end
32
41
 
33
42
  it 'should push event into the events array' do
34
43
  subject.on :click, :test
35
- subject.events.length.should be 2
44
+ events.length.should be 2
36
45
  end
37
46
  end
38
47
 
39
48
  describe '#component' do
40
49
  it 'should create components array' do
41
50
  subject.component :test, 'test'
42
- subject.components.should_not be nil
43
- subject.components.length.should be 1
51
+ components.should_not be nil
52
+ components.length.should be 1
44
53
  end
45
54
 
46
55
  it 'should create attr_reader for component' do
47
56
  subject.component :a, 'a'
48
- subject.instance_methods.include?(:a).should be true
49
- end
50
- end
51
-
52
- describe '#delegate' do
53
- it 'should create delegated methods' do
54
- subject.delegate :text, :test
55
- subject.delegates.should_not be nil
56
- subject.delegates[0].should eq [:text,:test]
57
+ subject.new.methods.include?(:a).should be true
57
58
  end
58
59
  end
59
60
  end
60
61
 
61
- describe "#initialize" do
62
+ describe '#initialize' do
62
63
  it 'should create element' do
63
64
  subject.tag.should eq 'td'
64
65
  end
@@ -74,27 +75,22 @@ describe Fron::Component do
74
75
  subject.test.should_not be nil
75
76
  subject.test.tag.should be 'test'
76
77
  end
77
-
78
- it 'should call render if model given' do
79
- comp = TestComponent.new(Fron::Model.new)
80
- comp.rendered.should be true
81
- end
82
78
  end
83
79
 
84
- describe "#component" do
80
+ describe '#component' do
85
81
  it 'should create a component from a Class' do
86
82
  subject.component 'b', TestComponent
87
- subject.instance_variable_get("@b").class.should eq TestComponent
83
+ subject.instance_variable_get('@b').class.should eq TestComponent
88
84
  end
89
85
 
90
86
  it 'should create a component from a String' do
91
87
  subject.component 'e', 'i'
92
- subject.instance_variable_get("@e").class.should eq Fron::Component
88
+ subject.instance_variable_get('@e').class.should eq Fron::Component
93
89
  end
94
90
 
95
91
  it 'should append component' do
96
92
  subject.component 'd', TestComponent
97
- comp = subject.instance_variable_get("@d")
93
+ comp = subject.instance_variable_get('@d')
98
94
  comp.parent.should eq subject
99
95
  end
100
96
 
@@ -1,56 +1,56 @@
1
- require 'fron/core'
1
+ require 'spec_helper'
2
2
 
3
+ # Test Eventable
3
4
  class TestEventable
4
5
  include Fron::Eventable
5
6
  end
6
7
 
7
8
  describe Fron::Eventable do
8
-
9
9
  subject { described_class }
10
- let(:events) { subject.instance_variable_get("@events") }
10
+ let(:events) { subject.instance_variable_get '@events' }
11
11
  let(:instance) { TestEventable.new }
12
12
 
13
- describe "#on" do
14
- it "should add to events array" do
13
+ describe '#on' do
14
+ it 'should add to events array' do
15
15
  subject.on 'event' do end
16
16
  events.should_not be nil
17
17
  events[:event].should_not be nil
18
18
  end
19
19
 
20
- it "should add block to events array" do
21
- a = Proc.new {}
22
- subject.on 'event', &a
23
- events[:event].last.should eq a
20
+ it 'should add block to events array' do
21
+ proc = proc {}
22
+ subject.on 'event', &proc
23
+ events[:event].last.should eq proc
24
24
  end
25
25
  end
26
26
 
27
- describe "#trigger" do
28
- it "should not trigger global event if called on self" do
27
+ describe '#trigger' do
28
+ it 'should not trigger global event if called on self' do
29
29
  expect(subject).to receive(:trigger).once.and_call_original
30
30
  subject.trigger 'test'
31
31
  end
32
32
 
33
- it "should trigger global event if specified and not self" do
33
+ it 'should trigger global event if specified and not self' do
34
34
  expect(subject).to receive(:trigger).once.and_call_original
35
35
  instance.on 'test' do end
36
36
  instance.trigger 'test'
37
37
  end
38
38
 
39
- it "should not trigger global event if not specified" do
39
+ it 'should not trigger global event if not specified' do
40
40
  expect(subject).not_to receive(:trigger)
41
41
  instance.trigger 'test', false
42
42
  end
43
43
 
44
- it "should call listeners" do
45
- a = Proc.new {}
46
- expect(a).to receive(:call)
47
- instance.on 'test', &a
44
+ it 'should call listeners' do
45
+ proc = proc {}
46
+ expect(proc).to receive(:call)
47
+ instance.on 'test', &proc
48
48
  instance.trigger 'test'
49
49
  end
50
50
  end
51
51
 
52
- describe "#off" do
53
- it "should remove the block from the events array" do
52
+ describe '#off' do
53
+ it 'should remove the block from the events array' do
54
54
  block = subject.on 'test' do end
55
55
  events['test'].last.should eq block
56
56
  subject.off 'test', block
@@ -1,26 +1,25 @@
1
- require 'fron/core'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fron::Logger do
4
-
5
4
  subject { described_class.new }
6
5
 
7
6
  before do
8
7
  allow(subject).to receive(:puts)
9
8
  end
10
9
 
11
- describe "#initialize" do
10
+ describe '#initialize' do
12
11
  it 'should set log level to :info' do
13
12
  subject.level.should eq :info
14
13
  end
15
14
  end
16
15
 
17
- describe "#info" do
18
- it "should add timestamp to message" do
16
+ describe '#info' do
17
+ it 'should add timestamp to message' do
19
18
  expect(Time).to receive(:now).and_call_original
20
19
  subject.info 'test'
21
20
  end
22
21
 
23
- it "should call puts" do
22
+ it 'should call puts' do
24
23
  expect(subject).to receive(:puts).once
25
24
  subject.info 'test'
26
25
  end
@@ -1,16 +1,15 @@
1
- require 'fron/dom'
1
+ require 'spec_helper'
2
2
 
3
3
  describe DOM::Document do
4
-
5
4
  subject { DOM::Document }
6
5
 
7
- describe "head" do
6
+ describe 'head' do
8
7
  it 'should return the head element' do
9
8
  DOM::Element.new(`document.head`).should eq subject.head
10
9
  end
11
10
  end
12
11
 
13
- describe "body" do
12
+ describe 'body' do
14
13
  it 'should return the body element' do
15
14
  DOM::Element.new(`document.body`).should eq subject.body
16
15
  end
@@ -18,7 +17,7 @@ describe DOM::Document do
18
17
 
19
18
  describe 'title' do
20
19
  it 'should return the title of the document' do
21
- subject.title.should eq "Opal Server"
20
+ subject.title.should eq 'Opal Server'
22
21
  end
23
22
  end
24
23