tablets 0.3.3 → 0.3.4
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/app/assets/javascripts/tablets/tablet.js.coffee +3 -2
- data/lib/tablets/data/processing/base.rb +5 -0
- data/lib/tablets/data/processing/filter.rb +2 -0
- data/lib/tablets/data/query.rb +7 -9
- data/lib/tablets/data.rb +8 -1
- data/lib/tablets/renderer.rb +2 -0
- data/lib/tablets/utils/config.rb +2 -0
- data/lib/tablets/version.rb +1 -1
- data/spec/lib/tablets/data/processing/base_spec.rb +12 -4
- data/spec/lib/tablets/data/processing/filter_spec.rb +9 -0
- data/spec/lib/tablets/data/processing/order_spec.rb +9 -0
- data/spec/lib/tablets/data/processing/paginate_spec.rb +2 -2
- data/spec/lib/tablets/data/query_spec.rb +112 -0
- data/spec/lib/tablets/data_spec.rb +7 -0
- data/spec/lib/tablets/global/configurator_spec.rb +15 -0
- data/spec/lib/tablets/global/loader_spec.rb +71 -0
- data/spec/lib/tablets/global/store_spec.rb +1 -1
- data/spec/lib/tablets/renderer_spec.rb +2 -1
- data/spec/lib/tablets/utils/config_spec.rb +19 -1
- data/spec/lib/tablets/view_helpers_spec.rb +2 -1
- metadata +15 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8913447e8e90a68f62572e09b15021e29735d1d8
|
4
|
+
data.tar.gz: c89c42ec3ac921e0e35390f57b493977992bfec0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb8b28dfa772a35282cfae6e82858146db98fa9a55f9c74214a2dbdd504191303f6f75239b18364426d093701765b65c8cec9eae79d8ea942d56f7399fb3445e
|
7
|
+
data.tar.gz: bb2bb9bc0b285e077061a176416e6981d4bbbefd007efe14898dcc613746104129fd51cf89f491327e2948cb5d8cddf303cfcfa2f05080ddd00490eb58663093
|
@@ -1,11 +1,13 @@
|
|
1
1
|
class Tablets.Tablet
|
2
2
|
constructor: (@element, @options, @params) ->
|
3
3
|
@initVars()
|
4
|
-
@initTable()
|
5
4
|
@initHandlers()
|
6
5
|
|
7
6
|
Tablets.set(@id, this)
|
8
7
|
|
8
|
+
$ =>
|
9
|
+
@initTable()
|
10
|
+
|
9
11
|
dataTableOptions: ->
|
10
12
|
$.extend {}, @options,
|
11
13
|
fnServerParams: (data) =>
|
@@ -37,7 +39,6 @@ class Tablets.Tablet
|
|
37
39
|
@element.on 'xhr.dt', (_event, _table, data) =>
|
38
40
|
@trigger('afterResponse', data)
|
39
41
|
|
40
|
-
|
41
42
|
reload: ->
|
42
43
|
@element.dataTable().fnDraw(false)
|
43
44
|
|
@@ -14,6 +14,11 @@ module Tablets
|
|
14
14
|
fail NotImplementedError, '#apply need to be overrided by processing.'
|
15
15
|
end
|
16
16
|
|
17
|
+
# Shorthand for create processing and apply it.
|
18
|
+
def self.apply(params, columns, relation)
|
19
|
+
new(params, columns).apply(relation)
|
20
|
+
end
|
21
|
+
|
17
22
|
private
|
18
23
|
|
19
24
|
attr_reader :params, :columns
|
data/lib/tablets/data/query.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
|
1
3
|
require 'tablets/data/processing/filter'
|
2
4
|
require 'tablets/data/processing/paginate'
|
3
5
|
require 'tablets/data/processing/order'
|
@@ -15,11 +17,7 @@ module Tablets
|
|
15
17
|
|
16
18
|
# Applies all processings on relation and returns it.
|
17
19
|
def fetch
|
18
|
-
|
19
|
-
result = order(result)
|
20
|
-
result = filter(result)
|
21
|
-
result = paginate(result)
|
22
|
-
result
|
20
|
+
paginate filter order relation
|
23
21
|
end
|
24
22
|
|
25
23
|
# Returns total records count before filter and pagination is applied.
|
@@ -40,21 +38,21 @@ module Tablets
|
|
40
38
|
def order(records)
|
41
39
|
return records unless params[:order].present?
|
42
40
|
|
43
|
-
Tablets::Data::Processing::Order.
|
41
|
+
Tablets::Data::Processing::Order.apply(params, columns, records)
|
44
42
|
end
|
45
43
|
|
46
44
|
# Applies filter processing.
|
47
45
|
def filter(records)
|
48
46
|
return records unless params[:search].present?
|
49
47
|
|
50
|
-
Tablets::Data::Processing::Filter.
|
48
|
+
Tablets::Data::Processing::Filter.apply(params, columns, records)
|
51
49
|
end
|
52
50
|
|
53
51
|
# Applies paginate processing.
|
54
52
|
def paginate(records)
|
55
|
-
return records if params
|
53
|
+
return records if params[:length] == '-1'
|
56
54
|
|
57
|
-
Tablets::Data::Processing::Paginate.
|
55
|
+
Tablets::Data::Processing::Paginate.apply(params, columns, records)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
data/lib/tablets/data.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
|
1
3
|
require 'tablets/data/query'
|
2
4
|
|
3
5
|
module Tablets
|
@@ -26,11 +28,16 @@ module Tablets
|
|
26
28
|
|
27
29
|
# Initializes query with concretized relation.
|
28
30
|
def query
|
29
|
-
@query ||= Tablets::Data::Query.new(tablet.relation(
|
31
|
+
@query ||= Tablets::Data::Query.new(tablet.relation(relation_params),
|
30
32
|
params,
|
31
33
|
tablet.columns)
|
32
34
|
end
|
33
35
|
|
36
|
+
# Relation params. Empty hash by default.
|
37
|
+
def relation_params
|
38
|
+
params[:params] || {}
|
39
|
+
end
|
40
|
+
|
34
41
|
# Fetching records and applies process tablet callback on it.
|
35
42
|
def records
|
36
43
|
@records ||= tablet.process(query.fetch)
|
data/lib/tablets/renderer.rb
CHANGED
data/lib/tablets/utils/config.rb
CHANGED
data/lib/tablets/version.rb
CHANGED
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
require 'tablets/data/processing/base'
|
4
4
|
|
5
5
|
RSpec.describe Tablets::Data::Processing::Base do
|
6
|
-
subject {
|
6
|
+
subject { described_class.new(params, columns) }
|
7
7
|
|
8
|
-
let(:relation) {
|
9
|
-
let(:params) {
|
10
|
-
let(:columns) {
|
8
|
+
let(:relation) { :relation }
|
9
|
+
let(:params) { :params }
|
10
|
+
let(:columns) { :columns }
|
11
11
|
|
12
12
|
describe '#apply' do
|
13
13
|
it 'raises not implemented error' do
|
@@ -16,4 +16,12 @@ RSpec.describe Tablets::Data::Processing::Base do
|
|
16
16
|
end.to raise_error(NotImplementedError)
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
describe '.apply' do
|
21
|
+
it 'raises not implemented error' do
|
22
|
+
expect do
|
23
|
+
described_class.apply(params, columns, relation)
|
24
|
+
end.to raise_error(NotImplementedError)
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
require 'tablets/data/processing/paginate'
|
4
4
|
|
5
5
|
RSpec.describe Tablets::Data::Processing::Paginate do
|
6
|
-
subject {
|
6
|
+
subject { described_class.new(params, columns) }
|
7
7
|
|
8
8
|
let(:relation) { double }
|
9
9
|
let(:params) { { start: start, length: length } }
|
10
|
-
let(:columns) {
|
10
|
+
let(:columns) { :columns }
|
11
11
|
|
12
12
|
describe '#apply' do
|
13
13
|
before do
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'tablets/data/query'
|
4
|
+
|
5
|
+
RSpec.describe Tablets::Data::Query do
|
6
|
+
subject { described_class.new(relation, params, columns) }
|
7
|
+
|
8
|
+
let(:relation) { 'relation' }
|
9
|
+
let(:params) { {} }
|
10
|
+
let(:columns) { :columns }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(Tablets::Data::Processing::Order).to receive(:apply)
|
14
|
+
.with(params, columns, relation).and_return(relation)
|
15
|
+
allow(Tablets::Data::Processing::Filter).to receive(:apply)
|
16
|
+
.with(params, columns, relation).and_return(relation)
|
17
|
+
allow(Tablets::Data::Processing::Paginate).to receive(:apply)
|
18
|
+
.with(params, columns, relation).and_return(relation)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#fetch' do
|
22
|
+
let!(:result) { subject.fetch }
|
23
|
+
|
24
|
+
let(:params) { { order: :order, search: :search } }
|
25
|
+
|
26
|
+
it 'returns relation' do
|
27
|
+
expect(result).to eq(relation)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'applies order' do
|
31
|
+
expect(Tablets::Data::Processing::Order).to have_received(:apply)
|
32
|
+
.with(params, columns, relation)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'applies filter' do
|
36
|
+
expect(Tablets::Data::Processing::Filter).to have_received(:apply)
|
37
|
+
.with(params, columns, relation)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'applies paginate' do
|
41
|
+
expect(Tablets::Data::Processing::Paginate).to have_received(:apply)
|
42
|
+
.with(params, columns, relation)
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'without order' do
|
46
|
+
let(:params) { { search: :search } }
|
47
|
+
|
48
|
+
it 'not applies order' do
|
49
|
+
expect(Tablets::Data::Processing::Order).to_not have_received(:apply)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'without search' do
|
54
|
+
let(:params) { { order: :order } }
|
55
|
+
|
56
|
+
it 'not applies order' do
|
57
|
+
expect(Tablets::Data::Processing::Filter).to_not have_received(:apply)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with negative length' do
|
62
|
+
let(:params) { { length: '-1' } }
|
63
|
+
|
64
|
+
it 'not applies order' do
|
65
|
+
expect(Tablets::Data::Processing::Paginate).to_not have_received(:apply)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#total' do
|
71
|
+
let(:total) { :total }
|
72
|
+
|
73
|
+
before do
|
74
|
+
allow(relation).to receive(:count).with(:all).and_return(total)
|
75
|
+
end
|
76
|
+
|
77
|
+
let!(:result) { subject.total }
|
78
|
+
|
79
|
+
it 'returns total' do
|
80
|
+
expect(result).to eq(total)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#filtered' do
|
85
|
+
let(:params) { { search: :search } }
|
86
|
+
|
87
|
+
let(:total) { :total }
|
88
|
+
|
89
|
+
before do
|
90
|
+
allow(relation).to receive(:count).with(:all).and_return(total)
|
91
|
+
end
|
92
|
+
|
93
|
+
let!(:result) { subject.filtered }
|
94
|
+
|
95
|
+
it 'applies filter' do
|
96
|
+
expect(Tablets::Data::Processing::Filter).to have_received(:apply)
|
97
|
+
.with(params, columns, relation)
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'without search' do
|
101
|
+
let(:params) { {} }
|
102
|
+
|
103
|
+
it 'not applies order' do
|
104
|
+
expect(Tablets::Data::Processing::Filter).to_not have_received(:apply)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns total' do
|
109
|
+
expect(result).to eq(total)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'tablets/global/configurator'
|
4
|
+
|
5
|
+
RSpec.describe Tablets::Global::Configurator do
|
6
|
+
subject { Object.new.tap { |object| object.extend(described_class) } }
|
7
|
+
|
8
|
+
describe '#setup' do
|
9
|
+
it 'yields self' do
|
10
|
+
expect do |expect_block|
|
11
|
+
subject.setup(&expect_block)
|
12
|
+
end.to yield_with_args(subject)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'tablets'
|
4
|
+
|
5
|
+
require 'tablets/global/loader'
|
6
|
+
|
7
|
+
RSpec.describe Tablets::Global::Loader do
|
8
|
+
subject { Object.new.tap { |object| object.extend(described_class) } }
|
9
|
+
|
10
|
+
def self.set_tablets
|
11
|
+
before do
|
12
|
+
subject.instance_variable_set(:@tablets, yield)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def tablets
|
17
|
+
subject.instance_variable_get(:@tablets)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#unload!' do
|
21
|
+
set_tablets { {} }
|
22
|
+
|
23
|
+
before { subject.unload! }
|
24
|
+
|
25
|
+
it 'sets tablets to nil' do
|
26
|
+
expect(tablets).to be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#loaded?' do
|
31
|
+
context 'if tablets is not nil' do
|
32
|
+
set_tablets { {} }
|
33
|
+
|
34
|
+
it 'returns true' do
|
35
|
+
expect(subject.loaded?).to eq(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'if tablets is nil' do
|
40
|
+
it 'returns false' do
|
41
|
+
expect(subject.loaded?).to eq(false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#load!' do
|
47
|
+
let(:files) { %w(file1 file2) }
|
48
|
+
let(:tablets_dir) { 'dir' }
|
49
|
+
|
50
|
+
before do
|
51
|
+
allow(Tablets).to receive(:tablets_dir).and_return(tablets_dir)
|
52
|
+
allow(Dir).to receive(:[]).and_return(files)
|
53
|
+
end
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:load)
|
57
|
+
end
|
58
|
+
|
59
|
+
before { subject.load! }
|
60
|
+
|
61
|
+
it 'sets tablets to empty hash' do
|
62
|
+
expect(tablets).to eq({})
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'loads each file' do
|
66
|
+
files.each do |file|
|
67
|
+
expect(subject).to have_received(:load).with(file)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
require 'tablets/global/store'
|
4
4
|
|
5
5
|
RSpec.describe Tablets::Global::Store do
|
6
|
-
subject { Object.new.tap { |object| object.extend(
|
6
|
+
subject { Object.new.tap { |object| object.extend(described_class) } }
|
7
7
|
|
8
8
|
describe '#register' do
|
9
9
|
let(:name) { :posts }
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'tablets'
|
4
|
+
|
4
5
|
require 'tablets/renderer'
|
5
6
|
|
6
7
|
RSpec.describe Tablets::Renderer do
|
7
|
-
subject {
|
8
|
+
subject { described_class.new(tablet, params) }
|
8
9
|
|
9
10
|
describe '#render' do
|
10
11
|
let(:tablet) { double }
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
require 'tablets/utils/config'
|
4
4
|
|
5
5
|
RSpec.describe Tablets::Utils::Config do
|
6
|
-
subject {
|
6
|
+
subject { described_class.new(&block) }
|
7
7
|
|
8
8
|
def hash
|
9
9
|
subject.instance_eval { @hash }
|
@@ -38,6 +38,24 @@ RSpec.describe Tablets::Utils::Config do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
describe '#has?' do
|
42
|
+
context 'if value exists' do
|
43
|
+
let(:block) { proc { var('val') } }
|
44
|
+
|
45
|
+
it 'returns true' do
|
46
|
+
expect(subject.has?(:var)).to eq(true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'if value not exists' do
|
51
|
+
let(:block) { nil }
|
52
|
+
|
53
|
+
it 'returns false' do
|
54
|
+
expect(subject.has?(:var)).to eq(false)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
41
59
|
describe '#get' do
|
42
60
|
context 'if value exists' do
|
43
61
|
let(:block) { proc { var('val') } }
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'tablets'
|
4
|
+
|
4
5
|
require 'tablets/view_helpers'
|
5
6
|
|
6
7
|
RSpec.describe Tablets::ViewHelpers do
|
7
|
-
subject { Object.new.tap { |object| object.extend(
|
8
|
+
subject { Object.new.tap { |object| object.extend(described_class) } }
|
8
9
|
|
9
10
|
describe '#render_tablet' do
|
10
11
|
let(:name) { :name }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yevhen Shemet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,7 +131,13 @@ files:
|
|
131
131
|
- lib/tablets/version.rb
|
132
132
|
- lib/tablets/view_helpers.rb
|
133
133
|
- spec/lib/tablets/data/processing/base_spec.rb
|
134
|
+
- spec/lib/tablets/data/processing/filter_spec.rb
|
135
|
+
- spec/lib/tablets/data/processing/order_spec.rb
|
134
136
|
- spec/lib/tablets/data/processing/paginate_spec.rb
|
137
|
+
- spec/lib/tablets/data/query_spec.rb
|
138
|
+
- spec/lib/tablets/data_spec.rb
|
139
|
+
- spec/lib/tablets/global/configurator_spec.rb
|
140
|
+
- spec/lib/tablets/global/loader_spec.rb
|
135
141
|
- spec/lib/tablets/global/store_spec.rb
|
136
142
|
- spec/lib/tablets/renderer_spec.rb
|
137
143
|
- spec/lib/tablets/utils/config_spec.rb
|
@@ -157,15 +163,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
163
|
version: '0'
|
158
164
|
requirements: []
|
159
165
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.4.
|
166
|
+
rubygems_version: 2.4.6
|
161
167
|
signing_key:
|
162
168
|
specification_version: 4
|
163
169
|
summary: Wrapper around jquery-datatables.
|
164
170
|
test_files:
|
171
|
+
- spec/lib/tablets/data_spec.rb
|
165
172
|
- spec/lib/tablets/utils/config_spec.rb
|
166
173
|
- spec/lib/tablets/view_helpers_spec.rb
|
167
174
|
- spec/lib/tablets/renderer_spec.rb
|
168
175
|
- spec/lib/tablets/data/processing/base_spec.rb
|
176
|
+
- spec/lib/tablets/data/processing/order_spec.rb
|
177
|
+
- spec/lib/tablets/data/processing/filter_spec.rb
|
169
178
|
- spec/lib/tablets/data/processing/paginate_spec.rb
|
179
|
+
- spec/lib/tablets/data/query_spec.rb
|
180
|
+
- spec/lib/tablets/global/loader_spec.rb
|
170
181
|
- spec/lib/tablets/global/store_spec.rb
|
182
|
+
- spec/lib/tablets/global/configurator_spec.rb
|
171
183
|
- spec/spec_helper.rb
|