will_paginate 2.2.2 → 2.3.11

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

Potentially problematic release.


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

@@ -0,0 +1,110 @@
1
+ == 2.3.6, released 2008-10-26
2
+
3
+ * Rails 2.2 fix: stop using `extract_attribute_names_from_match` inernal AR method, it no longer exists
4
+
5
+ == 2.3.5, released 2008-10-07
6
+
7
+ * update the backported named_scope implementation for Rails versions older than 2.1
8
+ * break out of scope of paginated_each() yielded block when used on named scopes
9
+ * fix paginate(:from)
10
+
11
+ == 2.3.4, released 2008-09-16
12
+
13
+ * Removed gem dependency to Active Support (causes trouble with vendored rails).
14
+ * Rails 2.1: fix a failing test and a deprecation warning.
15
+ * Cope with scoped :select when counting.
16
+
17
+ == 2.3.3, released 2008-08-29
18
+
19
+ * Ensure that paginate_by_sql doesn't change the original SQL query.
20
+ * RDoc love (now live at http://mislav.caboo.se/static/will_paginate/doc/)
21
+ * Rename :prev_label to :previous_label for consistency. old name still functions but is deprecated
22
+ * ActiveRecord 2.1: Remove :include option from count_all query when it's possible.
23
+
24
+ == 2.3.2, released 2008-05-16
25
+
26
+ * Fixed LinkRenderer#stringified_merge by removing "return" from iterator block
27
+ * Ensure that 'href' values in pagination links are escaped URLs
28
+
29
+ == 2.3.1, released 2008-05-04
30
+
31
+ * Fixed page numbers not showing with custom routes and implicit first page
32
+ * Try to use Hanna for documentation (falls back to default RDoc template if not)
33
+
34
+ == 2.3.0, released 2008-04-29
35
+
36
+ * Changed LinkRenderer to receive collection, options and reference to view template NOT in
37
+ constructor, but with the #prepare method. This is a step towards supporting passing of
38
+ LinkRenderer (or subclass) instances that may be preconfigured in some way
39
+ * LinkRenderer now has #page_link and #page_span methods for easier customization of output in
40
+ subclasses
41
+ * Changed page_entries_info() method to adjust its output according to humanized class name of
42
+ collection items. Override this with :entry_name parameter (singular).
43
+
44
+ page_entries_info(@posts)
45
+ #-> "Displaying all 12 posts"
46
+ page_entries_info(@posts, :entry_name => 'item')
47
+ #-> "Displaying all 12 items"
48
+
49
+ == 2.2.3, released 2008-04-26
50
+
51
+ * will_paginate gem is no longer published on RubyForge, but on
52
+ gems.github.com:
53
+
54
+ gem sources -a http://gems.github.com/ (you only need to do this once)
55
+ gem install mislav-will_paginate
56
+
57
+ * extract reusable pagination testing stuff into WillPaginate::View
58
+ * rethink the page URL construction mechanizm to be more bulletproof when
59
+ combined with custom routing for page parameter
60
+ * test that anchor parameter can be used in pagination links
61
+
62
+ == 2.2.2, released 2008-04-21
63
+
64
+ * Add support for page parameter in custom routes like "/foo/page/2"
65
+ * Change output of "page_entries_info" on single-page collection and erraneous
66
+ output with empty collection as reported by Tim Chater
67
+
68
+ == 2.2.1, released 2008-04-08
69
+
70
+ * take less risky path when monkeypatching named_scope; fix that it no longer
71
+ requires ActiveRecord::VERSION
72
+ * use strings in "respond_to?" calls to work around a bug in acts_as_ferret
73
+ stable (ugh)
74
+ * add rake release task
75
+
76
+
77
+ == 2.2.0, released 2008-04-07
78
+
79
+ === API changes
80
+ * Rename WillPaginate::Collection#page_count to "total_pages" for consistency.
81
+ If you implemented this interface, change your implementation accordingly.
82
+ * Remove old, deprecated style of calling Array#paginate as "paginate(page,
83
+ per_page)". If you want to specify :page, :per_page or :total_entries, use a
84
+ parameter hash.
85
+ * Rename LinkRenderer#url_options to "url_for" and drastically optimize it
86
+
87
+ === View changes
88
+ * Added "prev_page" and "next_page" CSS classes on previous/next page buttons
89
+ * Add examples of pagination links styling in "examples/index.html"
90
+ * Change gap in pagination links from "..." to
91
+ "<span class="gap">&hellip;</span>".
92
+ * Add "paginated_section", a block helper that renders pagination both above and
93
+ below content in the block
94
+ * Add rel="prev|next|start" to page links
95
+
96
+ === Other
97
+
98
+ * Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
99
+ WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
100
+ * Support complex page parameters like "developers[page]"
101
+ * Move Array#paginate definition to will_paginate/array.rb. You can now easily
102
+ use pagination on arrays outside of Rails:
103
+
104
+ gem 'will_paginate'
105
+ require 'will_paginate/array'
106
+
107
+ * Add "paginated_each" method for iterating through every record by loading only
108
+ one page of records at the time
109
+ * Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
110
+ default
@@ -11,44 +11,18 @@ can.
11
11
 
12
12
  Some resources to get you started:
13
13
 
14
- * Your mind reels with questions? Join our Google
15
- group[http://groups.google.com/group/will_paginate].
16
- * The will_paginate project page: http://github.com/mislav/will_paginate
17
- * How to report bugs: http://github.com/mislav/will_paginate/wikis/report-bugs
18
- * Ryan Bates made an awesome screencast[http://railscasts.com/episodes/51],
19
- check it out.
20
-
21
- == Installation
22
-
23
- Previously, the plugin was available on the following SVN location:
24
-
25
- svn://errtheblog.com/svn/plugins/will_paginate
26
-
27
- In February 2008, it moved to GitHub to be tracked with git version control.
28
- The SVN repo continued to have updates for some time, but now it doesn't.
29
-
30
- You should switch to using the gem:
31
-
32
- gem install will_paginate
33
-
34
- After that, you can remove the plugin from your application and add
35
- a simple require to the end of config/environment.rb:
36
-
37
- require 'will_paginate'
38
-
39
- That's it, just remember to install the gem on all machines that
40
- you are deploying to.
41
-
42
- <i>There are extensive
43
- installation[http://github.com/mislav/will_paginate/wikis/installation]
44
- instructions on the wiki[http://github.com/mislav/will_paginate/wikis].</i>
14
+ * {Installation instructions}[http://github.com/mislav/will_paginate/wikis/installation]
15
+ on {the wiki}[http://github.com/mislav/will_paginate/wikis]
16
+ * Your mind reels with questions? Join our
17
+ {Google group}[http://groups.google.com/group/will_paginate].
18
+ * {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bugs]
45
19
 
46
20
 
47
21
  == Example usage
48
22
 
49
23
  Use a paginate finder in the controller:
50
24
 
51
- @posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'
25
+ @posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'
52
26
 
53
27
  Yeah, +paginate+ works just like +find+ -- it just doesn't fetch all the
54
28
  records. Don't forget to tell it which page you want, or it will complain!
@@ -57,44 +31,43 @@ Read more on WillPaginate::Finder::ClassMethods.
57
31
  Render the posts in your view like you would normally do. When you need to render
58
32
  pagination, just stick this in:
59
33
 
60
- <%= will_paginate @posts %>
34
+ <%= will_paginate @posts %>
61
35
 
62
- You're done. (Copy and paste the example fancy CSS styles from the bottom.) You
63
- can find the option list at WillPaginate::ViewHelpers.
36
+ You're done. (You can find the option list at WillPaginate::ViewHelpers.)
64
37
 
65
38
  How does it know how much items to fetch per page? It asks your model by calling
66
39
  its <tt>per_page</tt> class method. You can define it like this:
67
40
 
68
- class Post < ActiveRecord::Base
69
- cattr_reader :per_page
70
- @@per_page = 50
71
- end
41
+ class Post < ActiveRecord::Base
42
+ cattr_reader :per_page
43
+ @@per_page = 50
44
+ end
72
45
 
73
46
  ... or like this:
74
47
 
75
- class Post < ActiveRecord::Base
76
- def self.per_page
77
- 50
78
- end
48
+ class Post < ActiveRecord::Base
49
+ def self.per_page
50
+ 50
79
51
  end
52
+ end
80
53
 
81
54
  ... or don't worry about it at all. WillPaginate defines it to be <b>30</b> by default.
82
55
  But you can always specify the count explicitly when calling +paginate+:
83
56
 
84
- @posts = Post.paginate :page => params[:page], :per_page => 50
57
+ @posts = Post.paginate :page => params[:page], :per_page => 50
85
58
 
86
59
  The +paginate+ finder wraps the original finder and returns your resultset that now has
87
60
  some new properties. You can use the collection as you would with any ActiveRecord
88
61
  resultset. WillPaginate view helpers also need that object to be able to render pagination:
89
62
 
90
- <ol>
91
- <% for post in @posts -%>
92
- <li>Render `post` in some nice way.</li>
93
- <% end -%>
94
- </ol>
63
+ <ol>
64
+ <% for post in @posts -%>
65
+ <li>Render `post` in some nice way.</li>
66
+ <% end -%>
67
+ </ol>
95
68
 
96
- <p>Now let's render us some pagination!</p>
97
- <%= will_paginate @posts %>
69
+ <p>Now let's render us some pagination!</p>
70
+ <%= will_paginate @posts %>
98
71
 
99
72
  More detailed documentation:
100
73
 
@@ -114,22 +87,21 @@ contributions or just simply awesome ideas:
114
87
  Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
115
88
  Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
116
89
  van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
117
- Lourens Naudé, Rick Olson, Russell Norris.
90
+ Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris Eppstein,
91
+ Denis Barushev, Ben Pickles.
118
92
 
119
93
 
120
94
  == Usable pagination in the UI
121
95
 
122
96
  There are some CSS styles to get you started in the "examples/" directory. They
123
- are showcased in the <b>"examples/index.html"</b> file.
97
+ are {showcased online here}[http://mislav.caboo.se/static/will_paginate/].
124
98
 
125
99
  More reading about pagination as design pattern:
126
100
 
127
- * Pagination 101:
128
- http://kurafire.net/log/archive/2007/06/22/pagination-101
129
- * Pagination gallery:
130
- http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/
131
- * Pagination on Yahoo Design Pattern Library:
132
- http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination
101
+ * {Pagination 101}[http://kurafire.net/log/archive/2007/06/22/pagination-101]
102
+ * {Pagination gallery}[http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/]
103
+ * {Pagination on Yahoo Design Pattern Library}[http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination]
104
+
105
+ Want to discuss, request features, ask questions? Join the
106
+ {Google group}[http://groups.google.com/group/will_paginate].
133
107
 
134
- Want to discuss, request features, ask questions? Join the Google group:
135
- http://groups.google.com/group/will_paginate
data/Rakefile CHANGED
@@ -1,116 +1,53 @@
1
- require File.dirname(__FILE__) + '/lib/rake_hacks'
1
+ require 'rubygems'
2
+ begin
3
+ hanna_dir = '/Users/mislav/Projects/Hanna/lib'
4
+ $:.unshift hanna_dir if File.exists? hanna_dir
5
+ require 'hanna/rdoctask'
6
+ rescue LoadError
7
+ require 'rake'
8
+ require 'rake/rdoctask'
9
+ end
10
+ load 'test/tasks.rake'
2
11
 
3
12
  desc 'Default: run unit tests.'
4
13
  task :default => :test
5
14
 
6
- desc 'Test the will_paginate plugin.'
7
- Rake::TestTask.new(:test) do |t|
8
- t.pattern = 'test/**/*_test.rb'
9
- t.verbose = true
10
- t.libs << 'test'
11
- end
12
-
13
- for configuration in %w( sqlite3 mysql postgres )
14
- EnvTestTask.new("test_#{configuration}") do |t|
15
- t.pattern = 'test/finder_test.rb'
16
- t.verbose = true
17
- t.env = { 'DB' => configuration }
18
- t.libs << 'test'
19
- end
20
- end
21
-
22
- task :test_databases => %w(test_mysql test_sqlite3 test_postgres)
23
-
24
- desc %{Test everything on SQLite3, MySQL and PostgreSQL}
25
- task :test_full => %w(test test_mysql test_postgres)
26
-
27
- desc %{Test everything with Rails 1.2.x and 2.0.x gems}
28
- task :test_all do
29
- all = Rake::Task['test_full']
30
- ENV['RAILS_VERSION'] = '~>1.2.6'
31
- all.invoke
32
- # reset the invoked flag
33
- %w( test_full test test_mysql test_postgres ).each do |name|
34
- Rake::Task[name].instance_variable_set '@already_invoked', false
35
- end
36
- # do it again
37
- ENV['RAILS_VERSION'] = '~>2.0.2'
38
- all.invoke
39
- end
40
-
41
15
  desc 'Generate RDoc documentation for the will_paginate plugin.'
42
- Rake::RDocTask.new(:doc) do |rdoc|
43
- files = ['README.rdoc', 'LICENSE', 'CHANGELOG']
44
- files << FileList.new('lib/**/*.rb').
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
18
+ include('lib/**/*.rb').
45
19
  exclude('lib/will_paginate/named_scope*').
46
20
  exclude('lib/will_paginate/array.rb').
47
21
  exclude('lib/will_paginate/version.rb')
48
-
49
- rdoc.rdoc_files.add(files)
22
+
50
23
  rdoc.main = "README.rdoc" # page to start on
51
24
  rdoc.title = "will_paginate documentation"
52
25
 
53
- my_template = '/home/mislav/projects/rdoc_template/mislav.rb'
54
- rdoc.template = my_template if File.exists? my_template
55
-
56
26
  rdoc.rdoc_dir = 'doc' # rdoc output folder
57
- rdoc.options << '--inline-source'
58
- rdoc.options << '--charset=UTF-8'
27
+ rdoc.options << '--inline-source' << '--charset=UTF-8'
59
28
  rdoc.options << '--webcvs=http://github.com/mislav/will_paginate/tree/master/'
60
29
  end
61
30
 
31
+ desc %{Update ".manifest" with the latest list of project filenames. Respect\
32
+ .gitignore by excluding everything that git ignores. Update `files` and\
33
+ `test_files` arrays in "*.gemspec" file if it's present.}
62
34
  task :manifest do
63
- list = Dir['**/*']
64
-
65
- File.read('.gitignore').each_line do |glob|
66
- glob = glob.chomp.sub(/^\//, '')
67
- list -= Dir[glob]
68
- list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
69
- puts "excluding #{glob}"
70
- end
71
-
72
- File.open('.manifest', 'w') do |file|
73
- file.write list.sort.join("\n")
35
+ list = `git ls-files --full-name --exclude=*.gemspec --exclude=.*`.chomp.split("\n")
36
+
37
+ if spec_file = Dir['*.gemspec'].first
38
+ spec = File.read spec_file
39
+ spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
40
+ assignment = $1
41
+ bunch = $2 ? list.grep(/^test\//) : list
42
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
43
+ end
44
+
45
+ File.open(spec_file, 'w') { |f| f << spec }
74
46
  end
75
- end
76
-
77
- desc 'Package and upload the release to rubyforge.'
78
- task :release do
79
- require 'yaml'
80
- require 'rubyforge'
81
-
82
- meta = YAML::load open('.gemified')
83
- version = meta[:version]
84
-
85
- v = ENV['VERSION'] or abort "Must supply VERSION=x.y.z"
86
- abort "Version doesn't match #{version}" if v != version
87
-
88
- gem = "#{meta[:name]}-#{version}.gem"
89
- project = meta[:rubyforge_project]
90
-
91
- rf = RubyForge.new
92
- puts "Logging in to RubyForge"
93
- rf.login
94
-
95
- c = rf.userconfig
96
- c['release_notes'] = meta[:summary]
97
- c['release_changes'] = File.read('CHANGELOG').split(/^== .+\n/)[1].strip
98
- c['preformatted'] = true
99
-
100
- puts "Releasing #{meta[:name]} #{version}"
101
- rf.add_release project, project, version, gem
47
+ File.open('.manifest', 'w') { |f| f << list.join("\n") }
102
48
  end
103
49
 
104
50
  task :examples do
105
51
  %x(haml examples/index.haml examples/index.html)
106
52
  %x(sass examples/pagination.sass examples/pagination.css)
107
53
  end
108
-
109
- task :rcov do
110
- excludes = %w( lib/will_paginate/named_scope*
111
- lib/will_paginate/core_ext.rb
112
- lib/will_paginate.rb
113
- rails* )
114
-
115
- system %[rcov -Itest:lib test/*.rb -x #{excludes.join(',')}]
116
- end
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'will_paginate/core_ext'
2
3
 
3
4
  # = You *will* paginate!
4
5
  #
@@ -9,29 +10,29 @@ require 'active_support'
9
10
  # Happy paginating!
10
11
  module WillPaginate
11
12
  class << self
12
- # shortcut for <tt>enable_actionpack; enable_activerecord</tt>
13
+ # shortcut for <tt>enable_actionpack</tt> and <tt>enable_activerecord</tt> combined
13
14
  def enable
14
15
  enable_actionpack
15
16
  enable_activerecord
16
17
  end
17
18
 
18
- # mixes in WillPaginate::ViewHelpers in ActionView::Base
19
+ # hooks WillPaginate::ViewHelpers into ActionView::Base
19
20
  def enable_actionpack
20
- return if ActionView::Base.instance_methods.include? 'will_paginate'
21
+ return if ActionView::Base.instance_methods.include_method? :will_paginate
21
22
  require 'will_paginate/view_helpers'
22
- ActionView::Base.class_eval { include ViewHelpers }
23
+ ActionView::Base.send :include, ViewHelpers
23
24
 
24
25
  if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
25
26
  ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
26
27
  end
27
28
  end
28
29
 
29
- # mixes in WillPaginate::Finder in ActiveRecord::Base and classes that deal
30
+ # hooks WillPaginate::Finder into ActiveRecord::Base and classes that deal
30
31
  # with associations
31
32
  def enable_activerecord
32
33
  return if ActiveRecord::Base.respond_to? :paginate
33
34
  require 'will_paginate/finder'
34
- ActiveRecord::Base.class_eval { include Finder }
35
+ ActiveRecord::Base.send :include, Finder
35
36
 
36
37
  # support pagination on associations
37
38
  a = ActiveRecord::Associations
@@ -41,9 +42,17 @@ module WillPaginate
41
42
  classes << a::HasManyThroughAssociation
42
43
  end
43
44
  }.each do |klass|
44
- klass.class_eval do
45
- include Finder::ClassMethods
46
- alias_method_chain :method_missing, :paginate
45
+ klass.send :include, Finder::ClassMethods
46
+ klass.class_eval { alias_method_chain :method_missing, :paginate }
47
+ end
48
+
49
+ # monkeypatch Rails ticket #2189: "count breaks has_many :through"
50
+ ActiveRecord::Base.class_eval do
51
+ protected
52
+ def self.construct_count_options_from_args(*args)
53
+ result = super
54
+ result[0] = '*' if result[0].is_a?(String) and result[0] =~ /\.\*$/
55
+ result
47
56
  end
48
57
  end
49
58
  end
@@ -61,26 +70,21 @@ module WillPaginate
61
70
  require 'will_paginate/named_scope'
62
71
  require 'will_paginate/named_scope_patch' if patch
63
72
 
64
- ActiveRecord::Base.class_eval do
65
- include WillPaginate::NamedScope
66
- end
73
+ ActiveRecord::Base.send :include, WillPaginate::NamedScope
67
74
  end
68
75
  end
69
76
 
70
- module Deprecation #:nodoc:
77
+ module Deprecation # :nodoc:
71
78
  extend ActiveSupport::Deprecation
72
79
 
73
80
  def self.warn(message, callstack = caller)
74
81
  message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
75
- behavior.call(message, callstack) if behavior && !silenced?
76
- end
77
-
78
- def self.silenced?
79
- ActiveSupport::Deprecation.silenced?
82
+ ActiveSupport::Deprecation.warn(message, callstack)
80
83
  end
81
84
  end
82
85
  end
83
86
 
84
- if defined?(Rails) and defined?(ActiveRecord) and defined?(ActionController)
85
- WillPaginate.enable
87
+ if defined? Rails
88
+ WillPaginate.enable_activerecord if defined? ActiveRecord
89
+ WillPaginate.enable_actionpack if defined? ActionController
86
90
  end