mighty_grid 0.1.0 → 0.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4844d991f9821e4d7f8c255c34eda1e0e162cf5b
|
4
|
+
data.tar.gz: fa07a1f87c95c2ac6d7fafa723d89c3d7010c7b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7cfed903a2b101ce0fcf90451588fd9162ca5285720e8645c25bfa5535a452e2e37820d3a59c3b36085cbc188ce997387a61edd98bcb6a204a910684e276bf5
|
7
|
+
data.tar.gz: 8a26a1320f48f36084caee47be29ceeb490a03dfb170846ae2b792071f76a5ce44197354ac71b0a7ef190ae423f3cb76b77a8140f708f3359cc0e4cbf31a2a28
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module MightyGrid
|
2
2
|
class GridRenderer
|
3
|
-
attr_reader :columns, :th_columns, :total_columns
|
3
|
+
attr_reader :columns, :th_columns, :total_columns, :blank_slate_handler
|
4
4
|
|
5
5
|
def initialize(grid, view)
|
6
6
|
@columns = []
|
7
7
|
@th_columns = []
|
8
|
+
@blank_slate_handler = nil
|
8
9
|
end
|
9
10
|
|
10
11
|
def column(attr_or_options = {}, options=nil, &block)
|
@@ -23,5 +24,15 @@ module MightyGrid
|
|
23
24
|
end
|
24
25
|
@total_columns = @columns.count
|
25
26
|
end
|
27
|
+
|
28
|
+
def blank_slate(html_or_opts, &block)
|
29
|
+
if (html_or_opts.is_a?(Hash) && html_or_opts.has_key?(:partial) || html_or_opts.is_a?(String)) && !block_given?
|
30
|
+
@blank_slate_handler = html_or_opts
|
31
|
+
elsif html_or_opts.nil? && block_given?
|
32
|
+
@blank_slate_handler = block
|
33
|
+
else
|
34
|
+
raise MightyGridArgumentError.new("blank_slate accepts only a string, a block, or :partial => 'path_to_partial' ")
|
35
|
+
end
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
@@ -12,29 +12,33 @@ module MightyGrid
|
|
12
12
|
block.call(rendering)
|
13
13
|
|
14
14
|
table_html_attrs = options[:html] || {}
|
15
|
-
table_html_attrs
|
16
|
-
table_html_classes = ["mighty-grid"] + MightyGrid.config.table_class.split(' ')
|
17
|
-
table_html_attrs[:class] = (table_html_classes + table_html_attrs[:class].split(' ')).reject(&:blank?).uniq.join(' ')
|
15
|
+
table_html_attrs = MightyGrid::MgHTML.join_html_classes(table_html_attrs, 'mighty-grid', MightyGrid.config.table_class)
|
18
16
|
|
19
17
|
grid.read
|
20
18
|
|
21
|
-
grid.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
if grid.relation.total_count > 0
|
20
|
+
grid.output_buffer = content_tag :table, table_html_attrs do
|
21
|
+
html = header_grid_html(rendering, grid, options)
|
22
|
+
html += footer_grid_html(rendering, grid)
|
23
|
+
html += body_grid_html(rendering, grid)
|
24
|
+
html
|
25
|
+
end
|
26
|
+
else
|
27
|
+
grid.output_buffer = blank_slate_template(rendering)
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|
29
31
|
|
32
|
+
# Used after <tt>define_grid</tt> to actually output the grid HTML code.
|
33
|
+
# Usually used with detached filters: first <tt>define_grid</tt>, then <tt>grid_filter</tt>s, and then
|
34
|
+
# <tt>render_grid</tt>
|
30
35
|
def render_grid(grid)
|
31
36
|
grid.output_buffer.html_safe
|
32
37
|
end
|
33
38
|
|
34
39
|
def mighty_filter_for(grid, options={}, &block)
|
35
40
|
html_options = options[:html] ||= {}
|
36
|
-
html_options
|
37
|
-
html_options[:class] = (['mighty-grid-filter'] + html_options[:class].split(' ')).reject(&:blank?).uniq.join(' ')
|
41
|
+
html_options = MightyGrid::MgHTML.join_html_classes(html_options, 'mighty-grid-filter')
|
38
42
|
html_options[:method] = options.delete(:method) if options.has_key?(:method)
|
39
43
|
html_options[:method] ||= :get
|
40
44
|
|
@@ -46,9 +50,7 @@ module MightyGrid
|
|
46
50
|
|
47
51
|
def header_grid_html(rendering, grid, options)
|
48
52
|
header_tr_html = options[:header_tr_html] || {}
|
49
|
-
header_tr_html
|
50
|
-
header_tr_html_classes = MightyGrid.config.header_tr_class.split(' ')
|
51
|
-
header_tr_html[:class] = (header_tr_html_classes + header_tr_html[:class].split(' ')).reject(&:blank?).uniq.join(' ')
|
53
|
+
header_tr_html = MightyGrid::MgHTML.join_html_classes(header_tr_html, MightyGrid.config.header_tr_class)
|
52
54
|
|
53
55
|
content_tag :thead do
|
54
56
|
content_tag :tr, header_tr_html do
|
@@ -79,7 +81,7 @@ module MightyGrid
|
|
79
81
|
|
80
82
|
def footer_grid_html(rendering, grid)
|
81
83
|
content_tag :tfoot do
|
82
|
-
|
84
|
+
content_tag :tr do
|
83
85
|
content_tag :td, colspan: rendering.total_columns do
|
84
86
|
html_pag = paginate(grid.relation, theme: MightyGrid.config.pagination_theme, param_name: "#{grid.name}[page]")
|
85
87
|
html_pag += content_tag :strong do
|
@@ -87,9 +89,19 @@ module MightyGrid
|
|
87
89
|
end
|
88
90
|
html_pag.html_safe
|
89
91
|
end
|
90
|
-
end
|
92
|
+
end.html_safe
|
93
|
+
end
|
94
|
+
end
|
91
95
|
|
92
|
-
|
96
|
+
def blank_slate_template(rendering)
|
97
|
+
if rendering.blank_slate_handler.present?
|
98
|
+
case rendering.blank_slate_handler
|
99
|
+
when Proc; return rendering.blank_slate_handler.call
|
100
|
+
when String; return rendering.blank_slate_handler
|
101
|
+
when Hash; return render(rendering.blank_slate_handler)
|
102
|
+
end
|
103
|
+
else
|
104
|
+
content_tag :div, 'No records found'
|
93
105
|
end
|
94
106
|
end
|
95
107
|
|
@@ -18,4 +18,16 @@ module MightyGrid
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
module MgHTML
|
23
|
+
class << self
|
24
|
+
def join_html_classes(html_options, *html_classes)
|
25
|
+
html_options[:class] ||= ''
|
26
|
+
html_options[:class] = ([html_options[:class]] + html_classes).reject(&:blank?).map do |h_classes|
|
27
|
+
h_classes.split(' ')
|
28
|
+
end.flatten.uniq.join(' ')
|
29
|
+
html_options
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
21
33
|
end
|
data/lib/mighty_grid/version.rb
CHANGED