simple_datatables 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,111 +1,106 @@
1
- PATH
2
- remote: .
3
- specs:
4
- simple_datatables (0.1)
5
- meta_search
6
- rails (~> 3.1.0.rc5)
7
- will_paginate (~> 3.0.pre2)
8
-
9
- PATH
10
- remote: jsonify-rails
11
- specs:
12
- jsonify-rails (0.0.6)
13
- actionpack (~> 3.1.0.rc4)
14
- jsonify
15
-
16
- GEM
17
- remote: http://rubygems.org/
18
- specs:
19
- actionmailer (3.1.0.rc5)
20
- actionpack (= 3.1.0.rc5)
21
- mail (~> 2.3.0)
22
- actionpack (3.1.0.rc5)
23
- activemodel (= 3.1.0.rc5)
24
- activesupport (= 3.1.0.rc5)
25
- builder (~> 3.0.0)
26
- erubis (~> 2.7.0)
27
- i18n (~> 0.6)
28
- rack (~> 1.3.1)
29
- rack-cache (~> 1.0.2)
30
- rack-mount (~> 0.8.1)
31
- rack-test (~> 0.6.0)
32
- sprockets (~> 2.0.0.beta.12)
33
- activemodel (3.1.0.rc5)
34
- activesupport (= 3.1.0.rc5)
35
- bcrypt-ruby (~> 2.1.4)
36
- builder (~> 3.0.0)
37
- i18n (~> 0.6)
38
- activerecord (3.1.0.rc5)
39
- activemodel (= 3.1.0.rc5)
40
- activesupport (= 3.1.0.rc5)
41
- arel (~> 2.1.4)
42
- tzinfo (~> 0.3.29)
43
- activeresource (3.1.0.rc5)
44
- activemodel (= 3.1.0.rc5)
45
- activesupport (= 3.1.0.rc5)
46
- activesupport (3.1.0.rc5)
47
- multi_json (~> 1.0)
48
- arel (2.1.4)
49
- bcrypt-ruby (2.1.4-x86-mingw32)
50
- builder (3.0.0)
51
- erubis (2.7.0)
52
- hike (1.2.0)
53
- i18n (0.6.0)
54
- jsonify (0.1.0)
55
- mail (2.3.0)
56
- i18n (>= 0.4.0)
57
- mime-types (~> 1.16)
58
- treetop (~> 1.4.8)
59
- meta_search (0.5.4)
60
- actionpack (>= 3.0.0.beta4)
61
- activerecord (>= 3.0.0.beta4)
62
- activesupport (>= 3.0.0.beta4)
63
- arel (>= 0.4.0)
64
- mime-types (1.16)
65
- multi_json (1.0.3)
66
- polyglot (0.3.2)
67
- rack (1.3.2)
68
- rack-cache (1.0.2)
69
- rack (>= 0.4)
70
- rack-mount (0.8.1)
71
- rack (>= 1.0.0)
72
- rack-ssl (1.3.2)
73
- rack
74
- rack-test (0.6.1)
75
- rack (>= 1.0)
76
- rails (3.1.0.rc5)
77
- actionmailer (= 3.1.0.rc5)
78
- actionpack (= 3.1.0.rc5)
79
- activerecord (= 3.1.0.rc5)
80
- activeresource (= 3.1.0.rc5)
81
- activesupport (= 3.1.0.rc5)
82
- bundler (~> 1.0)
83
- railties (= 3.1.0.rc5)
84
- railties (3.1.0.rc5)
85
- actionpack (= 3.1.0.rc5)
86
- activesupport (= 3.1.0.rc5)
87
- rack-ssl (~> 1.3.2)
88
- rake (>= 0.8.7)
89
- rdoc (~> 3.4)
90
- thor (~> 0.14.6)
91
- rake (0.9.2)
92
- rdoc (3.9.1)
93
- sprockets (2.0.0.beta.13)
94
- hike (~> 1.2)
95
- rack (~> 1.0)
96
- tilt (~> 1.1, != 1.3.0)
97
- thor (0.14.6)
98
- tilt (1.3.2)
99
- treetop (1.4.10)
100
- polyglot
101
- polyglot (>= 0.3.1)
102
- tzinfo (0.3.29)
103
- will_paginate (3.0.pre4)
104
-
105
- PLATFORMS
106
- ruby
107
- x86-mingw32
108
-
109
- DEPENDENCIES
110
- jsonify-rails!
111
- simple_datatables!
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_datatables (0.2.1)
5
+ jsonify-rails
6
+ meta_search (~> 1.1.0)
7
+ rails (~> 3.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionmailer (3.2.6)
13
+ actionpack (= 3.2.6)
14
+ mail (~> 2.4.4)
15
+ actionpack (3.2.6)
16
+ activemodel (= 3.2.6)
17
+ activesupport (= 3.2.6)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ journey (~> 1.0.1)
21
+ rack (~> 1.4.0)
22
+ rack-cache (~> 1.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.1.3)
25
+ activemodel (3.2.6)
26
+ activesupport (= 3.2.6)
27
+ builder (~> 3.0.0)
28
+ activerecord (3.2.6)
29
+ activemodel (= 3.2.6)
30
+ activesupport (= 3.2.6)
31
+ arel (~> 3.0.2)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.2.6)
34
+ activemodel (= 3.2.6)
35
+ activesupport (= 3.2.6)
36
+ activesupport (3.2.6)
37
+ i18n (~> 0.6)
38
+ multi_json (~> 1.0)
39
+ arel (3.0.2)
40
+ builder (3.0.0)
41
+ erubis (2.7.0)
42
+ hike (1.2.1)
43
+ i18n (0.6.0)
44
+ journey (1.0.4)
45
+ json (1.7.3)
46
+ jsonify (0.3.1)
47
+ multi_json (~> 1.0)
48
+ jsonify-rails (0.3.2)
49
+ actionpack
50
+ jsonify (< 0.4.0)
51
+ mail (2.4.4)
52
+ i18n (>= 0.4.0)
53
+ mime-types (~> 1.16)
54
+ treetop (~> 1.4.8)
55
+ meta_search (1.1.3)
56
+ actionpack (~> 3.1)
57
+ activerecord (~> 3.1)
58
+ activesupport (~> 3.1)
59
+ polyamorous (~> 0.5.0)
60
+ mime-types (1.19)
61
+ multi_json (1.3.6)
62
+ polyamorous (0.5.0)
63
+ activerecord (~> 3.0)
64
+ polyglot (0.3.3)
65
+ rack (1.4.1)
66
+ rack-cache (1.2)
67
+ rack (>= 0.4)
68
+ rack-ssl (1.3.2)
69
+ rack
70
+ rack-test (0.6.1)
71
+ rack (>= 1.0)
72
+ rails (3.2.6)
73
+ actionmailer (= 3.2.6)
74
+ actionpack (= 3.2.6)
75
+ activerecord (= 3.2.6)
76
+ activeresource (= 3.2.6)
77
+ activesupport (= 3.2.6)
78
+ bundler (~> 1.0)
79
+ railties (= 3.2.6)
80
+ railties (3.2.6)
81
+ actionpack (= 3.2.6)
82
+ activesupport (= 3.2.6)
83
+ rack-ssl (~> 1.3.2)
84
+ rake (>= 0.8.7)
85
+ rdoc (~> 3.4)
86
+ thor (>= 0.14.6, < 2.0)
87
+ rake (0.9.2.2)
88
+ rdoc (3.12)
89
+ json (~> 1.4)
90
+ sprockets (2.1.3)
91
+ hike (~> 1.2)
92
+ rack (~> 1.0)
93
+ tilt (~> 1.1, != 1.3.0)
94
+ thor (0.15.4)
95
+ tilt (1.3.3)
96
+ treetop (1.4.10)
97
+ polyglot
98
+ polyglot (>= 0.3.1)
99
+ tzinfo (0.3.33)
100
+
101
+ PLATFORMS
102
+ ruby
103
+ x86-mingw32
104
+
105
+ DEPENDENCIES
106
+ simple_datatables!
@@ -1,6 +1,6 @@
1
1
  = Simple Datatables
2
2
 
3
- Connects two awesome plugins - Datatables for Jquery and Meta Search together for Rails 3.1
3
+ Connects two awesome plugins - Datatables for Jquery and Meta Search together for Rails 3
4
4
 
5
5
  == Install
6
6
 
@@ -8,7 +8,7 @@ Add the following to your Gemfile to install simple datatables:
8
8
 
9
9
  gem 'simple_datatables'
10
10
 
11
- After bundle install add this line to rails 3.1 assets pipeline and restart server:
11
+ After bundle install add this line to rails assets pipeline and restart server:
12
12
 
13
13
  //= require simple_datatables
14
14
 
@@ -40,27 +40,33 @@ Use standard datatables initializer options for creating table:
40
40
  * fnServerData: point to simpleDatatables function
41
41
  * aoColumns: you *should* define all searchable/fiterable sName attributes here. Use format as used in meta_search (with underscores)
42
42
 
43
- Create Jsonify view with column values for columns listed in aoColumns. See example for clarification.
43
+ Create Jsonify view with column values for columns listed in aoColumns. View should be written in Jsonify style and should have *.jsonify file extension in order to work properly. See example and Jsonify docs for more details.
44
+
45
+ == Dependencies
44
46
 
45
47
  This gem uses:
46
48
  * meta_search for nice search and sort request syntax mapping
47
49
  * jsonify for simple output generation
48
50
 
49
51
  This gem provides integration with:
50
- * will_paginate for nice pagination request syntax mapping
52
+ * will_paginate for nice pagination request syntax mapping (not bundled)
51
53
 
52
- Gem works only with rails 3.1.
54
+ Gem works only with rails 3.1 and higher.
53
55
 
54
56
  Gem includes datatables library and fnSetFilteringDelay plugin so you haven't include it by yourself.
55
57
 
58
+ Gem does not include any CSS files. Please use styles from datatables website examples.
59
+
56
60
  == Pagination
57
61
 
58
- Simple_datatables is compatible with will_paginate. Datatables will provide you "page" and "per_page" request params.
62
+ Simple_datatables is compatible with will_paginate. In order to provide choise freedom you should add will_paginate to your project by yourself. Datatables will provide you "page" and "per_page" request params.
59
63
 
60
64
  If you do not use pagination do not forget to save search result to some variable with meta_search relation method:
61
65
 
62
66
  @products = Product.search(params[:search]).relation
63
67
 
68
+ Your can use any other paginator. See below for the details.
69
+
64
70
  == Search for all fields
65
71
 
66
72
  Note that fulltext search will work only with text fields due to meta_search restrictions. To prevent errors use bSearchable: false for non-text columns in aoColumns field.
@@ -79,19 +85,30 @@ Independent fields search will always search using "starts_with" finder.
79
85
 
80
86
  If you are getting strange results (for instance, iTotalRecords and iTotalDisplayRecords both equal 0, or entirely the wrong collection is used), you might want to specify which collection to use:
81
87
 
82
- respond_with @products, :locals => {:collection => @products}
88
+ @collection = @products
89
+ respond_with @products
83
90
 
84
91
  Also if you are using own or uncommon implementation of pagination you may use direct page count variables setting as follows:
85
92
 
86
- respond_with @products, :locals => {:total_entries => 12, :current_page_entries => 10}
93
+ @total_entries = 12
94
+ @current_page_entries = 10
95
+ respond_with @products
87
96
 
88
- In this case gem will not try to find collection or pagination and will use the counters passed via locals.
97
+ In this case gem will not try to find collection or pagination and will use the counters passed via variables.
89
98
 
90
99
  == Example
91
100
 
92
101
  The following code will show products list datatables. Manufacturer is belongs_to association for Product.
93
102
 
94
- In your controller:
103
+ First of all add to your routes.rb datatables search api method:
104
+
105
+ resources :products do
106
+ collection do
107
+ get :search
108
+ end
109
+ end
110
+
111
+ Then implement it in your controller:
95
112
 
96
113
  respond_to :html, :datatables
97
114
 
@@ -101,13 +118,13 @@ In your controller:
101
118
  respond_with @products
102
119
  end
103
120
 
104
- In your search view (app/views/products/search.jsonify):
121
+ In your search view (app/views/products/search.jsonify) implement output fields order:
105
122
 
106
123
  @products.each do |product|
107
124
  json << [product.name, product.manufacturer.name]
108
125
  end
109
126
 
110
- In your index view:
127
+ In your index view make a table with header (HAML):
111
128
 
112
129
  %table#products
113
130
  %thead
@@ -117,8 +134,7 @@ In your index view:
117
134
 
118
135
  %tbody
119
136
 
120
-
121
- In your javascript:
137
+ In your javascript add the following code to initialize the datatables (be sure to do it after document load):
122
138
 
123
139
  $("#products").dataTable({
124
140
  "sAjaxSource" : "/products/search.datatables",
@@ -133,4 +149,4 @@ In your javascript:
133
149
 
134
150
  == Copyright
135
151
 
136
- Copyright (c) Grigory Dmitrenko, 2011. See LICENSE for details.
152
+ Copyright (c) Grigory Dmitrenko, 2012. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
- require "bundler"
1
+ require 'rspec/core/rake_task'
2
2
 
3
- Bundler::GemHelper.install_tasks
3
+ task :default => :spec
4
+
5
+ desc 'Run ALL OF the specs'
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ # t.ruby_opts = '-w'
8
+ end
@@ -1,36 +1,36 @@
1
- total_entries ||= nil
2
- current_page_entries ||= 0
3
- collection ||= nil
1
+ @total_entries ||= nil
2
+ @current_page_entries ||= 0
3
+ @collection ||= nil
4
4
 
5
5
  # Looking for object with pagination if pages count not set
6
- if total_entries.nil? and current_page_entries==0
6
+ if @total_entries.nil? and @current_page_entries==0
7
7
 
8
8
  # looking for the right collection if not initiated via parameter
9
- if collection.nil?
9
+ if @collection.nil?
10
10
  instance_variables.each do |vn|
11
11
  v = instance_variable_get(vn)
12
12
 
13
13
  # if a collection variable was specified, use it only
14
- next if collection && collection != v
14
+ next if @collection && @collection != v
15
15
  next if v.class.name.nil?
16
16
 
17
- collection = v if v.class.name.start_with?("MetaSearch::Searches", "ActiveRecord::Relation", "Mongoid::Criteria")
17
+ @collection = v if v.class.name.start_with?("MetaSearch::Searches", "ActiveRecord::Relation", "Mongoid::Criteria")
18
18
  end
19
19
  end
20
20
 
21
21
  # receiving correct current page entries count
22
- current_page_entries = collection.size if collection.respond_to?('size')
22
+ @current_page_entries = @collection.size if @collection.respond_to?('size')
23
23
 
24
24
  # looking for the total entries count
25
- total_entries = collection.length if collection.class.name.start_with?("Mongoid::Criteria")
26
- total_entries = collection.total_entries if collection.respond_to?('total_entries')
25
+ @total_entries = @collection.length if @collection.class.name.start_with?("Mongoid::Criteria")
26
+ @total_entries = @collection.total_entries if @collection.respond_to?('total_entries')
27
27
 
28
28
  # fallback to 1 page if total entries count not found
29
- total_entries = current_page_entries if total_entries.nil?
29
+ @total_entries = @current_page_entries if @total_entries.nil?
30
30
  end
31
31
 
32
- json.iTotalRecords current_page_entries
33
- json.iTotalDisplayRecords total_entries
32
+ json.iTotalRecords @current_page_entries
33
+ json.iTotalDisplayRecords @total_entries
34
34
  json.sEcho params["sEcho"].to_i
35
35
  json.aaData do
36
36
  json.ingest! yield
@@ -1,3 +1,3 @@
1
1
  module SimpleDatatables
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,24 +1,24 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require "simple_datatables/version"
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "simple_datatables"
6
- s.version = SimpleDatatables::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["Grigory"]
9
- s.email = ["grigory@snsk.ru"]
10
- s.homepage = "http://github.com/gryphon/simple_datatables"
11
- s.summary = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
12
- s.description = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
13
-
14
- s.rubyforge_project = "data_table"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
19
-
20
- s.add_dependency "rails", "~> 3.1.0"
21
- s.add_dependency "meta_search", '~> 1.1.0'
22
- s.add_dependency "jsonify-rails"
23
-
24
- end
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "simple_datatables/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "simple_datatables"
6
+ s.version = SimpleDatatables::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Grigory"]
9
+ s.email = ["grigory@snsk.ru"]
10
+ s.homepage = "http://github.com/gryphon/simple_datatables"
11
+ s.summary = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
12
+ s.description = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
13
+
14
+ s.rubyforge_project = "data_table"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "rails", "~> 3.1"
21
+ s.add_dependency "meta_search", '~> 1.1.0'
22
+ s.add_dependency "jsonify-rails"
23
+
24
+ end