tabulatr2 0.9.4 → 0.9.6

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/Gemfile +1 -2
  4. data/README.md +155 -95
  5. data/app/assets/javascripts/tabulatr/_storage.js +41 -0
  6. data/app/assets/javascripts/tabulatr/_tabulatr.js +598 -0
  7. data/app/assets/javascripts/tabulatr/application.js +3 -553
  8. data/app/assets/stylesheets/tabulatr/application.css.scss +21 -12
  9. data/app/assets/stylesheets/tabulatr.css +1 -0
  10. data/app/views/tabulatr/_tabulatr_actual_table.html.slim +18 -18
  11. data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +1 -1
  12. data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +1 -1
  13. data/app/views/tabulatr/_tabulatr_static_table.html.slim +3 -3
  14. data/app/views/tabulatr/_tabulatr_table.html.slim +17 -12
  15. data/lib/tabulatr/data/data.rb +7 -9
  16. data/lib/tabulatr/data/dsl.rb +36 -21
  17. data/lib/tabulatr/data/filtering.rb +41 -13
  18. data/lib/tabulatr/data/formatting.rb +7 -20
  19. data/lib/tabulatr/data/pagination.rb +1 -2
  20. data/lib/tabulatr/data/proxy.rb +2 -0
  21. data/lib/tabulatr/data/sorting.rb +24 -13
  22. data/lib/tabulatr/engine.rb +1 -0
  23. data/lib/tabulatr/generators/tabulatr/templates/tabulatr.yml +2 -2
  24. data/lib/tabulatr/json_builder.rb +23 -25
  25. data/lib/tabulatr/rails/action_controller.rb +4 -0
  26. data/lib/tabulatr/rails/action_view.rb +3 -2
  27. data/lib/tabulatr/renderer/checkbox.rb +3 -1
  28. data/lib/tabulatr/renderer/column.rb +47 -5
  29. data/lib/tabulatr/renderer/columns_from_block.rb +24 -6
  30. data/lib/tabulatr/renderer/renderer.rb +26 -17
  31. data/lib/tabulatr/utility/unexpected_search_result_error.rb +9 -0
  32. data/lib/tabulatr/utility/utility.rb +4 -0
  33. data/lib/tabulatr/version.rb +1 -1
  34. data/spec/dummy/app/controllers/products_controller.rb +9 -0
  35. data/spec/dummy/app/views/products/local_storage.html.slim +4 -0
  36. data/spec/dummy/app/views/products/simple_index.html.erb +1 -1
  37. data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
  38. data/spec/dummy/config/application.rb +1 -1
  39. data/spec/dummy/config/locales/tabulatr.yml +2 -2
  40. data/spec/dummy/config/routes.rb +1 -0
  41. data/spec/features/tabulatrs_spec.rb +27 -27
  42. data/spec/lib/tabulatr/data/data_spec.rb +12 -16
  43. data/spec/lib/tabulatr/data/filtering_spec.rb +48 -7
  44. data/spec/lib/tabulatr/data/formatting_spec.rb +32 -0
  45. data/spec/lib/tabulatr/data/sorting_spec.rb +81 -0
  46. data/spec/lib/tabulatr/json_builder_spec.rb +23 -9
  47. data/spec/lib/tabulatr/renderer/checkbox_spec.rb +14 -0
  48. data/spec/lib/tabulatr/renderer/renderer_spec.rb +20 -8
  49. data/tabulatr.gemspec +4 -3
  50. metadata +45 -9
  51. data/lib/tabulatr/data/column_name_builder.rb +0 -86
@@ -2,15 +2,29 @@ require 'spec_helper'
2
2
 
3
3
  describe Tabulatr::JsonBuilder do
4
4
 
5
- it "does not complain when no id is manually provided" do
6
- attribute = {action: :id}
7
- data = {title: 'test', price: '7.0 EUR'}
8
- expect{Tabulatr::JsonBuilder.insert_attribute_in_hash(attribute, data)}.to_not raise_error
9
- end
5
+ describe '.insert_attribute_in_hash' do
6
+ it "does not complain when no id is manually provided" do
7
+ attribute = {action: :id}
8
+ data = {title: 'test', price: '7.0 EUR'}
9
+ expect{Tabulatr::JsonBuilder.insert_attribute_in_hash(attribute, data)}.to_not raise_error
10
+ end
11
+
12
+ it "complains when a non given attribute other than id is requested" do
13
+ attribute = {action: :bar}
14
+ data = {title: 'test', price: '7.0 EUR'}
15
+ expect{Tabulatr::JsonBuilder.insert_attribute_in_hash(attribute, data)}.to raise_error
16
+ end
10
17
 
11
- it "complains when a non given attribute other than id is requested" do
12
- attribute = {action: :bar}
13
- data = {title: 'test', price: '7.0 EUR'}
14
- expect{Tabulatr::JsonBuilder.insert_attribute_in_hash(attribute, data)}.to raise_error
18
+ # it 'accepts arguments without table name' do
19
+ # attribute = {action: :title}
20
+ # data = {"products"=>
21
+ # {"title"=>"title 9", "id"=>10, "price"=>"32.0 EUR",
22
+ # "vendor_product_name"=>"title 9 from my first vendor"},
23
+ # "vendor"=>
24
+ # {"name"=>"my first vendor"},
25
+ # "tags"=>{"title"=>"''", "count"=>0},
26
+ # "_row_config"=>{"class"=>"tabulatr-row"}, "id"=>10}
27
+ # expect{Tabulatr::JsonBuilder.insert_attribute_in_hash(attribute, data)}.to_not raise_error
28
+ # end
15
29
  end
16
30
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tabulatr::Renderer::Checkbox do
4
+
5
+ describe "#human_name" do
6
+
7
+ it "generates a checkbox" do
8
+ checkbox = Tabulatr::Renderer::Checkbox.new
9
+ expect(checkbox.human_name).to eq('<input class="tabulatr_mark_all" id="mark_all" name="mark_all" type="checkbox" value="1" />')
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -2,14 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe Tabulatr::Renderer do
4
4
 
5
- describe "#generate_id"
6
-
7
- it "generates a 'unique' id for a table" do
8
- klass = Product
9
- renderer = Tabulatr::Renderer.new(klass, nil)
10
- first_id = renderer.generate_id
11
- second_id = renderer.generate_id
12
- expect(first_id).to_not eq second_id
5
+ def double_view
6
+ view = double(controller: double(controller_name: 'products', action_name: 'index'))
7
+ view.instance_variable_set('@_tabulatr_table_index', 0)
8
+ view
13
9
  end
14
10
 
11
+ describe '.initialize' do
12
+ it 'sets pagination_position to top if not set explicitely' do
13
+ renderer = Tabulatr::Renderer.new(Product, double_view)
14
+ expect(renderer.instance_variable_get('@table_options')[:pagination_position]).to eq :top
15
+ end
16
+
17
+ it 'sets persistent to false if not set explicitely' do
18
+ renderer = Tabulatr::Renderer.new(Product, double_view)
19
+ expect(renderer.instance_variable_get('@table_options')[:persistent]).to eq false
20
+ end
21
+
22
+ it 'sets persistent to true if paginate is true' do
23
+ renderer = Tabulatr::Renderer.new(Product, double_view, paginate: true)
24
+ expect(renderer.instance_variable_get('@table_options')[:persistent]).to eq true
25
+ end
26
+ end
15
27
  end
data/tabulatr.gemspec CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.rdoc_options = ['--charset=UTF-8']
24
24
 
25
25
 
26
- s.add_runtime_dependency('rails', '>= 4.0.0')
27
- s.add_dependency('slim', '>= 2.0.1')
28
- s.add_runtime_dependency('activerecord_outer_joins', '~> 0.0.1')
26
+ s.add_runtime_dependency('rails', '~> 4.0.0', '>= 4.0.0')
27
+ s.add_dependency('slim', '~> 2.0.0', '>= 2.0.0')
28
+ s.add_dependency('tilt', '~> 1.4.1')
29
+ s.add_dependency('font-awesome-rails', '~> 4.0')
29
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,12 +10,15 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-29 00:00:00.000000000 Z
13
+ date: 2014-05-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 4.0.0
19
22
  - - ">="
20
23
  - !ruby/object:Gem::Version
21
24
  version: 4.0.0
@@ -23,6 +26,9 @@ dependencies:
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: 4.0.0
26
32
  - - ">="
27
33
  - !ruby/object:Gem::Version
28
34
  version: 4.0.0
@@ -30,30 +36,50 @@ dependencies:
30
36
  name: slim
31
37
  requirement: !ruby/object:Gem::Requirement
32
38
  requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 2.0.0
33
42
  - - ">="
34
43
  - !ruby/object:Gem::Version
35
- version: 2.0.1
44
+ version: 2.0.0
36
45
  type: :runtime
37
46
  prerelease: false
38
47
  version_requirements: !ruby/object:Gem::Requirement
39
48
  requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: 2.0.0
40
52
  - - ">="
41
53
  - !ruby/object:Gem::Version
42
- version: 2.0.1
54
+ version: 2.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: tilt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.1
43
69
  - !ruby/object:Gem::Dependency
44
- name: activerecord_outer_joins
70
+ name: font-awesome-rails
45
71
  requirement: !ruby/object:Gem::Requirement
46
72
  requirements:
47
73
  - - "~>"
48
74
  - !ruby/object:Gem::Version
49
- version: 0.0.1
75
+ version: '4.0'
50
76
  type: :runtime
51
77
  prerelease: false
52
78
  version_requirements: !ruby/object:Gem::Requirement
53
79
  requirements:
54
80
  - - "~>"
55
81
  - !ruby/object:Gem::Version
56
- version: 0.0.1
82
+ version: '4.0'
57
83
  description: A tight DSL to build tables of ActiveRecord models with sorting, pagination,
58
84
  finding/filtering, selecting and batch actions. Tries to do for tables what formtastic
59
85
  and simple_form did for forms.
@@ -73,6 +99,8 @@ files:
73
99
  - app/assets/images/pacman-loader.gif
74
100
  - app/assets/images/standard-loader.gif
75
101
  - app/assets/javascripts/tabulatr.js
102
+ - app/assets/javascripts/tabulatr/_storage.js
103
+ - app/assets/javascripts/tabulatr/_tabulatr.js
76
104
  - app/assets/javascripts/tabulatr/application.js
77
105
  - app/assets/javascripts/tabulatr/jquery.inview.min.js
78
106
  - app/assets/stylesheets/tabulatr.css
@@ -89,7 +117,6 @@ files:
89
117
  - app/views/tabulatr/_tabulatr_table.html.slim
90
118
  - init.rb
91
119
  - lib/tabulatr.rb
92
- - lib/tabulatr/data/column_name_builder.rb
93
120
  - lib/tabulatr/data/data.rb
94
121
  - lib/tabulatr/data/dsl.rb
95
122
  - lib/tabulatr/data/filtering.rb
@@ -117,6 +144,7 @@ files:
117
144
  - lib/tabulatr/renderer/columns_from_block.rb
118
145
  - lib/tabulatr/renderer/renderer.rb
119
146
  - lib/tabulatr/utility/request_data_not_included_error.rb
147
+ - lib/tabulatr/utility/unexpected_search_result_error.rb
120
148
  - lib/tabulatr/utility/utility.rb
121
149
  - lib/tabulatr/version.rb
122
150
  - lib/tabulatr2.rb
@@ -142,6 +170,7 @@ files:
142
170
  - spec/dummy/app/views/layouts/application.html.erb
143
171
  - spec/dummy/app/views/products/count_tags.html.erb
144
172
  - spec/dummy/app/views/products/implicit_columns.html.erb
173
+ - spec/dummy/app/views/products/local_storage.html.slim
145
174
  - spec/dummy/app/views/products/one_item_per_page.html.erb
146
175
  - spec/dummy/app/views/products/simple_index.html.erb
147
176
  - spec/dummy/app/views/products/stupid_array.html.erb
@@ -182,8 +211,11 @@ files:
182
211
  - spec/features/tabulatrs_spec.rb
183
212
  - spec/lib/tabulatr/data/data_spec.rb
184
213
  - spec/lib/tabulatr/data/filtering_spec.rb
214
+ - spec/lib/tabulatr/data/formatting_spec.rb
185
215
  - spec/lib/tabulatr/data/pagination_spec.rb
216
+ - spec/lib/tabulatr/data/sorting_spec.rb
186
217
  - spec/lib/tabulatr/json_builder_spec.rb
218
+ - spec/lib/tabulatr/renderer/checkbox_spec.rb
187
219
  - spec/lib/tabulatr/renderer/renderer_spec.rb
188
220
  - spec/spec_helper.rb
189
221
  - tabulatr.gemspec
@@ -208,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
240
  version: '0'
209
241
  requirements: []
210
242
  rubyforge_project:
211
- rubygems_version: 2.2.1
243
+ rubygems_version: 2.2.2
212
244
  signing_key:
213
245
  specification_version: 4
214
246
  summary: A tight DSL to build tables of ActiveRecord models with sorting, pagination,
@@ -236,6 +268,7 @@ test_files:
236
268
  - spec/dummy/app/views/layouts/application.html.erb
237
269
  - spec/dummy/app/views/products/count_tags.html.erb
238
270
  - spec/dummy/app/views/products/implicit_columns.html.erb
271
+ - spec/dummy/app/views/products/local_storage.html.slim
239
272
  - spec/dummy/app/views/products/one_item_per_page.html.erb
240
273
  - spec/dummy/app/views/products/simple_index.html.erb
241
274
  - spec/dummy/app/views/products/stupid_array.html.erb
@@ -276,7 +309,10 @@ test_files:
276
309
  - spec/features/tabulatrs_spec.rb
277
310
  - spec/lib/tabulatr/data/data_spec.rb
278
311
  - spec/lib/tabulatr/data/filtering_spec.rb
312
+ - spec/lib/tabulatr/data/formatting_spec.rb
279
313
  - spec/lib/tabulatr/data/pagination_spec.rb
314
+ - spec/lib/tabulatr/data/sorting_spec.rb
280
315
  - spec/lib/tabulatr/json_builder_spec.rb
316
+ - spec/lib/tabulatr/renderer/checkbox_spec.rb
281
317
  - spec/lib/tabulatr/renderer/renderer_spec.rb
282
318
  - spec/spec_helper.rb
@@ -1,86 +0,0 @@
1
- #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- module Tabulatr
25
- class Data
26
- module ColumnNameBuilder
27
- #--
28
- # Access the actual data
29
- #++
30
- def build_column_name(colname, table_name: nil, use_for: nil, assoc_name: nil)
31
- if column_with_table? colname
32
- t,c = split_column_name_from_table(colname)
33
- return build_column_name(c, table_name: t, use_for: use_for)
34
- end
35
- table_name ||= @table_name
36
- if table_name == @table_name
37
- mapping = get_mapping(requested_method: @columns[colname.to_sym], usage: use_for)
38
- return mapping if mapping.present?
39
- else
40
- assoc_name = table_name unless assoc_name
41
- include_relation! assoc_name
42
- mapping = get_mapping(requested_method: @assocs[assoc_name.to_sym][colname.to_sym], usage: use_for)
43
- return mapping if mapping.present?
44
- end
45
-
46
- complete_column_name table_name, colname
47
- end
48
-
49
- private
50
-
51
- def split_column_name_from_table column_name
52
- if column_with_table?(column_name)
53
- column_name.split(/\.|:/)
54
- else
55
- column_name
56
- end
57
- end
58
-
59
- def column_with_table? column_name
60
- column_name['.'] || column_name[':']
61
- end
62
-
63
- def complete_column_name table, column
64
- t = "#{table.tableize}.#{column}"
65
- raise "SECURITY violation, field name is '#{t}'" unless /^[\d\w]+(\.[\d\w]+)?$/.match t
66
- t
67
- end
68
-
69
- def get_mapping requested_method: nil, usage: nil
70
- return if requested_method.nil? || usage.nil?
71
- case usage.to_sym
72
- when :filter
73
- requested_method[:filter_sql]
74
- when :sort
75
- requested_method[:sort_sql]
76
- end
77
- end
78
-
79
- def include_relation! name_of_relation
80
- @includes << name_of_relation.to_sym
81
- end
82
- end
83
- end
84
- end
85
-
86
- Tabulatr::Data.send :include, Tabulatr::Data::ColumnNameBuilder