will_mostly_paginate 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,143 @@
1
+ = 2.4.2, released 2011-02-11
2
+
3
+ * fork will_paginate as will_mostly_paginate, adding the 'page_all' option to calls to 'paginate'
4
+
5
+ = 2.3.12, released 2009-12-01
6
+
7
+ * make view helpers "HTML safe" for Rails 2.3.5 with rails_xss plugin
8
+
9
+ = 2.3.11, released 2009-06-02
10
+
11
+ * fix `enable_actionpack`
12
+
13
+ = 2.3.10, released 2009-05-21
14
+
15
+ * count_by_sql: don't use table alias with any adapters starting with "oracle"
16
+ * Add back "AS count_table" alias to `paginate_by_sql` counter SQL
17
+
18
+ = 2.3.9, released 2009-05-29
19
+
20
+ * remove "AS count_table" alias from `paginate_by_sql` counter SQL
21
+ * Rails 2.3.2 compat: monkeypatch Rails issue #2189 (count breaks has_many :through)
22
+ * fix generation of page URLs that contain the "@" character
23
+ * check for method existance in a ruby 1.8- and 1.9-compatible way
24
+ * load will_paginate view helpers even if ActiveRecord is not loaded
25
+
26
+ == 2.3.8, released 2009-03-09
27
+
28
+ * Rails 2.3 compat: query parameter parsing with Rack
29
+
30
+ == 2.3.7, released 2009-02-09
31
+
32
+ * Removed all unnecessary &block variables since they cause serious memory damage and lots of subsequent gc runs.
33
+
34
+ == 2.3.6, released 2008-10-26
35
+
36
+ * Rails 2.2 fix: stop using `extract_attribute_names_from_match` inernal AR method, it no longer exists
37
+
38
+ == 2.3.5, released 2008-10-07
39
+
40
+ * update the backported named_scope implementation for Rails versions older than 2.1
41
+ * break out of scope of paginated_each() yielded block when used on named scopes
42
+ * fix paginate(:from)
43
+
44
+ == 2.3.4, released 2008-09-16
45
+
46
+ * Removed gem dependency to Active Support (causes trouble with vendored rails).
47
+ * Rails 2.1: fix a failing test and a deprecation warning.
48
+ * Cope with scoped :select when counting.
49
+
50
+ == 2.3.3, released 2008-08-29
51
+
52
+ * Ensure that paginate_by_sql doesn't change the original SQL query.
53
+ * RDoc love (now live at http://gitrdoc.com/mislav/will_paginate/tree/master)
54
+ * Rename :prev_label to :previous_label for consistency. old name still functions but is deprecated
55
+ * ActiveRecord 2.1: Remove :include option from count_all query when it's possible.
56
+
57
+ == 2.3.2, released 2008-05-16
58
+
59
+ * Fixed LinkRenderer#stringified_merge by removing "return" from iterator block
60
+ * Ensure that 'href' values in pagination links are escaped URLs
61
+
62
+ == 2.3.1, released 2008-05-04
63
+
64
+ * Fixed page numbers not showing with custom routes and implicit first page
65
+ * Try to use Hanna for documentation (falls back to default RDoc template if not)
66
+
67
+ == 2.3.0, released 2008-04-29
68
+
69
+ * Changed LinkRenderer to receive collection, options and reference to view template NOT in
70
+ constructor, but with the #prepare method. This is a step towards supporting passing of
71
+ LinkRenderer (or subclass) instances that may be preconfigured in some way
72
+ * LinkRenderer now has #page_link and #page_span methods for easier customization of output in
73
+ subclasses
74
+ * Changed page_entries_info() method to adjust its output according to humanized class name of
75
+ collection items. Override this with :entry_name parameter (singular).
76
+
77
+ page_entries_info(@posts)
78
+ #-> "Displaying all 12 posts"
79
+ page_entries_info(@posts, :entry_name => 'item')
80
+ #-> "Displaying all 12 items"
81
+
82
+ == 2.2.3, released 2008-04-26
83
+
84
+ * will_paginate gem is no longer published on RubyForge, but on
85
+ gems.github.com:
86
+
87
+ gem sources -a http://gems.github.com/ (you only need to do this once)
88
+ gem install mislav-will_paginate
89
+
90
+ * extract reusable pagination testing stuff into WillPaginate::View
91
+ * rethink the page URL construction mechanizm to be more bulletproof when
92
+ combined with custom routing for page parameter
93
+ * test that anchor parameter can be used in pagination links
94
+
95
+ == 2.2.2, released 2008-04-21
96
+
97
+ * Add support for page parameter in custom routes like "/foo/page/2"
98
+ * Change output of "page_entries_info" on single-page collection and erraneous
99
+ output with empty collection as reported by Tim Chater
100
+
101
+ == 2.2.1, released 2008-04-08
102
+
103
+ * take less risky path when monkeypatching named_scope; fix that it no longer
104
+ requires ActiveRecord::VERSION
105
+ * use strings in "respond_to?" calls to work around a bug in acts_as_ferret
106
+ stable (ugh)
107
+ * add rake release task
108
+
109
+
110
+ == 2.2.0, released 2008-04-07
111
+
112
+ === API changes
113
+ * Rename WillPaginate::Collection#page_count to "total_pages" for consistency.
114
+ If you implemented this interface, change your implementation accordingly.
115
+ * Remove old, deprecated style of calling Array#paginate as "paginate(page,
116
+ per_page)". If you want to specify :page, :per_page or :total_entries, use a
117
+ parameter hash.
118
+ * Rename LinkRenderer#url_options to "url_for" and drastically optimize it
119
+
120
+ === View changes
121
+ * Added "prev_page" and "next_page" CSS classes on previous/next page buttons
122
+ * Add examples of pagination links styling in "examples/index.html"
123
+ * Change gap in pagination links from "..." to
124
+ "<span class="gap">&hellip;</span>".
125
+ * Add "paginated_section", a block helper that renders pagination both above and
126
+ below content in the block
127
+ * Add rel="prev|next|start" to page links
128
+
129
+ === Other
130
+
131
+ * Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
132
+ WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
133
+ * Support complex page parameters like "developers[page]"
134
+ * Move Array#paginate definition to will_paginate/array.rb. You can now easily
135
+ use pagination on arrays outside of Rails:
136
+
137
+ gem 'will_paginate'
138
+ require 'will_paginate/array'
139
+
140
+ * Add "paginated_each" method for iterating through every record by loading only
141
+ one page of records at the time
142
+ * Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
143
+ default
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007 PJ Hyett and Mislav Marohnić, (c) 2011 Joshua Ballanco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,126 @@
1
+ = Will*Mostly*Paginate
2
+
3
+ {WillPaginate}[https://github.com/mislav/will_paginate/wiki/] is a great utility, but there's one small issue: what if you don't
4
+ need all the pages right now? For each model that you paginate with WillPaginate, the number of requests is roughly doubled just so
5
+ that WillPaginate can figure out how many page links to show. Most of the time, this isn't a problem. Sometimes, though, you want to
6
+ paginate requests that take a long time, and that extra request can really hurt. For those times, there's WillMostlyPaginate.
7
+
8
+ The only API difference is the addition of a +page_all+ option to the +paginate+ method. The class names are all the same, so this
9
+ should be a drop in replacement for all your existing pagination. What follows is the original WillPaginate documentation, modified
10
+ slightly with this in mind...
11
+
12
+
13
+ = WillPaginate
14
+
15
+ Pagination is just limiting the number of records displayed. Why should you let
16
+ it get in your way while developing, then? This plugin makes magic happen. Did
17
+ you ever want to be able to do just this on a model:
18
+
19
+ Post.paginate :page => 1, :order => 'created_at DESC'
20
+
21
+ ... and then render the page links with a single view helper? Well, now you
22
+ can.
23
+
24
+ Some resources to get you started:
25
+
26
+ * {Installation instructions}[http://github.com/mislav/will_paginate/wikis/installation]
27
+ on {the wiki}[http://github.com/mislav/will_paginate/wikis]
28
+ * Your mind reels with questions? Join our
29
+ {Google group}[http://groups.google.com/group/will_paginate].
30
+ * {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bugs]
31
+
32
+
33
+ == Example usage
34
+
35
+ Use a paginate finder in the controller:
36
+
37
+ @posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'
38
+
39
+ Yeah, +paginate+ works just like +find+ -- it just doesn't fetch all the
40
+ records. Don't forget to tell it which page you want, or it will complain!
41
+ Read more on WillPaginate::Finder::ClassMethods.
42
+
43
+ Render the posts in your view like you would normally do. When you need to render
44
+ pagination, just stick this in:
45
+
46
+ <%= will_paginate @posts %>
47
+
48
+ You're done. (You can find the option list at WillPaginate::ViewHelpers.)
49
+
50
+ How does it know how much items to fetch per page? It asks your model by calling
51
+ its <tt>per_page</tt> class method. You can define it like this:
52
+
53
+ class Post < ActiveRecord::Base
54
+ cattr_reader :per_page
55
+ @@per_page = 50
56
+ end
57
+
58
+ ... or like this:
59
+
60
+ class Post < ActiveRecord::Base
61
+ def self.per_page
62
+ 50
63
+ end
64
+ end
65
+
66
+ ... or don't worry about it at all. WillPaginate defines it to be <b>30</b> by default.
67
+ But you can always specify the count explicitly when calling +paginate+:
68
+
69
+ @posts = Post.paginate :page => params[:page], :per_page => 50
70
+
71
+ ... what if you don't need to know how many total pages there are? Save time and SQL
72
+ queries by passing the +page_all+ option:
73
+
74
+ @posts = Post.paginate :page => params[:page], :page_all => false
75
+
76
+ If you don't pass this option, it defaults to +true+, so you still get the traditional WillPaginate behavior.
77
+
78
+ The +paginate+ finder wraps the original finder and returns your resultset that now has
79
+ some new properties. You can use the collection as you would with any ActiveRecord
80
+ resultset. WillPaginate view helpers also need that object to be able to render pagination:
81
+
82
+ <ol>
83
+ <% for post in @posts -%>
84
+ <li>Render `post` in some nice way.</li>
85
+ <% end -%>
86
+ </ol>
87
+
88
+ <p>Now let's render us some pagination!</p>
89
+ <%= will_paginate @posts %>
90
+
91
+ More detailed documentation:
92
+
93
+ * WillPaginate::Finder::ClassMethods for pagination on your models;
94
+ * WillPaginate::ViewHelpers for your views.
95
+
96
+
97
+ == Authors and credits
98
+
99
+ Authors:: Mislav Marohnić, PJ Hyett
100
+ Original announcement:: http://errtheblog.com/post/929
101
+ Original PHP source:: http://www.strangerstudios.com/sandbox/pagination/diggstyle.php
102
+
103
+ All these people helped making will_paginate what it is now with their code
104
+ contributions or just simply awesome ideas:
105
+
106
+ Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
107
+ Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
108
+ van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
109
+ Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris Eppstein,
110
+ Denis Barushev, Ben Pickles.
111
+
112
+
113
+ == Usable pagination in the UI
114
+
115
+ There are some CSS styles to get you started in the "examples/" directory. They
116
+ are {showcased online here}[http://mislav.uniqpath.com/will_paginate/].
117
+
118
+ More reading about pagination as design pattern:
119
+
120
+ * {Pagination 101}[http://kurafire.net/log/archive/2007/06/22/pagination-101]
121
+ * {Pagination gallery}[http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/]
122
+ * {Pagination on Yahoo Design Pattern Library}[http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination]
123
+
124
+ Want to discuss, request features, ask questions? Join the
125
+ {Google group}[http://groups.google.com/group/will_paginate].
126
+
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ begin
4
+ require 'yard'
5
+ require 'yard/rake/yardoc_task'
6
+ YARD::Rake::YardocTask.new do |t|
7
+ t.files = Dir['lib/**/*.rb'] - %w| lib/will_paginate/named_scope.rb
8
+ lib/will_pagenate/named_scope_patch.rb
9
+ lib/will_paginate/array.rb
10
+ lib/will_paginate/version.rb |
11
+ end
12
+ rescue LoadError
13
+ require 'rake/rdoctask'
14
+ desc 'Generate RDoc documentation for the will_paginate plugin.'
15
+ Rake::RDocTask.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
17
+ include('lib/**/*.rb').
18
+ exclude('lib/will_paginate/named_scope*').
19
+ exclude('lib/will_paginate/array.rb').
20
+ exclude('lib/will_paginate/version.rb')
21
+
22
+ rdoc.main = "README.rdoc" # page to start on
23
+ rdoc.title = "will_paginate documentation"
24
+
25
+ rdoc.rdoc_dir = 'doc' # rdoc output folder
26
+ rdoc.options << '--inline-source' << '--charset=UTF-8'
27
+ end
28
+ end
29
+
30
+ load 'test/tasks.rake'
31
+
32
+ desc 'Default: run unit tests.'
33
+ task :default => :test
34
+
35
+ desc %{Update ".manifest" with the latest list of project filenames. Respect\
36
+ .gitignore by excluding everything that git ignores. Update `files` and\
37
+ `test_files` arrays in "*.gemspec" file if it's present.}
38
+ task :manifest do
39
+ list = `git ls-files --full-name --exclude=*.gemspec --exclude=.*`.chomp.split("\n")
40
+
41
+ if spec_file = Dir['*.gemspec'].first
42
+ spec = File.read spec_file
43
+ spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
44
+ assignment = $1
45
+ bunch = $2 ? list.grep(/^test\//) : list
46
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
47
+ end
48
+
49
+ File.open(spec_file, 'w') { |f| f << spec }
50
+ end
51
+ File.open('.manifest', 'w') { |f| f << list.join("\n") }
52
+ end
53
+
54
+ task :examples do
55
+ %x(haml examples/index.haml examples/index.html)
56
+ %x(sass examples/pagination.sass examples/pagination.css)
57
+ end
@@ -0,0 +1,90 @@
1
+ require 'active_support'
2
+ require 'will_mostly_paginate/core_ext'
3
+
4
+ # = You *will* paginate!
5
+ #
6
+ # First read about WillPaginate::Finder::ClassMethods, then see
7
+ # WillPaginate::ViewHelpers. The magical array you're handling in-between is
8
+ # WillPaginate::Collection.
9
+ #
10
+ # Happy paginating!
11
+ module WillPaginate
12
+ class << self
13
+ # shortcut for <tt>enable_actionpack</tt> and <tt>enable_activerecord</tt> combined
14
+ def enable
15
+ enable_actionpack
16
+ enable_activerecord
17
+ end
18
+
19
+ # hooks WillPaginate::ViewHelpers into ActionView::Base
20
+ def enable_actionpack
21
+ return if ActionView::Base.instance_methods.include_method? :will_paginate
22
+ require 'will_mostly_paginate/view_helpers'
23
+ ActionView::Base.send :include, ViewHelpers
24
+
25
+ if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
26
+ ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
27
+ end
28
+ end
29
+
30
+ # hooks WillPaginate::Finder into ActiveRecord::Base and classes that deal
31
+ # with associations
32
+ def enable_activerecord
33
+ return if ActiveRecord::Base.respond_to? :paginate
34
+ require 'will_mostly_paginate/finder'
35
+ ActiveRecord::Base.send :include, Finder
36
+
37
+ # support pagination on associations
38
+ a = ActiveRecord::Associations
39
+ [ a::AssociationCollection ].tap { |classes|
40
+ # detect http://dev.rubyonrails.org/changeset/9230
41
+ unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
42
+ classes << a::HasManyThroughAssociation
43
+ end
44
+ }.each do |klass|
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
56
+ end
57
+ end
58
+ end
59
+
60
+ # Enable named_scope, a feature of Rails 2.1, even if you have older Rails
61
+ # (tested on Rails 2.0.2 and 1.2.6).
62
+ #
63
+ # You can pass +false+ for +patch+ parameter to skip monkeypatching
64
+ # *associations*. Use this if you feel that <tt>named_scope</tt> broke
65
+ # has_many, has_many :through or has_and_belongs_to_many associations in
66
+ # your app. By passing +false+, you can still use <tt>named_scope</tt> in
67
+ # your models, but not through associations.
68
+ def enable_named_scope(patch = true)
69
+ return if defined? ActiveRecord::NamedScope
70
+ require 'will_mostly_paginate/named_scope'
71
+ require 'will_mostly_paginate/named_scope_patch' if patch
72
+
73
+ ActiveRecord::Base.send :include, WillPaginate::NamedScope
74
+ end
75
+ end
76
+
77
+ module Deprecation # :nodoc:
78
+ extend ActiveSupport::Deprecation
79
+
80
+ def self.warn(message, callstack = caller)
81
+ message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
82
+ ActiveSupport::Deprecation.warn(message, callstack)
83
+ end
84
+ end
85
+ end
86
+
87
+ if defined? Rails
88
+ WillPaginate.enable_activerecord if defined? ActiveRecord
89
+ WillPaginate.enable_actionpack if defined? ActionController
90
+ end
@@ -0,0 +1,16 @@
1
+ require 'will_mostly_paginate/collection'
2
+
3
+ Array.class_eval do
4
+ def paginate(options = {})
5
+ raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options
6
+
7
+ WillPaginate::Collection.create(
8
+ options[:page] || 1,
9
+ options[:per_page] || 30,
10
+ options[:total_entries] || self.length,
11
+ options.keys.include?(:page_all) ? options[:page_all] : true
12
+ ) { |pager|
13
+ pager.replace self[pager.offset, pager.per_page].to_a
14
+ }
15
+ end
16
+ end