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 +4 -4
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/datagrid.gemspec +4 -4
- data/lib/datagrid/column_names_attribute.rb +4 -4
- data/lib/datagrid/scaffold.rb +25 -7
- data/spec/datagrid/column_names_attribute_spec.rb +20 -0
- data/spec/datagrid/scaffold_spec.rb +21 -12
- data/templates/controller.rb.erb +1 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a4a2eb29ee46c28e9a999c0344f1b7552259e1b
|
4
|
+
data.tar.gz: 758b66ea4521616cbb3dc76ac959a228446c33c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
1
|
+
1.4.3
|
data/datagrid.gemspec
CHANGED
@@ -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.
|
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.
|
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-
|
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.
|
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
|
-
|
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
|
-
|
53
|
+
available_columns - mandatory_columns
|
54
54
|
end
|
55
55
|
|
56
56
|
protected
|
data/lib/datagrid/scaffold.rb
CHANGED
@@ -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
|
-
|
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
|
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 '
|
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
|
12
|
+
context "when WillPaginate exists" do
|
18
13
|
before(:each) do
|
19
|
-
Object.const_set("
|
14
|
+
Object.const_set("WillPaginate", 1)
|
20
15
|
end
|
21
|
-
it '
|
22
|
-
expect(subject.pagination_helper_code).to eql('
|
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, "
|
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
|
data/templates/controller.rb.erb
CHANGED
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.
|
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-
|
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.
|
331
|
+
rubygems_version: 2.4.7
|
332
332
|
signing_key:
|
333
333
|
specification_version: 4
|
334
334
|
summary: Ruby gem to create datagrids
|