mighty_grid 0.5.0 → 0.6.0
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/README.md +1 -1
- data/app/views/mighty_grid/_actions.html.erb +11 -0
- data/lib/mighty_grid/base.rb +1 -1
- data/lib/mighty_grid/column.rb +7 -11
- data/lib/mighty_grid/grid_renderer.rb +17 -8
- data/lib/mighty_grid/helpers/mighty_grid_view_helpers.rb +5 -2
- data/lib/mighty_grid/version.rb +1 -1
- data/spec/lib/column_spec.rb +5 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9fb8a05f406c93425c49c6bc860276ab6d7140b
|
4
|
+
data.tar.gz: 6245a2f298bf5db56c004e3fb81d13413993dfcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4867e8238ab8c79d6c525bc5d1b325c6d57c7ab010e0a547bd66583e69cc17f87ee7de682b961e6adb9b9f7bcae40e0fb2f87d6a5a8585bd78a4984f6214880
|
7
|
+
data.tar.gz: 12f58aca2256556dca79d1932f9008a62212206b2d80fdbe4e0f0e0d7001bf9b17d137f6737522c7725b295e1d47a7f99723d34fba228ca1ad19e40dc9a3fe5d
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MightyGrid [](http://badge.fury.io/rb/mighty_grid) [](https://travis-ci.org/jurrick/mighty_grid) [](https://codeclimate.com/github/jurrick/mighty_grid) [](http://badge.fury.io/rb/mighty_grid) [](https://travis-ci.org/jurrick/mighty_grid) [](https://codeclimate.com/github/jurrick/mighty_grid) [](http://inch-ci.org/github/jurrick/mighty_grid)
|
2
2
|
|
3
3
|
MightyGrid is a flexible grid solution for Ruby On Rails.
|
4
4
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% if actions.include? :show %>
|
2
|
+
<%= link_to 'Просмотреть', url_for(object) %>
|
3
|
+
<br/>
|
4
|
+
<% end %>
|
5
|
+
<% if actions.include? :edit %>
|
6
|
+
<%= link_to 'Редактировать', url_for([:edit, object]) %>
|
7
|
+
<br/>
|
8
|
+
<% end %>
|
9
|
+
<% if actions.include? :destroy %>
|
10
|
+
<%= link_to 'Удалить', url_for(object), method: :delete, data: {confirm: 'Are you sure?'} %>
|
11
|
+
<% end %>
|
data/lib/mighty_grid/base.rb
CHANGED
@@ -2,7 +2,7 @@ module MightyGrid
|
|
2
2
|
|
3
3
|
class Base
|
4
4
|
|
5
|
-
attr_reader :klass, :name, :relation, :options, :mg_params
|
5
|
+
attr_reader :klass, :name, :relation, :options, :mg_params, :controller
|
6
6
|
attr_accessor :output_buffer, :filters
|
7
7
|
|
8
8
|
def initialize(klass_or_relation, controller, opts = {}) #:nodoc:
|
data/lib/mighty_grid/column.rb
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
module MightyGrid
|
2
2
|
class Column
|
3
3
|
|
4
|
-
attr_reader :attribute, :attrs, :th_attrs, :options, :title, :model
|
4
|
+
attr_reader :attribute, :attrs, :th_attrs, :options, :title, :model, :partial
|
5
5
|
attr_accessor :render_value
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(options={}, &block)
|
8
8
|
@attrs = {}
|
9
9
|
@th_attrs = {}
|
10
|
+
|
11
|
+
@attribute = options.delete(:attribute) if options.has_key?(:attribute)
|
12
|
+
|
13
|
+
@options ||= options
|
14
|
+
|
10
15
|
if block_given?
|
11
|
-
if attr_or_options.is_a?(Hash)
|
12
|
-
@options = attr_or_options || {}
|
13
|
-
else
|
14
|
-
@options = options || {}
|
15
|
-
@attribute = attr_or_options if attr_or_options.present?
|
16
|
-
end
|
17
|
-
|
18
16
|
@render_value = block
|
19
17
|
else
|
20
|
-
@options = options || {}
|
21
|
-
@attribute = attr_or_options
|
22
18
|
@render_value = @attribute
|
23
19
|
end
|
24
20
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module MightyGrid
|
2
2
|
class GridRenderer
|
3
|
-
attr_reader :columns, :th_columns, :
|
3
|
+
attr_reader :columns, :th_columns, :blank_slate_handler
|
4
4
|
|
5
5
|
def initialize(grid, view)
|
6
6
|
@grid = grid
|
@@ -26,15 +26,22 @@ module MightyGrid
|
|
26
26
|
end
|
27
27
|
|
28
28
|
if block_given?
|
29
|
-
|
30
|
-
@columns << MightyGrid::Column.new(attribute, options, &block)
|
31
|
-
else
|
32
|
-
@columns << MightyGrid::Column.new(options, &block)
|
33
|
-
end
|
29
|
+
@columns << MightyGrid::Column.new(options, &block)
|
34
30
|
else
|
35
|
-
@columns << MightyGrid::Column.new(
|
31
|
+
@columns << MightyGrid::Column.new(options)
|
36
32
|
end
|
37
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
def actions(opts = {})
|
36
|
+
options = {
|
37
|
+
partial: 'mighty_grid/actions',
|
38
|
+
only: [:show, :edit, :destroy]
|
39
|
+
}
|
40
|
+
|
41
|
+
opts.assert_valid_keys(options.keys)
|
42
|
+
options.merge!(opts)
|
43
|
+
|
44
|
+
@columns << MightyGrid::Column.new({title: 'Actions'}){ |object| @grid.controller.render_to_string(partial: options[:partial], locals: {actions: options[:only], object: object})}
|
38
45
|
end
|
39
46
|
|
40
47
|
def blank_slate(html_or_opts = nil, &block)
|
@@ -46,5 +53,7 @@ module MightyGrid
|
|
46
53
|
raise MightyGridArgumentError.new("blank_slate accepts only a string, a block, or :partial => 'path_to_partial' ")
|
47
54
|
end
|
48
55
|
end
|
56
|
+
|
57
|
+
def total_columns; @columns.count end
|
49
58
|
end
|
50
59
|
end
|
@@ -78,6 +78,10 @@ module MightyGrid
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
def actions_template(rendering)
|
82
|
+
render(partial: 'mighty_grid/actions')
|
83
|
+
end
|
84
|
+
|
81
85
|
private
|
82
86
|
|
83
87
|
def header_grid_html(rendering, grid, options)
|
@@ -96,13 +100,12 @@ module MightyGrid
|
|
96
100
|
if column.options[:ordering] && column.attribute.present?
|
97
101
|
order_asc = column.options[:order_asc] || options[:order_asc]
|
98
102
|
order_desc = column.options[:order_desc] || options[:order_desc]
|
103
|
+
order_active = grid.get_active_order_direction(grid_order_params(grid, column))
|
99
104
|
|
100
105
|
case options[:order_type]
|
101
106
|
when 'pair'
|
102
|
-
order_active = grid.get_active_order_direction(grid_order_params(grid, column))
|
103
107
|
order_asc_class = MightyGrid::MgHTML.join_html_classes({}, (order_active == 'asc' ? options[:order_active_link_class] : nil), options[:order_asc_link_class])[:class]
|
104
108
|
order_desc_class = MightyGrid::MgHTML.join_html_classes({}, (order_active == 'desc' ? options[:order_active_link_class] : nil), options[:order_desc_link_class])[:class]
|
105
|
-
|
106
109
|
html_title = column.title
|
107
110
|
html_title += content_tag :div, class: options[:order_wrapper_class] do
|
108
111
|
html_order = get_order_html(grid, column, order_active, order_asc, 'asc', class: order_asc_class)
|
data/lib/mighty_grid/version.rb
CHANGED
data/spec/lib/column_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe MightyGrid::Column do
|
|
5
5
|
describe '#new' do
|
6
6
|
describe 'with attribute' do
|
7
7
|
context 'without options' do
|
8
|
-
subject { MightyGrid::Column.new(:name) }
|
8
|
+
subject { MightyGrid::Column.new({attribute: :name}) }
|
9
9
|
context 'parameters' do
|
10
10
|
its(:attribute) { should == :name }
|
11
11
|
its(:render_value) { should == :name }
|
@@ -17,21 +17,21 @@ describe MightyGrid::Column do
|
|
17
17
|
|
18
18
|
context 'with html option' do
|
19
19
|
let(:options) { {html: {class: 'column'}} }
|
20
|
-
subject { MightyGrid::Column.new(:name
|
20
|
+
subject { MightyGrid::Column.new({attribute: :name}.merge(options)) }
|
21
21
|
its(:options) { should == options }
|
22
22
|
its(:attrs) { should == options[:html] }
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'with title option' do
|
26
26
|
let(:options) { {title: 'Name'} }
|
27
|
-
subject { MightyGrid::Column.new(:name
|
27
|
+
subject { MightyGrid::Column.new({attribute: :name}.merge(options)) }
|
28
28
|
its(:options) { should == options }
|
29
29
|
its(:title) { should == options[:title] }
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'with th_html option' do
|
33
33
|
let(:options) { {th_html: {class: 'active'}} }
|
34
|
-
subject { MightyGrid::Column.new(:name
|
34
|
+
subject { MightyGrid::Column.new({attribute: :name}.merge(options)) }
|
35
35
|
its(:options) { should == options }
|
36
36
|
its(:th_attrs) { should == {class: 'active'} }
|
37
37
|
end
|
@@ -55,7 +55,7 @@ describe MightyGrid::Column do
|
|
55
55
|
let(:user){ User.create(name: 'user name') }
|
56
56
|
|
57
57
|
describe 'with attribute' do
|
58
|
-
subject(:column){ MightyGrid::Column.new(:name) }
|
58
|
+
subject(:column){ MightyGrid::Column.new({attribute: :name}) }
|
59
59
|
it 'should return attribute value' do
|
60
60
|
column.render(user).should == user[:name]
|
61
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mighty_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jurrick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- app/views/kaminari/mighty_grid/_page.html.erb
|
103
103
|
- app/views/kaminari/mighty_grid/_paginator.html.erb
|
104
104
|
- app/views/kaminari/mighty_grid/_prev_page.html.erb
|
105
|
+
- app/views/mighty_grid/_actions.html.erb
|
105
106
|
- config/locales/en.yml
|
106
107
|
- features/filtering.feature
|
107
108
|
- features/step_definitions/steps.rb
|