data_table 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,72 +1,73 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- data_table (0.2.0)
4
+ data_table (0.2.7)
5
5
  rails (~> 3.0.0)
6
- will_paginate (~> 3.0.pre2)
7
6
 
8
7
  GEM
9
8
  remote: http://rubygems.org/
10
9
  specs:
11
10
  abstract (1.0.0)
12
- actionmailer (3.0.5)
13
- actionpack (= 3.0.5)
14
- mail (~> 2.2.15)
15
- actionpack (3.0.5)
16
- activemodel (= 3.0.5)
17
- activesupport (= 3.0.5)
11
+ actionmailer (3.0.10)
12
+ actionpack (= 3.0.10)
13
+ mail (~> 2.2.19)
14
+ actionpack (3.0.10)
15
+ activemodel (= 3.0.10)
16
+ activesupport (= 3.0.10)
18
17
  builder (~> 2.1.2)
19
18
  erubis (~> 2.6.6)
20
- i18n (~> 0.4)
19
+ i18n (~> 0.5.0)
21
20
  rack (~> 1.2.1)
22
- rack-mount (~> 0.6.13)
21
+ rack-mount (~> 0.6.14)
23
22
  rack-test (~> 0.5.7)
24
23
  tzinfo (~> 0.3.23)
25
- activemodel (3.0.5)
26
- activesupport (= 3.0.5)
24
+ activemodel (3.0.10)
25
+ activesupport (= 3.0.10)
27
26
  builder (~> 2.1.2)
28
- i18n (~> 0.4)
29
- activerecord (3.0.5)
30
- activemodel (= 3.0.5)
31
- activesupport (= 3.0.5)
32
- arel (~> 2.0.2)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.10)
29
+ activemodel (= 3.0.10)
30
+ activesupport (= 3.0.10)
31
+ arel (~> 2.0.10)
33
32
  tzinfo (~> 0.3.23)
34
- activeresource (3.0.5)
35
- activemodel (= 3.0.5)
36
- activesupport (= 3.0.5)
37
- activesupport (3.0.5)
38
- arel (2.0.9)
33
+ activeresource (3.0.10)
34
+ activemodel (= 3.0.10)
35
+ activesupport (= 3.0.10)
36
+ activesupport (3.0.10)
37
+ arel (2.0.10)
39
38
  builder (2.1.2)
40
39
  diff-lcs (1.1.2)
41
40
  erubis (2.6.6)
42
41
  abstract (>= 1.0.0)
43
42
  i18n (0.5.0)
44
- mail (2.2.17)
43
+ mail (2.2.19)
45
44
  activesupport (>= 2.3.6)
46
45
  i18n (>= 0.4.0)
47
46
  mime-types (~> 1.16)
48
47
  treetop (~> 1.4.8)
49
48
  mime-types (1.16)
50
- polyglot (0.3.1)
51
- rack (1.2.2)
52
- rack-mount (0.6.13)
49
+ polyglot (0.3.2)
50
+ rack (1.2.3)
51
+ rack-mount (0.6.14)
53
52
  rack (>= 1.0.0)
54
53
  rack-test (0.5.7)
55
54
  rack (>= 1.0)
56
- rails (3.0.5)
57
- actionmailer (= 3.0.5)
58
- actionpack (= 3.0.5)
59
- activerecord (= 3.0.5)
60
- activeresource (= 3.0.5)
61
- activesupport (= 3.0.5)
55
+ rails (3.0.10)
56
+ actionmailer (= 3.0.10)
57
+ actionpack (= 3.0.10)
58
+ activerecord (= 3.0.10)
59
+ activeresource (= 3.0.10)
60
+ activesupport (= 3.0.10)
62
61
  bundler (~> 1.0)
63
- railties (= 3.0.5)
64
- railties (3.0.5)
65
- actionpack (= 3.0.5)
66
- activesupport (= 3.0.5)
62
+ railties (= 3.0.10)
63
+ railties (3.0.10)
64
+ actionpack (= 3.0.10)
65
+ activesupport (= 3.0.10)
67
66
  rake (>= 0.8.7)
67
+ rdoc (~> 3.4)
68
68
  thor (~> 0.14.4)
69
- rake (0.8.7)
69
+ rake (0.9.2)
70
+ rdoc (3.9.4)
70
71
  rr (1.0.0)
71
72
  rspec (2.0.1)
72
73
  rspec-core (~> 2.0.1)
@@ -80,10 +81,10 @@ GEM
80
81
  rspec-expectations (~> 2.0.1)
81
82
  shoulda (2.11.3)
82
83
  thor (0.14.6)
83
- treetop (1.4.9)
84
+ treetop (1.4.10)
85
+ polyglot
84
86
  polyglot (>= 0.3.1)
85
- tzinfo (0.3.26)
86
- will_paginate (3.0.pre2)
87
+ tzinfo (0.3.29)
87
88
 
88
89
  PLATFORMS
89
90
  ruby
data/README.rdoc CHANGED
@@ -47,6 +47,14 @@ in your view (assuming HAML):
47
47
 
48
48
  %tbody
49
49
 
50
+ and in your Gemfile
51
+
52
+ # for ActiveRecord
53
+ gem "will_paginate"
54
+
55
+ # for Mongoid
56
+ gem "kaminari"
57
+
50
58
  == Advanced Features
51
59
 
52
60
  === Date fields
data/data_table.gemspec CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_dependency "rails", "~>3.0.0"
22
- s.add_dependency "will_paginate", "3.0.pre2"
23
22
 
24
23
  s.add_development_dependency "rspec", "~>2.0.0"
25
24
  s.add_development_dependency "shoulda", "~>2.11.0"
@@ -12,10 +12,11 @@ module DataTable
12
12
  block = (explicit_block or implicit_block)
13
13
 
14
14
  objects = _find_objects params, fields, search_fields
15
+ matching_count = objects.respond_to?(:total_entries) ? objects.total_entries : _matching_count(params, search_fields)
15
16
 
16
17
  {:sEcho => params[:sEcho].to_i,
17
18
  :iTotalRecords => self.count,
18
- :iTotalDisplayRecords => objects.total_entries,
19
+ :iTotalDisplayRecords => matching_count,
19
20
  :aaData => _yield_and_render_array(controller, objects, block)
20
21
  }.to_json.html_safe
21
22
  end
@@ -4,8 +4,12 @@ module DataTable
4
4
  def _find_objects params, fields, search_fields
5
5
  self.where(_where_conditions params[:sSearch], search_fields).
6
6
  order_by(_order_by_fields params, fields).
7
- limit(_per_page params).
8
- paginate :page => _page(params), :per_page => _per_page(params)
7
+ page(_page params).
8
+ per(_per_page params)
9
+ end
10
+
11
+ def _matching_count params, search_fields
12
+ self.where(_where_conditions params[:sSearch], search_fields).count
9
13
  end
10
14
 
11
15
  def _where_conditions raw_query, search_fields
@@ -1,3 +1,3 @@
1
1
  module DataTable
2
- VERSION = "0.2.7"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -32,6 +32,27 @@ describe DataTable do
32
32
  result.should == {:sEcho => 1, :iTotalRecords => 42, :iTotalDisplayRecords => 10, :aaData => :results}.to_json.html_safe
33
33
  end
34
34
 
35
+ # won't work because of ruby 1.9.2 bug... https://gist.github.com/455547
36
+ # it "should work with a pagination library that doesn't respond to #total_entries" do
37
+ # params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => "10", :sEcho => "1"}
38
+ # controller = mock!.params { params }.subject
39
+ #
40
+ # fields = %w(foo bar baz)
41
+ # search_fields = %w(foo bar)
42
+ #
43
+ # mock(self).count { 42 }
44
+ # mock(self)._matching_count(params, search_fields) { 10 }
45
+ # mock(self)._find_objects(params, fields, search_fields) { :objects }
46
+ # mock(self)._yield_and_render_array(controller, :objects, :block) { :results }
47
+ #
48
+ # result = for_data_table(controller, fields, search_fields, :block)
49
+ # result.should == {:sEcho => 1, :iTotalRecords => 42, :iTotalDisplayRecords => 10, :aaData => :results}.to_json.html_safe
50
+ # end
51
+
52
+ end
53
+
54
+ context "#_yield_and_render_array" do
55
+
35
56
  end
36
57
 
37
58
  context "#_yield_and_render_array" do
@@ -12,8 +12,8 @@ describe DataTable do
12
12
  mock(self)._order_by_fields(params, %w(foo bar baz)) { "order by" }
13
13
 
14
14
  mock(self)._page(params) { :page }
15
- mock(self)._per_page(params) { :per_page }.twice
16
- mock(self).where("where clause") { mock!.order_by("order by") { mock!.limit(:per_page) { mock!.paginate({:page => :page, :per_page => :per_page}) { :answer } } } }
15
+ mock(self)._per_page(params) { :per_page }
16
+ mock(self).where("where clause") { mock!.order_by("order by") { mock!.page(:page) { mock!.per(:per_page) { :answer } } } }
17
17
 
18
18
  _find_objects(params, %w(foo bar baz), %w(foo bar)).should == :answer
19
19
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: data_table
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.7
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Dew
@@ -24,50 +24,39 @@ dependencies:
24
24
  version: 3.0.0
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: will_paginate
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
33
- - - "="
34
- - !ruby/object:Gem::Version
35
- version: 3.0.pre2
36
- type: :runtime
37
- version_requirements: *id002
38
27
  - !ruby/object:Gem::Dependency
39
28
  name: rspec
40
29
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
30
+ requirement: &id002 !ruby/object:Gem::Requirement
42
31
  none: false
43
32
  requirements:
44
33
  - - ~>
45
34
  - !ruby/object:Gem::Version
46
35
  version: 2.0.0
47
36
  type: :development
48
- version_requirements: *id003
37
+ version_requirements: *id002
49
38
  - !ruby/object:Gem::Dependency
50
39
  name: shoulda
51
40
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
41
+ requirement: &id003 !ruby/object:Gem::Requirement
53
42
  none: false
54
43
  requirements:
55
44
  - - ~>
56
45
  - !ruby/object:Gem::Version
57
46
  version: 2.11.0
58
47
  type: :development
59
- version_requirements: *id004
48
+ version_requirements: *id003
60
49
  - !ruby/object:Gem::Dependency
61
50
  name: rr
62
51
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
52
+ requirement: &id004 !ruby/object:Gem::Requirement
64
53
  none: false
65
54
  requirements:
66
55
  - - ~>
67
56
  - !ruby/object:Gem::Version
68
57
  version: 1.0.0
69
58
  type: :development
70
- version_requirements: *id005
59
+ version_requirements: *id004
71
60
  description: Simple data preparation from AR/Mongoid to the jQuery DataTables plugin
72
61
  email:
73
62
  - jason.dew@gmail.com