datagrid 1.5.9 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Readme.markdown +6 -4
  4. data/app/views/datagrid/_table.html.erb +1 -1
  5. data/datagrid.gemspec +29 -166
  6. data/lib/datagrid/column_names_attribute.rb +15 -16
  7. data/lib/datagrid/columns.rb +34 -37
  8. data/lib/datagrid/columns/column.rb +4 -0
  9. data/lib/datagrid/core.rb +13 -1
  10. data/lib/datagrid/drivers/active_record.rb +2 -1
  11. data/lib/datagrid/drivers/mongoid.rb +5 -1
  12. data/lib/datagrid/filters.rb +3 -6
  13. data/lib/datagrid/filters/base_filter.rb +8 -0
  14. data/lib/datagrid/filters/composite_filters.rb +4 -4
  15. data/lib/datagrid/form_builder.rb +18 -15
  16. data/lib/datagrid/helper.rb +3 -3
  17. data/lib/datagrid/renderer.rb +2 -5
  18. data/lib/datagrid/utils.rb +2 -6
  19. data/lib/datagrid/version.rb +3 -0
  20. metadata +15 -201
  21. data/.document +0 -5
  22. data/.rspec +0 -1
  23. data/.travis.yml +0 -21
  24. data/Gemfile +0 -29
  25. data/Rakefile +0 -43
  26. data/VERSION +0 -1
  27. data/spec/datagrid/active_model_spec.rb +0 -33
  28. data/spec/datagrid/column_names_attribute_spec.rb +0 -86
  29. data/spec/datagrid/columns/column_spec.rb +0 -19
  30. data/spec/datagrid/columns_spec.rb +0 -592
  31. data/spec/datagrid/core_spec.rb +0 -196
  32. data/spec/datagrid/drivers/active_record_spec.rb +0 -79
  33. data/spec/datagrid/drivers/array_spec.rb +0 -106
  34. data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
  35. data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
  36. data/spec/datagrid/drivers/sequel_spec.rb +0 -111
  37. data/spec/datagrid/filters/base_filter_spec.rb +0 -19
  38. data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
  39. data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
  40. data/spec/datagrid/filters/date_filter_spec.rb +0 -195
  41. data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
  42. data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
  43. data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
  44. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
  45. data/spec/datagrid/filters/float_filter_spec.rb +0 -15
  46. data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
  47. data/spec/datagrid/filters/string_filter_spec.rb +0 -35
  48. data/spec/datagrid/filters_spec.rb +0 -332
  49. data/spec/datagrid/form_builder_spec.rb +0 -614
  50. data/spec/datagrid/helper_spec.rb +0 -640
  51. data/spec/datagrid/ordering_spec.rb +0 -150
  52. data/spec/datagrid/scaffold_spec.rb +0 -45
  53. data/spec/datagrid/stylesheet_spec.rb +0 -12
  54. data/spec/datagrid/utils_spec.rb +0 -19
  55. data/spec/datagrid_spec.rb +0 -83
  56. data/spec/spec_helper.rb +0 -114
  57. data/spec/support/active_record.rb +0 -38
  58. data/spec/support/configuration.rb +0 -28
  59. data/spec/support/i18n_helpers.rb +0 -6
  60. data/spec/support/matchers.rb +0 -101
  61. data/spec/support/mongo_mapper.rb +0 -32
  62. data/spec/support/mongoid.rb +0 -36
  63. data/spec/support/sequel.rb +0 -39
  64. data/spec/support/simple_report.rb +0 -64
  65. data/spec/support/test_partials/_actions.html.erb +0 -1
  66. data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
  67. data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
  68. data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
  69. data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
  70. data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
  71. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
  72. data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
  73. data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94a9a3ff232cd83f323e280e35a805ebd4ec725b74b531c18328c4de27952f2f
4
- data.tar.gz: c91f39764fa86f0d8b016de33eeabfd37b47d16411f3f52ec796f2bf1d14d534
3
+ metadata.gz: a5f1043a8a905be92c309d00b6c0b107ebec35939c89b5766f5d7c43dbe2c584
4
+ data.tar.gz: 8b4bd8b0130ef2fa83cebe7012386ffcdb4d9ba32d3e803080e4345d6eb74dee
5
5
  SHA512:
6
- metadata.gz: b999afc64d7094dfd47a2e4f393824df58edf15769c445a9d16712dc6f531f3b30f872046cd657bc9323df6a460b4d1a74334fc4b498de141a9998d3aa6c34bc
7
- data.tar.gz: 89d0e83bd75e28ee33dc890d2f5f82de6391a9d32b0723e77afa8dfc0856d126c1fe0ee4c8ab5b0b2f5491e5908b45e14de0bd18669c2786764faeac8c6fc0c2
6
+ metadata.gz: 4c42259fe4c806e235d10610ab4b3681319d8f5712c73addc1d54f61d6e6cbd0447a967464f878464da2b54f60dc376acef5238cce1467a097d7cbf799beb51d
7
+ data.tar.gz: 1ac692930c8a269190bc36ecce7c50cf1c1696fe5b9b6dc0644adfa59eb15a2bab77f4dac70a29633693e707e53ef29ed874eda6f6c82533ed441afe72a5d304
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 1.6.3
2
+
3
+ * Fix usage of options spread operator for ruby 3.0 [#296](https://github.com/bogdan/datagrid/issues/296)
4
+
5
+ ## 1.6.2
6
+
7
+ * Add `input_options` and `label_options` to `filter` method [#294](https://github.com/bogdan/datagrid/issues/294)
8
+ * Fix `<option>` tag rendering for Rails 6.0
9
+
10
+ ## 1.6.1 and before
11
+
12
+ Changes are not tracked
data/Readme.markdown CHANGED
@@ -1,6 +1,7 @@
1
1
  # Datagrid
2
2
 
3
3
  [![Build Status](https://travis-ci.org/bogdan/datagrid.svg?branch=master)](https://travis-ci.org/bogdan/datagrid)
4
+
4
5
  [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid?ref=badge_shield)
5
6
 
6
7
  Ruby library that helps you to build and represent table-like data with:
@@ -22,10 +23,11 @@ Ruby library that helps you to build and represent table-like data with:
22
23
  [Create an issue](https://github.com/bogdan/datagrid/issues/new) if you want more.
23
24
 
24
25
 
25
- ### Dependencies
26
+ ### Documentation
26
27
 
27
- * Ruby >= 2.0
28
- * Rails >= 3.2
28
+ * [Readme](/Readme.markdown) - this read-me for basic information
29
+ * [Wiki](https://github.com/bogdan/datagrid/wiki) - general reference on how to use the gem
30
+ * [Rdoc](https://rdoc.info/github/bogdan/datagrid) - API reference
29
31
 
30
32
  ### Live Demo
31
33
 
@@ -201,4 +203,4 @@ Read [author blog](http://gusiev.com).
201
203
 
202
204
 
203
205
  ## License
204
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid?ref=badge_large)
206
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid?ref=badge_large)
@@ -11,7 +11,7 @@ Local variables:
11
11
  </thead>
12
12
  <tbody>
13
13
  <% if assets.any? %>
14
- <%= datagrid_rows(grid, assets, options) %>
14
+ <%= datagrid_rows(grid, assets, **options) %>
15
15
  <% else %>
16
16
  <tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
17
17
  <% end %>
data/datagrid.gemspec CHANGED
@@ -1,178 +1,41 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: datagrid 1.5.9 ruby lib
1
+ # frozen_string_literal: true
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "datagrid/version"
6
5
 
7
6
  Gem::Specification.new do |s|
8
- s.name = "datagrid".freeze
9
- s.version = "1.5.9"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib".freeze]
13
- s.authors = ["Bogdan Gusiev".freeze]
14
- s.date = "2019-05-10"
15
- s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters".freeze
16
- s.email = "agresso@gmail.com".freeze
7
+ s.name = "datagrid"
8
+ s.version = Datagrid::VERSION
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Bogdan Gusiev"]
11
+ s.date = "2020-09-07"
12
+ s.summary = "Ruby gem to create datagrids"
13
+ s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
14
+ s.email = "agresso@gmail.com"
17
15
  s.extra_rdoc_files = [
18
- "LICENSE.txt"
16
+ "LICENSE.txt",
17
+ "Readme.markdown"
19
18
  ]
20
19
  s.files = [
21
- ".document",
22
- ".rspec",
23
- ".travis.yml",
24
- "Gemfile",
25
20
  "LICENSE.txt",
26
- "Rakefile",
21
+ "CHANGELOG.md",
27
22
  "Readme.markdown",
28
- "VERSION",
29
- "app/assets/stylesheets/datagrid.sass",
30
- "app/views/datagrid/_enum_checkboxes.html.erb",
31
- "app/views/datagrid/_form.html.erb",
32
- "app/views/datagrid/_head.html.erb",
33
- "app/views/datagrid/_order_for.html.erb",
34
- "app/views/datagrid/_range_filter.html.erb",
35
- "app/views/datagrid/_row.html.erb",
36
- "app/views/datagrid/_table.html.erb",
37
23
  "datagrid.gemspec",
38
- "lib/datagrid.rb",
39
- "lib/datagrid/active_model.rb",
40
- "lib/datagrid/column_names_attribute.rb",
41
- "lib/datagrid/columns.rb",
42
- "lib/datagrid/columns/column.rb",
43
- "lib/datagrid/configuration.rb",
44
- "lib/datagrid/core.rb",
45
- "lib/datagrid/drivers.rb",
46
- "lib/datagrid/drivers/abstract_driver.rb",
47
- "lib/datagrid/drivers/active_record.rb",
48
- "lib/datagrid/drivers/array.rb",
49
- "lib/datagrid/drivers/mongo_mapper.rb",
50
- "lib/datagrid/drivers/mongoid.rb",
51
- "lib/datagrid/drivers/sequel.rb",
52
- "lib/datagrid/engine.rb",
53
- "lib/datagrid/filters.rb",
54
- "lib/datagrid/filters/base_filter.rb",
55
- "lib/datagrid/filters/boolean_enum_filter.rb",
56
- "lib/datagrid/filters/boolean_filter.rb",
57
- "lib/datagrid/filters/composite_filters.rb",
58
- "lib/datagrid/filters/date_filter.rb",
59
- "lib/datagrid/filters/date_time_filter.rb",
60
- "lib/datagrid/filters/default_filter.rb",
61
- "lib/datagrid/filters/dynamic_filter.rb",
62
- "lib/datagrid/filters/enum_filter.rb",
63
- "lib/datagrid/filters/extended_boolean_filter.rb",
64
- "lib/datagrid/filters/float_filter.rb",
65
- "lib/datagrid/filters/integer_filter.rb",
66
- "lib/datagrid/filters/ranged_filter.rb",
67
- "lib/datagrid/filters/select_options.rb",
68
- "lib/datagrid/filters/string_filter.rb",
69
- "lib/datagrid/form_builder.rb",
70
- "lib/datagrid/helper.rb",
71
- "lib/datagrid/locale/en.yml",
72
- "lib/datagrid/ordering.rb",
73
- "lib/datagrid/renderer.rb",
74
- "lib/datagrid/rspec.rb",
75
- "lib/datagrid/scaffold.rb",
76
- "lib/datagrid/utils.rb",
77
- "lib/tasks/datagrid_tasks.rake",
78
- "spec/datagrid/active_model_spec.rb",
79
- "spec/datagrid/column_names_attribute_spec.rb",
80
- "spec/datagrid/columns/column_spec.rb",
81
- "spec/datagrid/columns_spec.rb",
82
- "spec/datagrid/core_spec.rb",
83
- "spec/datagrid/drivers/active_record_spec.rb",
84
- "spec/datagrid/drivers/array_spec.rb",
85
- "spec/datagrid/drivers/mongo_mapper_spec.rb",
86
- "spec/datagrid/drivers/mongoid_spec.rb",
87
- "spec/datagrid/drivers/sequel_spec.rb",
88
- "spec/datagrid/filters/base_filter_spec.rb",
89
- "spec/datagrid/filters/boolean_enum_filter_spec.rb",
90
- "spec/datagrid/filters/composite_filters_spec.rb",
91
- "spec/datagrid/filters/date_filter_spec.rb",
92
- "spec/datagrid/filters/date_time_filter_spec.rb",
93
- "spec/datagrid/filters/dynamic_filter_spec.rb",
94
- "spec/datagrid/filters/enum_filter_spec.rb",
95
- "spec/datagrid/filters/extended_boolean_filter_spec.rb",
96
- "spec/datagrid/filters/float_filter_spec.rb",
97
- "spec/datagrid/filters/integer_filter_spec.rb",
98
- "spec/datagrid/filters/string_filter_spec.rb",
99
- "spec/datagrid/filters_spec.rb",
100
- "spec/datagrid/form_builder_spec.rb",
101
- "spec/datagrid/helper_spec.rb",
102
- "spec/datagrid/ordering_spec.rb",
103
- "spec/datagrid/scaffold_spec.rb",
104
- "spec/datagrid/stylesheet_spec.rb",
105
- "spec/datagrid/utils_spec.rb",
106
- "spec/datagrid_spec.rb",
107
- "spec/spec_helper.rb",
108
- "spec/support/active_record.rb",
109
- "spec/support/configuration.rb",
110
- "spec/support/i18n_helpers.rb",
111
- "spec/support/matchers.rb",
112
- "spec/support/mongo_mapper.rb",
113
- "spec/support/mongoid.rb",
114
- "spec/support/sequel.rb",
115
- "spec/support/simple_report.rb",
116
- "spec/support/test_partials/_actions.html.erb",
117
- "spec/support/test_partials/client/datagrid/_form.html.erb",
118
- "spec/support/test_partials/client/datagrid/_head.html.erb",
119
- "spec/support/test_partials/client/datagrid/_order_for.html.erb",
120
- "spec/support/test_partials/client/datagrid/_row.html.erb",
121
- "spec/support/test_partials/client/datagrid/_table.html.erb",
122
- "spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb",
123
- "spec/support/test_partials/custom_form/_form.html.erb",
124
- "spec/support/test_partials/custom_range/_range_filter.html.erb",
125
- "templates/base.rb.erb",
126
- "templates/controller.rb.erb",
127
- "templates/grid.rb.erb",
128
- "templates/index.html.erb"
129
24
  ]
130
- s.homepage = "http://github.com/bogdan/datagrid".freeze
131
- s.licenses = ["MIT".freeze]
132
- s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
133
- s.rubygems_version = "2.7.8".freeze
134
- s.summary = "Ruby gem to create datagrids".freeze
135
-
136
- if s.respond_to? :specification_version then
137
- s.specification_version = 4
25
+ s.files += `git ls-files | grep -E '^(app|lib|templates)'`.split("\n")
26
+ s.homepage = "http://github.com/bogdan/datagrid"
27
+ s.licenses = ["MIT"]
28
+ s.required_ruby_version = Gem::Requirement.new(">= 2.0")
29
+ s.rubygems_version = "3.0.8"
30
+ url = 'https://github.com/bogdan/datagrid'
31
+ s.metadata = {
32
+ "homepage_uri" => url,
33
+ "bug_tracker_uri" => "#{url}/issues",
34
+ "documentation_uri" => "#{url}/wiki",
35
+ "changelog_uri" => "#{url}/blob/master/CHANGELOG.md",
36
+ "source_code_uri" => url,
37
+ }
138
38
 
139
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
140
- s.add_runtime_dependency(%q<rails>.freeze, [">= 4.0"])
141
- s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
142
- s.add_development_dependency(%q<jeweler>.freeze, [">= 2.1.2"])
143
- s.add_development_dependency(%q<pry-byebug>.freeze, [">= 0"])
144
- s.add_development_dependency(%q<rspec>.freeze, [">= 3"])
145
- s.add_development_dependency(%q<nokogiri>.freeze, [">= 0"])
146
- s.add_development_dependency(%q<sqlite3>.freeze, ["~> 1.3.6"])
147
- s.add_development_dependency(%q<sequel>.freeze, [">= 0"])
148
- s.add_development_dependency(%q<mongoid>.freeze, [">= 0"])
149
- s.add_development_dependency(%q<bson>.freeze, [">= 0"])
150
- s.add_development_dependency(%q<bson_ext>.freeze, [">= 0"])
151
- else
152
- s.add_dependency(%q<rails>.freeze, [">= 4.0"])
153
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
154
- s.add_dependency(%q<jeweler>.freeze, [">= 2.1.2"])
155
- s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
156
- s.add_dependency(%q<rspec>.freeze, [">= 3"])
157
- s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
158
- s.add_dependency(%q<sqlite3>.freeze, ["~> 1.3.6"])
159
- s.add_dependency(%q<sequel>.freeze, [">= 0"])
160
- s.add_dependency(%q<mongoid>.freeze, [">= 0"])
161
- s.add_dependency(%q<bson>.freeze, [">= 0"])
162
- s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
163
- end
164
- else
165
- s.add_dependency(%q<rails>.freeze, [">= 4.0"])
166
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
167
- s.add_dependency(%q<jeweler>.freeze, [">= 2.1.2"])
168
- s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
169
- s.add_dependency(%q<rspec>.freeze, [">= 3"])
170
- s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
171
- s.add_dependency(%q<sqlite3>.freeze, ["~> 1.3.6"])
172
- s.add_dependency(%q<sequel>.freeze, [">= 0"])
173
- s.add_dependency(%q<mongoid>.freeze, [">= 0"])
174
- s.add_dependency(%q<bson>.freeze, [">= 0"])
175
- s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
176
- end
39
+ s.add_dependency(%q<rails>, [">= 4.0"])
177
40
  end
178
41
 
@@ -23,23 +23,22 @@ module Datagrid
23
23
  # Accepts same options as <tt>:enum</tt> filter
24
24
  #
25
25
  # Examples:
26
- #
27
- # column_names_filter(:header => "Choose columns")
28
- #
29
- def column_names_filter(options = {})
30
- filter(:column_names, :enum, {
31
- :select => :optional_columns_select,
32
- :multiple => true,
33
- :dummy => true
34
- }.merge(options || {}))
26
+ #
27
+ # column_names_filter(header: "Choose columns")
28
+ #
29
+ def column_names_filter(**options)
30
+ filter(
31
+ :column_names, :enum,
32
+ select: :optional_columns_select,
33
+ multiple: true,
34
+ dummy: true,
35
+ **options,
36
+ )
35
37
  end
36
38
  end
37
39
 
38
- def columns(*args) #:nodoc:
39
- options = args.extract_options!
40
- column_names = selected_column_names(*args)
41
- column_names << options
42
- super(*column_names)
40
+ def columns(*args, **options) #:nodoc:
41
+ super(*selected_column_names(*args), **options)
43
42
  end
44
43
 
45
44
  # Returns a list of enabled columns with <tt>:mandatory => true</tt> option
@@ -59,7 +58,7 @@ module Datagrid
59
58
  optional_columns.map {|c| [c.header, c.name] }
60
59
  end
61
60
 
62
- def selected_column_names(*args)
61
+ def selected_column_names(*args)
63
62
  if args.any?
64
63
  args.compact!
65
64
  args.map!(&:to_sym)
@@ -75,7 +74,7 @@ module Datagrid
75
74
 
76
75
  def columns_visibility_enabled?
77
76
  columns_array.any? do |column|
78
- column.options.key?(:mandatory)
77
+ column.mandatory_explicitly_set?
79
78
  end
80
79
  end
81
80
 
@@ -16,6 +16,7 @@ module Datagrid
16
16
  self.default_column_options = {}
17
17
 
18
18
  class_attribute :batch_size
19
+ self.batch_size = 1000
19
20
 
20
21
  class_attribute :columns_array
21
22
  self.columns_array = []
@@ -85,9 +86,10 @@ module Datagrid
85
86
  #
86
87
  # Supported options:
87
88
  #
88
- # * :data - if true returns only non-html columns. Default: false.
89
- def columns(*args)
90
- filter_columns(columns_array, *args)
89
+ # * :data - if true returns only columns with data representation. Default: false.
90
+ # * :html - if true returns only columns with html columns. Default: false.
91
+ def columns(*args, data: false, html: false)
92
+ filter_columns(columns_array, *args, data: data, html: html)
91
93
  end
92
94
 
93
95
  # Defines new datagrid column
@@ -120,8 +122,8 @@ module Datagrid
120
122
  # * <tt>:preload</tt> - spefies which associations of the scope should be preloaded for this column
121
123
  #
122
124
  # See: https://github.com/bogdan/datagrid/wiki/Columns for examples
123
- def column(name, options_or_query = {}, options = {}, &block)
124
- define_column(columns_array, name, options_or_query, options, &block)
125
+ def column(name, query = nil, **options, &block)
126
+ define_column(columns_array, name, query, **options, &block)
125
127
  end
126
128
 
127
129
  # Returns column definition with given name
@@ -183,23 +185,17 @@ module Datagrid
183
185
  child_class.columns_array = self.columns_array.clone
184
186
  end
185
187
 
186
- def filter_columns(columns, *args) #:nodoc:
187
- options = args.extract_options!
188
- args.compact!
189
- args.map!(&:to_sym)
190
- columns.select do |column|
191
- (!options[:data] || column.data?) &&
192
- (!options[:html] || column.html?) &&
193
- (column.mandatory? || args.empty? || args.include?(column.name))
188
+ def filter_columns(columns_array, *names, data: false, html: false) #:nodoc:
189
+ names.compact!
190
+ names.map!(&:to_sym)
191
+ columns_array.select do |column|
192
+ (!data || column.data?) &&
193
+ (!html || column.html?) &&
194
+ (column.mandatory? || names.empty? || names.include?(column.name))
194
195
  end
195
196
  end
196
197
 
197
- def define_column(columns, name, options_or_query = {}, options = {}, &block) #:nodoc:
198
- if options_or_query.is_a?(String)
199
- query = options_or_query
200
- else
201
- options = options_or_query
202
- end
198
+ def define_column(columns, name, query = nil, **options, &block) #:nodoc:
203
199
  check_scope_defined!("Scope should be defined before columns")
204
200
  block ||= lambda do |model|
205
201
  model.send(name)
@@ -312,11 +308,12 @@ module Datagrid
312
308
  # grid.to_csv
313
309
  # grid.to_csv(:id, :name)
314
310
  # grid.to_csv(:col_sep => ';')
315
- def to_csv(*column_names)
311
+ def to_csv(*column_names, **options)
316
312
  require "csv"
317
- options = column_names.extract_options!
318
313
  CSV.generate(
319
- {:headers => self.header(*column_names), :write_headers => true}.merge!(options)
314
+ headers: self.header(*column_names),
315
+ write_headers: true,
316
+ **options
320
317
  ) do |csv|
321
318
  each_with_batches do |asset|
322
319
  csv << row_for(asset, *column_names)
@@ -333,24 +330,22 @@ module Datagrid
333
330
  # grid = MyGrid.new(:column_names => [:id, :name])
334
331
  # grid.columns # => id and name columns
335
332
  # grid.columns(:id, :category) # => id and category column
336
- def columns(*args)
337
- self.class.filter_columns(columns_array, *args).select {|column| column.enabled?(self)}
333
+ def columns(*args, data: false, html: false)
334
+ self.class.filter_columns(
335
+ columns_array, *args, data: data, html: html
336
+ ).select do |column|
337
+ column.enabled?(self)
338
+ end
338
339
  end
339
340
 
340
341
  # Returns all columns that can be represented in plain data(non-html) way
341
- def data_columns(*names)
342
- options = names.extract_options!
343
- options[:data] = true
344
- names << options
345
- self.columns(*names)
342
+ def data_columns(*names, **options)
343
+ self.columns(*names, **options, data: true)
346
344
  end
347
345
 
348
346
  # Returns all columns that can be represented in HTML table
349
- def html_columns(*names)
350
- options = names.extract_options!
351
- options[:html] = true
352
- names << options
353
- self.columns(*names)
347
+ def html_columns(*names, **options)
348
+ self.columns(*names, **options, html: true)
354
349
  end
355
350
 
356
351
  # Finds a column definition by name
@@ -406,8 +401,8 @@ module Datagrid
406
401
  # Defines a column at instance level
407
402
  #
408
403
  # See Datagrid::Columns::ClassMethods#column for more info
409
- def column(name, options_or_query = {}, options = {}, &block) #:nodoc:
410
- self.class.define_column(columns_array, name, options_or_query, options, &block)
404
+ def column(name, query = nil, **options, &block)
405
+ self.class.define_column(columns_array, name, query, **options, &block)
411
406
  end
412
407
 
413
408
  def initialize(*) #:nodoc:
@@ -415,7 +410,7 @@ module Datagrid
415
410
  super
416
411
  end
417
412
 
418
- # Returns all columns available for current grid configuration.
413
+ # Returns all columns that are possible to be displayed for the current grid object
419
414
  #
420
415
  # class MyGrid
421
416
  # filter(:search) {|scope, value| scope.full_text_search(value)}
@@ -535,6 +530,8 @@ module Datagrid
535
530
  def value_from_html_block(context, asset, column)
536
531
  args = []
537
532
  remaining_arity = column.html_block.arity
533
+ remaining_arity = 1 if remaining_arity < 0
534
+
538
535
  asset = decorate(asset)
539
536
 
540
537
  if column.data?