kaminari 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kaminari might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ doc
7
+ log
data/CHANGELOG CHANGED
@@ -1,3 +1,24 @@
1
+ == 0.12.0
2
+
3
+ * General configuration options #41 #62 [javierv, iain]
4
+ You can now globally override some default values such as default_per_page,
5
+ window, etc. via configuration file.
6
+ Also, here comes a generator command that generates the default
7
+ configuration file into your app's config/initilizers directory.
8
+
9
+ * Generic pagination support for Array object #47 #68 #74 [lda ened jianlin]
10
+ You can now paginate through any kind of Arrayish object in this way:
11
+ Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
12
+
13
+ * Fixed a serious performance regression in 0.11.0 [ankane]
14
+ There was a critical performance issue on #count method in 0.11.0 gem.
15
+
16
+ * Bugfix: Pass the real @params to url_for #90 [utkarshkukreti]
17
+
18
+ * Fixed a gem packaging problem (circular dependency)
19
+ There was a packaging problem with Kaminari 0.11.0 that the gem depends on
20
+ Kaminari gem. Maybe Jeweler + "gemspec" method didn't work well...
21
+
1
22
  == 0.11.0
2
23
 
3
24
  This release contains several backward incompatibilities on template API.
data/Gemfile CHANGED
@@ -1 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kaminari.gemspec
1
4
  gemspec
@@ -43,6 +43,7 @@ Put this line in your Gemfile:
43
43
  Then bundle:
44
44
  % bundle
45
45
 
46
+
46
47
  == Usage
47
48
 
48
49
  === Query Basics
@@ -58,6 +59,19 @@ Then bundle:
58
59
  User.page(7).per(50)
59
60
  Note that the +per+ scope is not directly defined on the models but is just a method defined on the page scope. This is absolutely reasonable because you will never actually use +per_page+ without specifying the +page+ number.
60
61
 
62
+ === General configuration options
63
+
64
+ You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method.
65
+ default_per_page # 25 by default
66
+ window # 4 by default
67
+ outer_window # 0 by default
68
+ left # 0 by default
69
+ right # 0 by default
70
+
71
+ There's a handy generator that generates the default configuration file into config/initilizers directory.
72
+ Run the following generator command, then edit the generated file.
73
+ % rails g kaminari:config
74
+
61
75
  === Configuring default +per_page+ value for each model
62
76
 
63
77
  * +paginates_per+
@@ -90,24 +104,24 @@ Then bundle:
90
104
  <%= paginate @users, :window => 2 %>
91
105
  This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
92
106
 
93
- * specifing the "outer window" size (1 by default)
107
+ * specifing the "outer window" size (0 by default)
94
108
 
95
109
  <%= paginate @users, :outer_window => 3 %>
96
110
  This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
97
111
 
98
- * outer window can be separetely specified by +left+, +right+ (1 by default)
112
+ * outer window can be separetely specified by +left+, +right+ (0 by default)
99
113
 
100
- <%= paginate @users, :left => 0, :right => 2 %>
114
+ <%= paginate @users, :left => 1, :right => 3 %>
101
115
  This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
102
116
 
103
117
  * changing the parameter name (:+param_name+) for the links
104
118
 
105
- <%= paginate @users, :param_name => :pagina
119
+ <%= paginate @users, :param_name => :pagina %>
106
120
  This would modify the query parameter name on each links.
107
121
 
108
122
  * extra parameters (:+params+) for the links
109
123
 
110
- <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'}
124
+ <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'} %>
111
125
  This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
112
126
 
113
127
  * Ajax links (crazy simple, but works perfectly!)
@@ -159,25 +173,33 @@ Kaminari includes a handy template generator.
159
173
  * multiple themes
160
174
 
161
175
  To utilize multiple themes from within a single application, create a directory within the app/views/kaminari/ and move your custom template files into that directory.
162
- rails g kaminari:views default (skip if you have existing kaminari views)
163
- cd app/views/kaminari
164
- mkdir my_custom_theme
165
- cp _*.html.* my_custom_theme/
166
-
176
+ % rails g kaminari:views default (skip if you have existing kaminari views)
177
+ % cd app/views/kaminari
178
+ % mkdir my_custom_theme
179
+ % cp _*.html.* my_custom_theme/
180
+
167
181
  Next reference that directory when calling the paginate method:
168
182
 
169
- % paginate @users, :theme => 'my_custom_theme'
183
+ <%= paginate @users, :theme => 'my_custom_theme' %>
170
184
 
171
185
  Customize away!
172
186
 
173
187
  Note: if the theme isn't present or none is specified, kaminari will default back to the views included within the gem.
174
188
 
189
+ === Paginating a generic Array object
190
+
191
+ Kaminari provides an Array wrapper class that adapts a generic Array object to the <tt>paginate</tt> view helper.
192
+ However, the <tt>paginate</tt> helper doesn't automatically handle your Array object (this is an intensional design).
193
+ <tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
194
+ Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
195
+
175
196
 
176
197
  == For more information
177
198
 
178
199
  Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniques.
179
200
  https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
180
201
 
202
+
181
203
  == Questions, Feedback
182
204
 
183
205
  Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇ :)
data/Rakefile CHANGED
@@ -1,42 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'rubygems'
4
3
  require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "kaminari"
18
- gem.homepage = "http://github.com/amatsuda/kaminari"
19
- gem.license = "MIT"
20
- gem.summary = 'A pagination engine plugin for Rails 3'
21
- gem.description = 'Kaminari is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3'
22
- gem.email = "ronnie@dio.jp"
23
- gem.authors = ["Akira Matsuda"]
24
- # Include your dependencies below. Runtime dependencies are required when using your gem,
25
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
- gem.add_development_dependency 'rails', '>= 3.0.0'
27
- gem.add_development_dependency 'bundler', '>= 1.0.0'
28
- gem.add_development_dependency 'sqlite3'
29
- gem.add_development_dependency 'mongoid', '>= 2'
30
- gem.add_development_dependency 'rspec'
31
- gem.add_development_dependency 'rspec-rails'
32
- gem.add_development_dependency 'rr'
33
- gem.add_development_dependency 'steak'
34
- gem.add_development_dependency 'capybara'
35
- gem.add_development_dependency 'database_cleaner'
36
- gem.add_development_dependency 'rcov'
37
- gem.add_development_dependency 'jeweler'
38
- end
39
- Jeweler::RubygemsDotOrgTasks.new
4
+ Bundler::GemHelper.install_tasks
40
5
 
41
6
  require 'rspec/core'
42
7
  require 'rspec/core/rake_task'
@@ -44,23 +9,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
44
9
  spec.pattern = FileList['spec/**/*_spec.rb']
45
10
  end
46
11
 
47
- RSpec::Core::RakeTask.new(:rcov) do |spec|
48
- spec.pattern = 'spec/**/*_spec.rb'
49
- spec.rcov = true
50
- end
51
-
52
12
  task :default => :spec
53
13
 
54
14
  require 'rake/rdoctask'
55
15
  Rake::RDocTask.new do |rdoc|
56
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
16
+ require 'kaminari/version'
57
17
 
58
18
  rdoc.rdoc_dir = 'rdoc'
59
- rdoc.title = "kaminari #{version}"
19
+ rdoc.title = "kaminari #{Kaminari::VERSION}"
60
20
  rdoc.rdoc_files.include('README*')
61
21
  rdoc.rdoc_files.include('lib/**/*.rb')
62
22
  end
63
-
64
- task :test do
65
- Rake::Task[:spec].invoke
66
- end
@@ -1,181 +1,34 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kaminari/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{kaminari}
8
- s.version = "0.11.0"
6
+ s.name = 'kaminari'
7
+ s.version = Kaminari::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Akira Matsuda']
10
+ s.email = ['ronnie@dio.jp']
11
+ s.homepage = 'https://github.com/amatsuda/kaminari'
12
+ s.summary = 'A pagination engine plugin for Rails 3'
13
+ s.description = 'Kaminari is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3'
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Akira Matsuda"]
12
- s.date = %q{2011-04-19}
13
- s.description = %q{Kaminari is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3}
14
- s.email = %q{ronnie@dio.jp}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gemtest",
22
- ".rspec",
23
- "CHANGELOG",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.rdoc",
28
- "Rakefile",
29
- "VERSION",
30
- "app/views/kaminari/_first_page.html.erb",
31
- "app/views/kaminari/_first_page.html.haml",
32
- "app/views/kaminari/_gap.html.erb",
33
- "app/views/kaminari/_gap.html.haml",
34
- "app/views/kaminari/_last_page.html.erb",
35
- "app/views/kaminari/_last_page.html.haml",
36
- "app/views/kaminari/_next_page.html.erb",
37
- "app/views/kaminari/_next_page.html.haml",
38
- "app/views/kaminari/_page.html.erb",
39
- "app/views/kaminari/_page.html.haml",
40
- "app/views/kaminari/_paginator.html.erb",
41
- "app/views/kaminari/_paginator.html.haml",
42
- "app/views/kaminari/_prev_page.html.erb",
43
- "app/views/kaminari/_prev_page.html.haml",
44
- "config/locales/kaminari.yml",
45
- "kaminari.gemspec",
46
- "lib/generators/kaminari/views_generator.rb",
47
- "lib/kaminari.rb",
48
- "lib/kaminari/engine.rb",
49
- "lib/kaminari/helpers/action_view_extension.rb",
50
- "lib/kaminari/helpers/paginator.rb",
51
- "lib/kaminari/helpers/tags.rb",
52
- "lib/kaminari/models/active_record_extension.rb",
53
- "lib/kaminari/models/active_record_relation_methods.rb",
54
- "lib/kaminari/models/configuration_methods.rb",
55
- "lib/kaminari/models/mongoid_criteria_methods.rb",
56
- "lib/kaminari/models/mongoid_extension.rb",
57
- "lib/kaminari/models/page_scope_methods.rb",
58
- "lib/kaminari/railtie.rb",
59
- "lib/kaminari/version.rb",
60
- "spec/acceptance/acceptance_helper.rb",
61
- "spec/acceptance/support/helpers.rb",
62
- "spec/acceptance/support/paths.rb",
63
- "spec/acceptance/users_spec.rb",
64
- "spec/fake_app.rb",
65
- "spec/helpers/helpers_spec.rb",
66
- "spec/helpers/tags_spec.rb",
67
- "spec/models/active_record_relation_methods_spec.rb",
68
- "spec/models/default_per_page_spec.rb",
69
- "spec/models/mongoid_spec.rb",
70
- "spec/models/scopes_spec.rb",
71
- "spec/spec_helper.rb",
72
- "spec/support/database_cleaner.rb",
73
- "spec/support/matchers.rb"
74
- ]
75
- s.homepage = %q{http://github.com/amatsuda/kaminari}
76
- s.licenses = ["MIT"]
77
- s.require_paths = ["lib"]
78
- s.rubygems_version = %q{1.7.2}
79
- s.summary = %q{A pagination engine plugin for Rails 3}
80
- s.test_files = [
81
- "spec/acceptance/acceptance_helper.rb",
82
- "spec/acceptance/support/helpers.rb",
83
- "spec/acceptance/support/paths.rb",
84
- "spec/acceptance/users_spec.rb",
85
- "spec/fake_app.rb",
86
- "spec/helpers/helpers_spec.rb",
87
- "spec/helpers/tags_spec.rb",
88
- "spec/models/active_record_relation_methods_spec.rb",
89
- "spec/models/default_per_page_spec.rb",
90
- "spec/models/mongoid_spec.rb",
91
- "spec/models/scopes_spec.rb",
92
- "spec/spec_helper.rb",
93
- "spec/support/database_cleaner.rb",
94
- "spec/support/matchers.rb"
95
- ]
15
+ s.rubyforge_project = 'kaminari'
96
16
 
97
- if s.respond_to? :specification_version then
98
- s.specification_version = 3
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.extra_rdoc_files = ['README.rdoc']
20
+ s.require_paths = ['lib']
99
21
 
100
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
101
- s.add_runtime_dependency(%q<kaminari>, [">= 0"])
102
- s.add_development_dependency(%q<rails>, [">= 3.0.0"])
103
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
104
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
105
- s.add_development_dependency(%q<mongoid>, [">= 2"])
106
- s.add_development_dependency(%q<rspec>, [">= 0"])
107
- s.add_development_dependency(%q<rspec-rails>, [">= 0"])
108
- s.add_development_dependency(%q<rr>, [">= 0"])
109
- s.add_development_dependency(%q<steak>, [">= 0"])
110
- s.add_development_dependency(%q<capybara>, [">= 0"])
111
- s.add_development_dependency(%q<database_cleaner>, [">= 0"])
112
- s.add_development_dependency(%q<rcov>, [">= 0"])
113
- s.add_development_dependency(%q<jeweler>, [">= 0"])
114
- s.add_development_dependency(%q<rails>, [">= 3.0.0"])
115
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
116
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
117
- s.add_development_dependency(%q<mongoid>, [">= 2"])
118
- s.add_development_dependency(%q<rspec>, [">= 0"])
119
- s.add_development_dependency(%q<rspec-rails>, [">= 0"])
120
- s.add_development_dependency(%q<rr>, [">= 0"])
121
- s.add_development_dependency(%q<steak>, [">= 0"])
122
- s.add_development_dependency(%q<capybara>, [">= 0"])
123
- s.add_development_dependency(%q<database_cleaner>, [">= 0"])
124
- s.add_development_dependency(%q<rcov>, [">= 0"])
125
- s.add_development_dependency(%q<jeweler>, [">= 0"])
126
- else
127
- s.add_dependency(%q<kaminari>, [">= 0"])
128
- s.add_dependency(%q<rails>, [">= 3.0.0"])
129
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
130
- s.add_dependency(%q<sqlite3>, [">= 0"])
131
- s.add_dependency(%q<mongoid>, [">= 2"])
132
- s.add_dependency(%q<rspec>, [">= 0"])
133
- s.add_dependency(%q<rspec-rails>, [">= 0"])
134
- s.add_dependency(%q<rr>, [">= 0"])
135
- s.add_dependency(%q<steak>, [">= 0"])
136
- s.add_dependency(%q<capybara>, [">= 0"])
137
- s.add_dependency(%q<database_cleaner>, [">= 0"])
138
- s.add_dependency(%q<rcov>, [">= 0"])
139
- s.add_dependency(%q<jeweler>, [">= 0"])
140
- s.add_dependency(%q<rails>, [">= 3.0.0"])
141
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
142
- s.add_dependency(%q<sqlite3>, [">= 0"])
143
- s.add_dependency(%q<mongoid>, [">= 2"])
144
- s.add_dependency(%q<rspec>, [">= 0"])
145
- s.add_dependency(%q<rspec-rails>, [">= 0"])
146
- s.add_dependency(%q<rr>, [">= 0"])
147
- s.add_dependency(%q<steak>, [">= 0"])
148
- s.add_dependency(%q<capybara>, [">= 0"])
149
- s.add_dependency(%q<database_cleaner>, [">= 0"])
150
- s.add_dependency(%q<rcov>, [">= 0"])
151
- s.add_dependency(%q<jeweler>, [">= 0"])
152
- end
153
- else
154
- s.add_dependency(%q<kaminari>, [">= 0"])
155
- s.add_dependency(%q<rails>, [">= 3.0.0"])
156
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
157
- s.add_dependency(%q<sqlite3>, [">= 0"])
158
- s.add_dependency(%q<mongoid>, [">= 2"])
159
- s.add_dependency(%q<rspec>, [">= 0"])
160
- s.add_dependency(%q<rspec-rails>, [">= 0"])
161
- s.add_dependency(%q<rr>, [">= 0"])
162
- s.add_dependency(%q<steak>, [">= 0"])
163
- s.add_dependency(%q<capybara>, [">= 0"])
164
- s.add_dependency(%q<database_cleaner>, [">= 0"])
165
- s.add_dependency(%q<rcov>, [">= 0"])
166
- s.add_dependency(%q<jeweler>, [">= 0"])
167
- s.add_dependency(%q<rails>, [">= 3.0.0"])
168
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
169
- s.add_dependency(%q<sqlite3>, [">= 0"])
170
- s.add_dependency(%q<mongoid>, [">= 2"])
171
- s.add_dependency(%q<rspec>, [">= 0"])
172
- s.add_dependency(%q<rspec-rails>, [">= 0"])
173
- s.add_dependency(%q<rr>, [">= 0"])
174
- s.add_dependency(%q<steak>, [">= 0"])
175
- s.add_dependency(%q<capybara>, [">= 0"])
176
- s.add_dependency(%q<database_cleaner>, [">= 0"])
177
- s.add_dependency(%q<rcov>, [">= 0"])
178
- s.add_dependency(%q<jeweler>, [">= 0"])
179
- end
180
- end
22
+ s.licenses = ['MIT']
181
23
 
24
+ s.add_dependency 'rails', ['>= 3.0.0']
25
+ s.add_development_dependency 'bundler', ['>= 1.0.0']
26
+ s.add_development_dependency 'sqlite3', ['>= 0']
27
+ s.add_development_dependency 'mongoid', ['>= 2']
28
+ s.add_development_dependency 'rspec', ['>= 0']
29
+ s.add_development_dependency 'rspec-rails', ['>= 0']
30
+ s.add_development_dependency 'rr', ['>= 0']
31
+ s.add_development_dependency 'steak', ['>= 0']
32
+ s.add_development_dependency 'capybara', ['>= 0']
33
+ s.add_development_dependency 'database_cleaner', ['>= 0']
34
+ end
@@ -0,0 +1,16 @@
1
+ module Kaminari
2
+ module Generators
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ desc <<DESC
7
+ Description:
8
+ Copies Kaminari configuration file to your application's initializer directory.
9
+ DESC
10
+
11
+ def copy_config_file
12
+ template 'kaminari_config.rb', 'config/initializers/kaminari_config.rb'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ Kaminari.configure do |config|
2
+ # config.default_per_page = 25
3
+ # config.window = 4
4
+ # config.outer_window = 0
5
+ # config.left = 0
6
+ # config.right = 0
7
+ end
@@ -1,3 +1,2 @@
1
- require File.join(File.dirname(__FILE__), 'kaminari/version')
2
1
  require File.join(File.dirname(__FILE__), 'kaminari/railtie')
3
2
  require File.join(File.dirname(__FILE__), 'kaminari/engine')
@@ -0,0 +1,35 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Kaminari
4
+ # Configures global settings for Kaminari
5
+ # Kaminari.configure do |config|
6
+ # config.default_per_page = 10
7
+ # end
8
+ def self.configure(&block)
9
+ yield @config ||= Kaminari::Configuration.new
10
+ end
11
+
12
+ # Global settings for Kaminari
13
+ def self.config
14
+ @config
15
+ end
16
+
17
+ # need a Class for 3.0
18
+ class Configuration #:nodoc:
19
+ include ActiveSupport::Configurable
20
+ config_accessor :default_per_page
21
+ config_accessor :window
22
+ config_accessor :outer_window
23
+ config_accessor :left
24
+ config_accessor :right
25
+ end
26
+
27
+ # this is ugly. why can't we pass the default value to config_accessor...?
28
+ configure do |config|
29
+ config.default_per_page = 25
30
+ config.window = 4
31
+ config.outer_window = 0
32
+ config.left = 0
33
+ config.right = 0
34
+ end
35
+ end