datagrid 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/datagrid.gemspec +1 -1
- data/lib/datagrid/core.rb +11 -0
- data/lib/datagrid/form_builder.rb +21 -4
- data/lib/datagrid/helper.rb +2 -2
- data/spec/datagrid/form_builder_spec.rb +8 -0
- data/spec/support/equal_to_dom.rb +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/datagrid.gemspec
CHANGED
data/lib/datagrid/core.rb
CHANGED
@@ -44,6 +44,11 @@ module Datagrid
|
|
44
44
|
self.to_s.underscore.split('/').last
|
45
45
|
end
|
46
46
|
|
47
|
+
# Required for ActionView form builder
|
48
|
+
def model_name
|
49
|
+
self.param_name
|
50
|
+
end
|
51
|
+
|
47
52
|
protected
|
48
53
|
def check_scope_defined!(message = "Scope not defined")
|
49
54
|
raise(Datagrid::ConfigurationError, message) unless @scope
|
@@ -100,9 +105,15 @@ module Datagrid
|
|
100
105
|
self.class.param_name
|
101
106
|
end
|
102
107
|
|
108
|
+
# Required for ActionView form builder
|
103
109
|
def to_key
|
104
110
|
[self.class.param_name]
|
105
111
|
end
|
112
|
+
|
113
|
+
# Required for ActionView form builder
|
114
|
+
def persisted?
|
115
|
+
false
|
116
|
+
end
|
106
117
|
|
107
118
|
protected
|
108
119
|
|
@@ -7,8 +7,13 @@ module Datagrid
|
|
7
7
|
filter = get_filter(filter_or_attribute)
|
8
8
|
options[:class] ||= ""
|
9
9
|
options[:class] += " " unless options[:class].blank?
|
10
|
-
options[:class] += "#{filter.name} #{
|
11
|
-
self.send(
|
10
|
+
options[:class] += "#{filter.name} #{datagrid_html_class(filter.class)}"
|
11
|
+
self.send(datagrid_filter_method(filter), filter, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def datagrid_label(filter_or_attribute, options = {})
|
15
|
+
filter = get_filter(filter_or_attribute)
|
16
|
+
self.label(filter.name, filter.header, options = {})
|
12
17
|
end
|
13
18
|
|
14
19
|
protected
|
@@ -43,12 +48,24 @@ module Datagrid
|
|
43
48
|
end
|
44
49
|
|
45
50
|
def get_filter(attribute_or_filter)
|
46
|
-
attribute_or_filter.is_a?(Symbol)
|
51
|
+
if attribute_or_filter.is_a?(Symbol)
|
52
|
+
object.class.filter_by_name(attribute_or_filter) ||
|
53
|
+
raise(Error, "filter #{attribute_or_filter} not found")
|
54
|
+
else
|
55
|
+
attribute_or_filter
|
56
|
+
end
|
47
57
|
end
|
48
58
|
|
49
|
-
def
|
59
|
+
def datagrid_html_class(klass)
|
50
60
|
klass.to_s.split("::").last.underscore
|
51
61
|
end
|
62
|
+
|
63
|
+
def datagrid_filter_method(filter)
|
64
|
+
:"datagrid_#{filter.class.to_s.underscore.split('/').last}"
|
65
|
+
end
|
66
|
+
|
67
|
+
class Error < StandardError
|
68
|
+
end
|
52
69
|
end
|
53
70
|
end
|
54
71
|
|
data/lib/datagrid/helper.rb
CHANGED
@@ -30,11 +30,11 @@ module Datagrid
|
|
30
30
|
|
31
31
|
protected
|
32
32
|
|
33
|
-
def datagrid_header(grid, options)
|
33
|
+
def datagrid_header(grid, options = {})
|
34
34
|
header = empty_string
|
35
35
|
grid.columns.each do |column|
|
36
36
|
data = _safe(column.header)
|
37
|
-
if column.order
|
37
|
+
if options[:order] && column.order
|
38
38
|
data << datagrid_order_for(grid, column)
|
39
39
|
end
|
40
40
|
header << content_tag(:th, data)
|
@@ -61,6 +61,14 @@ describe Datagrid::FormBuilder do
|
|
61
61
|
)}
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
describe ".datagrid_label" do
|
66
|
+
it "should generate label for filter" do
|
67
|
+
view.datagrid_label(:name).should equal_to_dom(
|
68
|
+
'<label for="report_name">Name</label>'
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
64
72
|
end
|
65
73
|
|
66
74
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|