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,65 +0,0 @@
1
- require 'fron/storage'
2
- require 'fron/core'
3
-
4
- describe Fron::Adapters::LocalAdapter do
5
-
6
- subject { described_class.new({fields: [:name]}) }
7
- let(:proc) { Proc.new {} }
8
-
9
- describe "#all" do
10
- it "should call localStorage#all" do
11
- Fron::Storage::LocalStorage.should receive(:all).once
12
- subject.all &proc
13
- end
14
-
15
- it "should run the block" do
16
- proc.should receive(:call)
17
- subject.all &proc
18
- end
19
- end
20
-
21
- describe "#get" do
22
- it "should call localStorage#get" do
23
- Fron::Storage::LocalStorage.should receive(:get).once
24
- subject.get 0, &proc
25
- end
26
-
27
- it "should run the block" do
28
- proc.should receive(:call)
29
- subject.get 0, &proc
30
- end
31
- end
32
-
33
- describe "#set" do
34
- it "should call localStorage#set" do
35
- Fron::Storage::LocalStorage.should receive(:set).once
36
- subject.set double(id: 0), {name: 'test'}, &proc
37
- end
38
-
39
- it "should run the block with nil if there are no errors" do
40
- proc.should receive(:call).with nil, {name: 'test', id: 0}
41
- subject.set double(id: 0), {name: 'test'}, &proc
42
- end
43
-
44
- it "should run the block with erros if ther are any" do
45
- proc.should receive(:call).with({name: ["can't be blank"]}, {})
46
- subject.set double(id: 0), {name: ''}, &proc
47
- end
48
-
49
- it "should add id if there isn't any" do
50
- result = subject.set double(id: nil), {name: ''}, &proc
51
- result[:id].should_not be nil
52
- end
53
- end
54
-
55
- describe "#validate" do
56
- it "should return errors for undefined fields" do
57
- subject.validate.should eq({name: ["can't be blank"]})
58
- end
59
-
60
- it "should return errors for empty fields" do
61
- subject.validate({name: ''}).should eq({name: ["can't be blank"]})
62
- end
63
- end
64
- end
65
-
@@ -1,77 +0,0 @@
1
- require 'fron/core'
2
- require 'fron/storage'
3
-
4
- class TestModel < Fron::Model
5
- end
6
-
7
- describe Fron::Adapters::RailsAdapter do
8
-
9
- subject do
10
- described_class.new({
11
- fields: [:name],
12
- endpoint: "test",
13
- resources: "users",
14
- resource: "user"
15
- })
16
- end
17
-
18
- let(:proc) { Proc.new {} }
19
- let(:request) { double :request }
20
- let(:model) { TestModel.new({ id: 0 }) }
21
- let(:newModel) { TestModel.new }
22
-
23
- before do
24
- subject.instance_variable_set "@request", request
25
- end
26
-
27
- describe "#all" do
28
- it "should call GET request to resources url" do
29
- request.should receive(:url=).with "test/users.json"
30
- request.should receive(:get) do |&block|
31
- block.call double json: true
32
- end
33
- proc.should receive(:call)
34
- subject.all &proc
35
- end
36
- end
37
-
38
- describe "#get" do
39
- it "should call GET request to resource url" do
40
- request.should receive(:url=).with "test/users/0"
41
- request.should receive(:get) do |&block|
42
- block.call double json: true
43
- end
44
- proc.should receive(:call)
45
- subject.get '0', &proc
46
- end
47
- end
48
-
49
- describe "#set" do
50
- it "should call POST request for new record" do
51
- request.should receive(:url=).with "test/users.json"
52
- request.should receive(:post) do |&block|
53
- block.call double status: 201, json: ''
54
- end
55
- proc.should receive(:call)
56
- subject.set newModel, {}, &proc
57
- end
58
-
59
- it "should call PUT request for exsistsing record" do
60
- request.should receive(:url=).with "test/users/0"
61
- request.should receive(:put) do |&block|
62
- block.call double status: 201, json: ''
63
- end
64
- proc.should receive(:call)
65
- subject.set model, {}, &proc
66
- end
67
-
68
- it "should call block with error" do
69
- request.should receive(:url=).with "test/users/0"
70
- request.should receive(:put) do |&block|
71
- block.call double status: 422, json: 'error'
72
- end
73
- proc.should receive(:call).with 'error', 'error'
74
- subject.set model, {}, &proc
75
- end
76
- end
77
- end
@@ -1,35 +0,0 @@
1
- require 'fron/core'
2
-
3
- class TestApplication < Fron::Application
4
- config.title = 'Test Application'
5
- config.logger.level = :error
6
- end
7
-
8
- describe Fron::Application do
9
-
10
- subject { TestApplication.new }
11
-
12
- after do
13
- subject.config.app.remove!
14
- end
15
-
16
- describe "#initialize" do
17
- it 'should insert the application into the DOM' do
18
- subject.config.app.parent.should_not be nil
19
- end
20
-
21
- it 'should set the title of the document' do
22
- DOM::Document.title.should eq 'Test Application'
23
- end
24
- end
25
-
26
- describe "#loadExternalStylesheets" do
27
- it 'should load external stylesheets' do
28
- subject.config.stylesheets = ['test']
29
- subject.send(:loadExternalStylesheets)
30
- link = DOM::Document.head.find('link')
31
- link['href'].should be 'test'
32
- link.remove!
33
- end
34
- end
35
- end
@@ -1,20 +0,0 @@
1
- require 'fron'
2
-
3
- describe Fron::Configuration do
4
-
5
- subject { described_class.new }
6
-
7
- describe '#initialize' do
8
- it 'should create a logger' do
9
- subject.logger.class.should be Fron::Logger
10
- end
11
-
12
- it 'should create the application container' do
13
- subject.app.class.should be Fron::Configuration::App
14
- end
15
-
16
- it 'should create the yield container' do
17
- subject.main.class.should be Fron::Configuration::Yield
18
- end
19
- end
20
- end
@@ -1,68 +0,0 @@
1
- require 'fron/core'
2
-
3
- class TestController < Fron::Controller
4
- end
5
-
6
- describe TestController do
7
-
8
- subject { described_class.new }
9
-
10
- describe 'DSL' do
11
-
12
- subject { TestController }
13
-
14
- describe '#base' do
15
- it 'should set the baseComponent' do
16
- subject.base Fron::Component
17
- subject.baseComponent.should eq Fron::Component
18
- end
19
- end
20
-
21
- describe '#route' do
22
- it 'should set routes map' do
23
- allow(Fron::Router).to receive(:map)
24
- subject.route '/', :test
25
- subject.routes.should_not be nil
26
- subject.routes.length.should eq 1
27
- end
28
-
29
- it 'should call Router.map' do
30
- expect(Fron::Router).to receive(:map).once
31
- subject.route '/a', :a
32
- end
33
- end
34
-
35
- describe '#on' do
36
- it 'should set events array' do
37
- subject.on :event, :action
38
- subject.events.should_not be nil
39
- subject.events[0].should eq({name: :event, action: :action})
40
- end
41
- end
42
-
43
- describe '#before' do
44
- it 'should set before filters' do
45
- subject.before :method, :action
46
- subject.beforeFilters.should_not be nil
47
- subject.beforeFilters[0].should eq({method: :method, actions: :action})
48
- end
49
- end
50
- end
51
-
52
- describe "#initialize" do
53
- it 'should create Element if no component is specified' do
54
- TestController.base nil
55
- subject.base.class.should eq DOM::Element
56
- end
57
-
58
- it 'should create component if component is specified' do
59
- TestController.base Fron::Component
60
- subject.base.class.should eq Fron::Component
61
- end
62
-
63
- it 'should call Eventable.on for event' do
64
- expect(Fron::Eventable).to receive(:on).once.with 'event'
65
- subject
66
- end
67
- end
68
- end
@@ -1,125 +0,0 @@
1
- require 'fron/core'
2
-
3
- class TestModel < Fron::Model
4
- end
5
-
6
- class MockAdapter
7
- def all(&block)
8
- block.call [{},{}]
9
- end
10
-
11
- def get(&block)
12
- block.call({name: 'User'})
13
- end
14
-
15
- def set(model,data,&block)
16
- if model.id == 0
17
- block.call(nil, data)
18
- else
19
- block.call({errors: true}, {})
20
- end
21
- end
22
- end
23
-
24
- describe TestModel do
25
-
26
- subject { described_class }
27
-
28
- describe "DSL" do
29
- describe "#adapter" do
30
- it "should set adapter" do
31
- subject.adapter MockAdapter
32
- subject.adapterObject.should_not be nil
33
- end
34
- end
35
-
36
- describe "#field" do
37
- it "should set fields array" do
38
- subject.field :name
39
- subject.fields.should_not be nil
40
- subject.fields.should include(:name)
41
- end
42
-
43
- it "should define methods" do
44
- subject.field :description
45
- subject.instance_methods.should include(:description)
46
- subject.instance_methods.should include(:description=)
47
- end
48
- end
49
- end
50
-
51
- describe "Class Methods" do
52
- describe "#all" do
53
- it "should call adapter#call" do
54
- subject.adapterObject.should receive(:all)
55
- subject.all
56
- end
57
-
58
- it "should call new on self class for items" do
59
- subject.should receive(:new).twice
60
- subject.adapterObject.should receive(:all).and_call_original
61
- subject.all do end
62
- end
63
- end
64
-
65
- describe "#find" do
66
- it "should return class instance" do
67
- subject.adapterObject.should receive(:get).and_call_original
68
- subject.find do |instance|
69
- instance.class.should eq described_class
70
- end
71
- end
72
-
73
- it "should merge user data" do
74
- subject.adapterObject.should receive(:get).and_call_original
75
- subject.find do |instance|
76
- instance.name.should eq 'User'
77
- end
78
- end
79
- end
80
- end
81
-
82
- describe "Instance Methods" do
83
- subject { described_class.new({name: 'Test'}) }
84
-
85
- describe "#initialize" do
86
- it "should set data" do
87
- subject.name.should eq 'Test'
88
- end
89
- end
90
-
91
- describe "#update" do
92
- it "should call adapter#set" do
93
- described_class.adapterObject.should receive(:set).and_call_original
94
- subject.update
95
- end
96
-
97
- it "should merge user data" do
98
- described_class.adapterObject.should receive(:set).and_call_original
99
- subject.id = 0
100
- subject.update name: "User" do
101
- subject.errors.should be nil
102
- subject.name.should eq 'User'
103
- end
104
- end
105
-
106
- it "should set errors" do
107
- subject.id == 2
108
- subject.update do
109
- subject.errors.should_not be nil
110
- end
111
- end
112
- end
113
-
114
- describe "#dirty?" do
115
- it "should return true if there is no id" do
116
- subject.dirty?.should eq true
117
- end
118
-
119
- it "should return false if there is and id" do
120
- subject.id = 0
121
- subject.dirty?.should eq false
122
- end
123
- end
124
- end
125
- end
@@ -1,124 +0,0 @@
1
- require 'fron/core'
2
-
3
- module Fron
4
- class Router
5
- attr_reader :routes
6
- end
7
- end
8
-
9
- class TestRouteController < Fron::Controller
10
- route "show/:id", :show
11
- route "*", :test
12
-
13
- def show
14
- end
15
- def test
16
- end
17
- end
18
-
19
- describe Fron::Router do
20
-
21
- subject { described_class.new [], config }
22
- let(:window) { DOM::Window }
23
- let(:window_listeners) {window.instance_variable_get("@listeners")}
24
- let(:controller) { TestRouteController.new }
25
- let(:config) { double :config, {
26
- injectBlock: nil,
27
- logger: double(:logger,info: true),
28
- main: double(:main, :"<<" => true, "empty" => true)
29
- }
30
- }
31
-
32
- before { window.off }
33
-
34
- describe "DSL" do
35
- describe "#map" do
36
- it "should retrun '*' path for action only" do
37
- result = described_class.map :test
38
- result[:path].should eq "*"
39
- result[:action].should eq :test
40
- end
41
-
42
- it "should return regexp for path" do
43
- result = described_class.map "/test", :test
44
- result[:path][:regexp].should eq Regexp.new "^/test"
45
- result[:path][:map].should eq []
46
- result[:action].should eq :test
47
- end
48
-
49
- it 'should parse string as action' do
50
- result = described_class.map :test
51
- result[:action].should eq :test
52
- result[:controller].should be nil
53
- end
54
-
55
- it 'should parse controllers as controller' do
56
- result = described_class.map Fron::Controller
57
- result[:controller].should_not be nil
58
- result[:controller].class.should eq Fron::Controller
59
- result[:action].should eq nil
60
- end
61
- end
62
- end
63
-
64
- describe "#route" do
65
- it "should deletage if controller is given" do
66
- subject.routes << {path: "*", controller: controller}
67
- subject.should receive(:route).twice.and_call_original
68
- subject.route
69
- end
70
-
71
- it "should call controller action" do
72
- subject.routes << {path: "*", controller: controller}
73
- controller.should receive(:test).once
74
- subject.route
75
- end
76
-
77
- it "should call controller action with params" do
78
- controller.should receive(:show).once.with({id: '10'})
79
- subject.routes << {path: "*", controller: controller}
80
- subject.route 'show/10'
81
- end
82
-
83
- it "should remove the matched portion of the hash" do
84
- controller.should receive(:show).once.with({id: '10'})
85
- subject.routes << {path: {regexp: Regexp.new("test/")}, controller: controller}
86
- subject.route 'test/show/10'
87
- end
88
- end
89
-
90
- describe "#applyRoute" do
91
- it "should call before methods" do
92
- controller.should receive(:empty).once
93
- subject.applyRoute controller, {action: 'show'}
94
- end
95
-
96
- it "should call action method" do
97
- controller.should receive(:show).once
98
- subject.applyRoute controller, {action: 'show'}
99
- end
100
-
101
- it 'should log the route' do
102
- config.logger.should receive(:info).once
103
- subject.applyRoute controller, {action: 'show'}
104
- end
105
-
106
- it "should append it the the main" do
107
- config.main.should receive(:<<).once
108
- subject.applyRoute controller, {action: 'show'}
109
- end
110
- end
111
-
112
- describe "#initalize" do
113
- it 'should listen on window load' do
114
- subject
115
- window_listeners['load'].should_not be nil
116
- end
117
-
118
- it 'should listen on window hashchange' do
119
- subject
120
- window_listeners['hashchange'].should_not be nil
121
- end
122
- end
123
-
124
- end