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 CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datagrid}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
@@ -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} #{datagrid_filter_class(filter.class)}"
11
- self.send(:"datagrid_#{filter.class.to_s.underscore.split('/').last}", filter, options)
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) ? object.class.filter_by_name(attribute_or_filter) : attribute_or_filter
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 datagrid_filter_class(klass)
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
 
@@ -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
 
@@ -20,7 +20,7 @@ class IncludeDom
20
20
  end
21
21
 
22
22
  def failure_message
23
- "Expected dom #{@matcher} to include #{@expectation}, but it wasn't"
23
+ "Expected dom #{@matcher.inspect} to include #{@expectation.inspect}, but it wasn't"
24
24
  end
25
25
  end
26
26
 
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev