datagrid 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b69adb5df9eebf47a8446dd095c6b966b635649
4
- data.tar.gz: 576710b7d11168fcde29d19eddc77f730b94fd43
3
+ metadata.gz: 2a4a2eb29ee46c28e9a999c0344f1b7552259e1b
4
+ data.tar.gz: 758b66ea4521616cbb3dc76ac959a228446c33c6
5
5
  SHA512:
6
- metadata.gz: 74512141aa0e4dd111ed9dea6783f562c71f509ae45b7a81395371b716331d75a5a95383e2157858c1555f7183de042f33143286eadef72a17db72dba9a83d3f
7
- data.tar.gz: 79d7d6e111160e03a1df224be0c3f8263cf968dc2d2266a1c3ca5a2f495adf9c0edb0f71d62e5428953f380b5b4fd3c1594848c7a89f03a41a40227f60b9a7d9
6
+ metadata.gz: 6232d055d5c2b037a18007ac3e77ec1423863da9a8e0085420a49d4275459c3d3e68f0451c285941d14cae0741ceadc6a62d866d279cd39d5db6bcc52a02969e
7
+ data.tar.gz: 8b06d12a459dd0a8cd2115d1c8721f5676859d747fc08cd890c748fb2949f8b4177050379ac040caf5b16883960f6e39f2729be22074f9b5e2670ba594aa972d
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ group :development do
9
9
 
10
10
 
11
11
  gem "debugger", :platform => :ruby_19
12
- gem "byebug", :platform => [:ruby_20, :ruby_21, :ruby_22] & Bundler::Dsl::VALID_PLATFORMS
12
+ gem "byebug", :platform => [:ruby_20, :ruby_21, :ruby_22, :ruby_23] & Bundler::Dsl::VALID_PLATFORMS
13
13
 
14
14
  gem "rspec", ">= 3"
15
15
  gem "nokogiri" # used to test html output
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.2
1
+ 1.4.3
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: datagrid 1.4.2 ruby lib
5
+ # stub: datagrid 1.4.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "datagrid"
9
- s.version = "1.4.2"
9
+ s.version = "1.4.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Bogdan Gusiev"]
14
- s.date = "2016-03-08"
14
+ s.date = "2016-03-31"
15
15
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
16
16
  s.email = "agresso@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -129,7 +129,7 @@ Gem::Specification.new do |s|
129
129
  ]
130
130
  s.homepage = "http://github.com/bogdan/datagrid"
131
131
  s.licenses = ["MIT"]
132
- s.rubygems_version = "2.4.5"
132
+ s.rubygems_version = "2.4.7"
133
133
  s.summary = "Ruby gem to create datagrids"
134
134
 
135
135
  if s.respond_to? :specification_version then
@@ -42,15 +42,15 @@ module Datagrid
42
42
  super(*column_names)
43
43
  end
44
44
 
45
- # Returns a list of columns with <tt>:mandatory => true</tt> option
45
+ # Returns a list of enabled columns with <tt>:mandatory => true</tt> option
46
46
  # If no mandatory columns specified than all of them considered mandatory
47
47
  def mandatory_columns
48
- columns_array.select(&:mandatory?)
48
+ available_columns.select {|c| c.mandatory? }
49
49
  end
50
50
 
51
- # Returns a list of columns without <tt>:mandatory => true</tt> option
51
+ # Returns a list of enabled columns without <tt>:mandatory => true</tt> option
52
52
  def optional_columns
53
- columns_array - mandatory_columns
53
+ available_columns - mandatory_columns
54
54
  end
55
55
 
56
56
  protected
@@ -1,11 +1,19 @@
1
1
  require "rails/generators"
2
2
 
3
3
  class Datagrid::Scaffold < Rails::Generators::NamedBase
4
+
5
+ include Rails::Generators::ResourceHelpers
6
+
7
+ check_class_collision :suffix => "Grid"
4
8
  source_root File.expand_path(__FILE__ + "/../../../templates")
5
9
 
6
10
  def create_scaffold
7
11
  template "grid.rb.erb", "app/grids/#{grid_class_name.underscore}.rb"
8
- template "controller.rb.erb", "app/controllers/#{grid_controller_name.underscore}.rb"
12
+ if File.exists?(grid_controller_file)
13
+ inject_into_file grid_controller_file, index_action, :after => %r{class .*#{grid_controller_name}.*\n}
14
+ else
15
+ template "controller.rb.erb", grid_controller_file
16
+ end
9
17
  template "index.html.erb", "app/views/#{grid_controller_short_name}/index.html.erb"
10
18
  route("resources :#{grid_controller_short_name}")
11
19
  unless defined?(::Kaminari) || defined?(::WillPaginate)
@@ -28,11 +36,15 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
28
36
  def grid_class_name
29
37
  file_name.camelize.pluralize + "Grid"
30
38
  end
31
-
39
+
32
40
  def grid_controller_name
33
41
  grid_controller_short_name.camelize + "Controller"
34
42
  end
35
43
 
44
+ def grid_controller_file
45
+ Rails.root.join("app/controllers/#{grid_controller_name.underscore}.rb")
46
+ end
47
+
36
48
  def grid_controller_short_name
37
49
  file_name.underscore.pluralize
38
50
  end
@@ -41,14 +53,10 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
41
53
  file_name.camelize.singularize
42
54
  end
43
55
 
44
- def grid_ivar_name
56
+ def grid_param_name
45
57
  grid_class_name.underscore
46
58
  end
47
59
 
48
- def paginate_code
49
- "page(params[:page])"
50
- end
51
-
52
60
  def pagination_helper_code
53
61
  if defined?(::WillPaginate)
54
62
  "will_paginate(@grid.assets)"
@@ -63,4 +71,14 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
63
71
  grid_controller_short_name + "_path"
64
72
  end
65
73
 
74
+ def index_action
75
+ indent(<<-RUBY)
76
+ def index
77
+ @grid = #{grid_class_name}.new(params[:#{grid_param_name}]) do |scope|
78
+ scope.page(params[:page])
79
+ end
80
+ end
81
+ RUBY
82
+ end
83
+
66
84
  end
@@ -63,4 +63,24 @@ describe Datagrid::ColumnNamesAttribute do
63
63
  end
64
64
 
65
65
  end
66
+
67
+ context "when some columns are disabled" do
68
+ subject do
69
+ test_report do
70
+ scope {Entry}
71
+ column(:id, :mandatory => true)
72
+ column(:name)
73
+ column(:category, if: proc { false })
74
+ column(:group, :mandatory => true, if: proc { false })
75
+ end
76
+ end
77
+
78
+ it "excludes them from mandatory_columns" do
79
+ expect(subject.mandatory_columns.map(&:name)).to eq([:id])
80
+ end
81
+
82
+ it "excludes them from optional_columns" do
83
+ expect(subject.optional_columns.map(&:name)).to eq([:name])
84
+ end
85
+ end
66
86
  end
@@ -1,30 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datagrid::Scaffold do
4
- subject { Datagrid::Scaffold.new([""]) }
4
+ subject { Datagrid::Scaffold.new(["user"]) }
5
5
 
6
- describe '.paginate_code' do
7
- it 'should fall through options successfully' do
8
- expect(subject.paginate_code).to eql('page(params[:page])')
9
- end
10
- end
11
6
 
12
7
  describe '.pagination_helper_code' do
13
- it 'should fall through options successfully' do
8
+ it 'uses kaminari by default' do
14
9
  expect(subject.pagination_helper_code).to eql('paginate(@grid.assets)')
15
10
  end
16
11
 
17
- context "when Kaminari exists" do
12
+ context "when WillPaginate exists" do
18
13
  before(:each) do
19
- Object.const_set("Kaminari", 1)
14
+ Object.const_set("WillPaginate", 1)
20
15
  end
21
- it 'should fall through options successfully' do
22
- expect(subject.pagination_helper_code).to eql('paginate(@grid.assets)')
16
+ it 'uses willpaginate' do
17
+ expect(subject.pagination_helper_code).to eql('will_paginate(@grid.assets)')
23
18
  end
24
19
 
25
20
  after(:each) do
26
- Object.send(:remove_const, "Kaminari")
21
+ Object.send(:remove_const, "WillPaginate")
27
22
  end
28
23
  end
29
24
  end
25
+
26
+ describe ".index_action" do
27
+
28
+ it "works" do
29
+ expect(subject.index_action).to eq(<<-RUBY)
30
+ def index
31
+ @grid = UsersGrid.new(params[:users_grid]) do |scope|
32
+ scope.page(params[:page])
33
+ end
34
+ end
35
+ RUBY
36
+ end
37
+
38
+ end
30
39
  end
@@ -1,10 +1,6 @@
1
1
  class <%= grid_controller_name %> < ApplicationController
2
2
 
3
- def index
4
- @grid = <%= grid_class_name %>.new(params[:<%= grid_ivar_name %>]) do |scope|
5
- scope.<%= paginate_code %>
6
- end
7
- end
3
+ <%= index_action -%>
8
4
 
9
5
  end
10
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -328,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
328
  version: '0'
329
329
  requirements: []
330
330
  rubyforge_project:
331
- rubygems_version: 2.4.5
331
+ rubygems_version: 2.4.7
332
332
  signing_key:
333
333
  specification_version: 4
334
334
  summary: Ruby gem to create datagrids