will_paginate 2.3.16 → 3.0.pre
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.
- data/CHANGELOG.rdoc +24 -80
- data/LICENSE +1 -1
- data/README.rdoc +125 -0
- data/Rakefile +26 -22
- data/lib/will_paginate/array.rb +25 -8
- data/lib/will_paginate/collection.rb +15 -28
- data/lib/will_paginate/core_ext.rb +26 -0
- data/lib/will_paginate/deprecation.rb +50 -0
- data/lib/will_paginate/finders/active_record.rb +158 -0
- data/lib/will_paginate/finders/active_resource.rb +51 -0
- data/lib/will_paginate/finders/base.rb +112 -0
- data/lib/will_paginate/finders/data_mapper.rb +30 -0
- data/lib/will_paginate/finders/sequel.rb +23 -0
- data/lib/will_paginate/finders.rb +9 -0
- data/lib/will_paginate/railtie.rb +26 -0
- data/lib/will_paginate/version.rb +5 -5
- data/lib/will_paginate/view_helpers/action_view.rb +142 -0
- data/lib/will_paginate/view_helpers/base.rb +126 -0
- data/lib/will_paginate/view_helpers/link_renderer.rb +130 -0
- data/lib/will_paginate/view_helpers/link_renderer_base.rb +83 -0
- data/lib/will_paginate/view_helpers/merb.rb +13 -0
- data/lib/will_paginate/view_helpers.rb +25 -436
- data/lib/will_paginate.rb +10 -84
- data/spec/collection_spec.rb +147 -0
- data/spec/console +8 -0
- data/spec/console_fixtures.rb +8 -0
- data/spec/database.yml +22 -0
- data/spec/finders/active_record_spec.rb +377 -0
- data/spec/finders/active_resource_spec.rb +52 -0
- data/spec/finders/activerecord_test_connector.rb +114 -0
- data/spec/finders/data_mapper_spec.rb +62 -0
- data/spec/finders/data_mapper_test_connector.rb +20 -0
- data/spec/finders/sequel_spec.rb +53 -0
- data/spec/finders/sequel_test_connector.rb +9 -0
- data/spec/finders_spec.rb +76 -0
- data/{test → spec}/fixtures/developer.rb +2 -3
- data/{test → spec}/fixtures/project.rb +2 -6
- data/{test → spec}/fixtures/projects.yml +1 -1
- data/{test → spec}/fixtures/reply.rb +1 -1
- data/spec/fixtures/topic.rb +7 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/tasks.rake +60 -0
- data/spec/view_helpers/action_view_spec.rb +345 -0
- data/spec/view_helpers/base_spec.rb +64 -0
- data/spec/view_helpers/link_renderer_base_spec.rb +84 -0
- data/spec/view_helpers/view_example_group.rb +103 -0
- metadata +60 -52
- data/README.md +0 -53
- data/lib/will_paginate/finder.rb +0 -264
- data/lib/will_paginate/i18n.rb +0 -29
- data/lib/will_paginate/locale/en.yml +0 -33
- data/lib/will_paginate/named_scope.rb +0 -170
- data/lib/will_paginate/named_scope_patch.rb +0 -37
- data/lib/will_paginate/per_page.rb +0 -27
- data/test/ci.rb +0 -56
- data/test/collection_test.rb +0 -160
- data/test/console +0 -8
- data/test/database.yml +0 -16
- data/test/finder_test.rb +0 -520
- data/test/fixtures/topic.rb +0 -12
- data/test/gemfiles/Gemfile.1.2 +0 -13
- data/test/gemfiles/Gemfile.1.2.lock +0 -39
- data/test/gemfiles/Gemfile.2.0 +0 -16
- data/test/gemfiles/Gemfile.2.0.lock +0 -28
- data/test/gemfiles/Gemfile.2.1 +0 -16
- data/test/gemfiles/Gemfile.2.1.lock +0 -28
- data/test/gemfiles/Gemfile.2.2 +0 -16
- data/test/gemfiles/Gemfile.2.2.lock +0 -28
- data/test/helper.rb +0 -34
- data/test/lib/activerecord_test_case.rb +0 -38
- data/test/lib/activerecord_test_connector.rb +0 -86
- data/test/lib/load_fixtures.rb +0 -12
- data/test/lib/view_test_process.rb +0 -186
- data/test/view_test.rb +0 -373
- /data/{test → spec}/fixtures/admin.rb +0 -0
- /data/{test → spec}/fixtures/developers_projects.yml +0 -0
- /data/{test → spec}/fixtures/replies.yml +0 -0
- /data/{test → spec}/fixtures/schema.rb +0 -0
- /data/{test → spec}/fixtures/topics.yml +0 -0
- /data/{test → spec}/fixtures/user.rb +0 -0
- /data/{test → spec}/fixtures/users.yml +0 -0
metadata
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: will_paginate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
version: 2.3.16
|
|
4
|
+
version: 3.0.pre
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- "Mislav Marohni\xC4\x87"
|
|
9
|
-
- PJ Hyett
|
|
10
8
|
autorequire:
|
|
11
9
|
bindir: bin
|
|
12
10
|
cert_chain: []
|
|
13
11
|
|
|
14
|
-
date:
|
|
12
|
+
date: 2010-02-05 00:00:00 +01:00
|
|
13
|
+
default_executable:
|
|
15
14
|
dependencies: []
|
|
16
15
|
|
|
17
|
-
description: will_paginate provides a simple API for
|
|
16
|
+
description: The will_paginate library provides a simple, yet powerful and extensible API for pagination and rendering of page links in web application templates.
|
|
18
17
|
email: mislav.marohnic@gmail.com
|
|
19
18
|
executables: []
|
|
20
19
|
|
|
21
20
|
extensions: []
|
|
22
21
|
|
|
23
22
|
extra_rdoc_files:
|
|
24
|
-
- README.
|
|
23
|
+
- README.rdoc
|
|
25
24
|
- LICENSE
|
|
26
25
|
- CHANGELOG.rdoc
|
|
27
26
|
files:
|
|
@@ -29,77 +28,86 @@ files:
|
|
|
29
28
|
- lib/will_paginate/array.rb
|
|
30
29
|
- lib/will_paginate/collection.rb
|
|
31
30
|
- lib/will_paginate/core_ext.rb
|
|
32
|
-
- lib/will_paginate/
|
|
33
|
-
- lib/will_paginate/
|
|
34
|
-
- lib/will_paginate/
|
|
35
|
-
- lib/will_paginate/
|
|
36
|
-
- lib/will_paginate/
|
|
37
|
-
- lib/will_paginate/
|
|
31
|
+
- lib/will_paginate/deprecation.rb
|
|
32
|
+
- lib/will_paginate/finders/active_record.rb
|
|
33
|
+
- lib/will_paginate/finders/active_resource.rb
|
|
34
|
+
- lib/will_paginate/finders/base.rb
|
|
35
|
+
- lib/will_paginate/finders/data_mapper.rb
|
|
36
|
+
- lib/will_paginate/finders/sequel.rb
|
|
37
|
+
- lib/will_paginate/finders.rb
|
|
38
|
+
- lib/will_paginate/railtie.rb
|
|
38
39
|
- lib/will_paginate/version.rb
|
|
40
|
+
- lib/will_paginate/view_helpers/action_view.rb
|
|
41
|
+
- lib/will_paginate/view_helpers/base.rb
|
|
42
|
+
- lib/will_paginate/view_helpers/link_renderer.rb
|
|
43
|
+
- lib/will_paginate/view_helpers/link_renderer_base.rb
|
|
44
|
+
- lib/will_paginate/view_helpers/merb.rb
|
|
39
45
|
- lib/will_paginate/view_helpers.rb
|
|
40
46
|
- lib/will_paginate.rb
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
47
|
+
- spec/collection_spec.rb
|
|
48
|
+
- spec/console
|
|
49
|
+
- spec/console_fixtures.rb
|
|
50
|
+
- spec/database.yml
|
|
51
|
+
- spec/finders/active_record_spec.rb
|
|
52
|
+
- spec/finders/active_resource_spec.rb
|
|
53
|
+
- spec/finders/activerecord_test_connector.rb
|
|
54
|
+
- spec/finders/data_mapper_spec.rb
|
|
55
|
+
- spec/finders/data_mapper_test_connector.rb
|
|
56
|
+
- spec/finders/sequel_spec.rb
|
|
57
|
+
- spec/finders/sequel_test_connector.rb
|
|
58
|
+
- spec/finders_spec.rb
|
|
59
|
+
- spec/fixtures/admin.rb
|
|
60
|
+
- spec/fixtures/developer.rb
|
|
61
|
+
- spec/fixtures/developers_projects.yml
|
|
62
|
+
- spec/fixtures/project.rb
|
|
63
|
+
- spec/fixtures/projects.yml
|
|
64
|
+
- spec/fixtures/replies.yml
|
|
65
|
+
- spec/fixtures/reply.rb
|
|
66
|
+
- spec/fixtures/schema.rb
|
|
67
|
+
- spec/fixtures/topic.rb
|
|
68
|
+
- spec/fixtures/topics.yml
|
|
69
|
+
- spec/fixtures/user.rb
|
|
70
|
+
- spec/fixtures/users.yml
|
|
71
|
+
- spec/rcov.opts
|
|
72
|
+
- spec/spec.opts
|
|
73
|
+
- spec/spec_helper.rb
|
|
74
|
+
- spec/tasks.rake
|
|
75
|
+
- spec/view_helpers/action_view_spec.rb
|
|
76
|
+
- spec/view_helpers/base_spec.rb
|
|
77
|
+
- spec/view_helpers/link_renderer_base_spec.rb
|
|
78
|
+
- spec/view_helpers/view_example_group.rb
|
|
79
|
+
- README.rdoc
|
|
73
80
|
- LICENSE
|
|
74
81
|
- CHANGELOG.rdoc
|
|
75
|
-
|
|
82
|
+
has_rdoc: true
|
|
83
|
+
homepage: http://github.com/mislav/will_paginate/wikis
|
|
76
84
|
licenses: []
|
|
77
85
|
|
|
78
86
|
post_install_message:
|
|
79
87
|
rdoc_options:
|
|
80
88
|
- --main
|
|
81
|
-
- README.
|
|
89
|
+
- README.rdoc
|
|
82
90
|
- --charset=UTF-8
|
|
83
91
|
require_paths:
|
|
84
92
|
- lib
|
|
85
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
-
none: false
|
|
87
94
|
requirements:
|
|
88
95
|
- - ">="
|
|
89
96
|
- !ruby/object:Gem::Version
|
|
90
97
|
version: "0"
|
|
98
|
+
version:
|
|
91
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
-
none: false
|
|
93
100
|
requirements:
|
|
94
|
-
- - "
|
|
101
|
+
- - ">"
|
|
95
102
|
- !ruby/object:Gem::Version
|
|
96
|
-
version:
|
|
103
|
+
version: 1.3.1
|
|
104
|
+
version:
|
|
97
105
|
requirements: []
|
|
98
106
|
|
|
99
107
|
rubyforge_project:
|
|
100
|
-
rubygems_version: 1.
|
|
108
|
+
rubygems_version: 1.3.5
|
|
101
109
|
signing_key:
|
|
102
110
|
specification_version: 3
|
|
103
|
-
summary:
|
|
111
|
+
summary: Adaptive pagination plugin for web frameworks and other applications
|
|
104
112
|
test_files: []
|
|
105
113
|
|
data/README.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# will_paginate
|
|
2
|
-
|
|
3
|
-
will_paginate v2.3 is a pagination plugin for Rails and Active Record.
|
|
4
|
-
|
|
5
|
-
Installation:
|
|
6
|
-
|
|
7
|
-
~~~ ruby
|
|
8
|
-
## environment.rb
|
|
9
|
-
Rails::Initializer.run do |config|
|
|
10
|
-
config.gem 'will_paginate', :version => '~> 2.3.16'
|
|
11
|
-
end
|
|
12
|
-
~~~
|
|
13
|
-
|
|
14
|
-
See [installation instructions][install] on the wiki for more info.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Basic will_paginate use
|
|
18
|
-
|
|
19
|
-
~~~ ruby
|
|
20
|
-
## perform a paginated query:
|
|
21
|
-
@posts = Post.paginate(:page => params[:page])
|
|
22
|
-
|
|
23
|
-
# or, use an explicit "per page" limit:
|
|
24
|
-
Post.paginate(:page => params[:page], :per_page => 30)
|
|
25
|
-
|
|
26
|
-
## render page links in the view:
|
|
27
|
-
<%= will_paginate @posts %>
|
|
28
|
-
~~~
|
|
29
|
-
|
|
30
|
-
And that's it! You're done. You just need to add some CSS styles to [make those pagination links prettier][css].
|
|
31
|
-
|
|
32
|
-
You can customize the default "per_page" value:
|
|
33
|
-
|
|
34
|
-
~~~ ruby
|
|
35
|
-
# for the Post model
|
|
36
|
-
class Post
|
|
37
|
-
self.per_page = 10
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# set per_page globally
|
|
41
|
-
WillPaginate.per_page = 10
|
|
42
|
-
~~~
|
|
43
|
-
|
|
44
|
-
See [the wiki][wiki] for more documentation. [Ask on the group][group] if you have usage questions. [Report bugs][issues] on GitHub.
|
|
45
|
-
|
|
46
|
-
Happy paginating.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[wiki]: https://github.com/mislav/will_paginate/wiki
|
|
50
|
-
[install]: https://github.com/mislav/will_paginate/wiki/Installation "will_paginate installation"
|
|
51
|
-
[group]: http://groups.google.com/group/will_paginate "will_paginate discussion and support group"
|
|
52
|
-
[issues]: https://github.com/mislav/will_paginate/issues
|
|
53
|
-
[css]: http://mislav.uniqpath.com/will_paginate/
|
data/lib/will_paginate/finder.rb
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
require 'will_paginate/core_ext'
|
|
2
|
-
require 'will_paginate/per_page'
|
|
3
|
-
|
|
4
|
-
module WillPaginate
|
|
5
|
-
# A mixin for ActiveRecord::Base. Provides +per_page+ class method
|
|
6
|
-
# and hooks things up to provide paginating finders.
|
|
7
|
-
#
|
|
8
|
-
# Find out more in WillPaginate::Finder::ClassMethods
|
|
9
|
-
#
|
|
10
|
-
module Finder
|
|
11
|
-
def self.included(base)
|
|
12
|
-
base.extend PerPage
|
|
13
|
-
base.extend ClassMethods
|
|
14
|
-
class << base
|
|
15
|
-
alias_method_chain :method_missing, :paginate
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# = Paginating finders for ActiveRecord models
|
|
20
|
-
#
|
|
21
|
-
# WillPaginate adds +paginate+, +per_page+ and other methods to
|
|
22
|
-
# ActiveRecord::Base class methods and associations. It also hooks into
|
|
23
|
-
# +method_missing+ to intercept pagination calls to dynamic finders such as
|
|
24
|
-
# +paginate_by_user_id+ and translate them to ordinary finders
|
|
25
|
-
# (+find_all_by_user_id+ in this case).
|
|
26
|
-
#
|
|
27
|
-
# In short, paginating finders are equivalent to ActiveRecord finders; the
|
|
28
|
-
# only difference is that we start with "paginate" instead of "find" and
|
|
29
|
-
# that <tt>:page</tt> is required parameter:
|
|
30
|
-
#
|
|
31
|
-
# @posts = Post.paginate :all, :page => params[:page], :order => 'created_at DESC'
|
|
32
|
-
#
|
|
33
|
-
# In paginating finders, "all" is implicit. There is no sense in paginating
|
|
34
|
-
# a single record, right? So, you can drop the <tt>:all</tt> argument:
|
|
35
|
-
#
|
|
36
|
-
# Post.paginate(...) => Post.find :all
|
|
37
|
-
# Post.paginate_all_by_something => Post.find_all_by_something
|
|
38
|
-
# Post.paginate_by_something => Post.find_all_by_something
|
|
39
|
-
#
|
|
40
|
-
# == The importance of the <tt>:order</tt> parameter
|
|
41
|
-
#
|
|
42
|
-
# In ActiveRecord finders, <tt>:order</tt> parameter specifies columns for
|
|
43
|
-
# the <tt>ORDER BY</tt> clause in SQL. It is important to have it, since
|
|
44
|
-
# pagination only makes sense with ordered sets. Without the <tt>ORDER
|
|
45
|
-
# BY</tt> clause, databases aren't required to do consistent ordering when
|
|
46
|
-
# performing <tt>SELECT</tt> queries; this is especially true for
|
|
47
|
-
# PostgreSQL.
|
|
48
|
-
#
|
|
49
|
-
# Therefore, make sure you are doing ordering on a column that makes the
|
|
50
|
-
# most sense in the current context. Make that obvious to the user, also.
|
|
51
|
-
# For perfomance reasons you will also want to add an index to that column.
|
|
52
|
-
module ClassMethods
|
|
53
|
-
# This is the main paginating finder.
|
|
54
|
-
#
|
|
55
|
-
# == Special parameters for paginating finders
|
|
56
|
-
# * <tt>:page</tt> -- REQUIRED, but defaults to 1 if false or nil
|
|
57
|
-
# * <tt>:per_page</tt> -- defaults to <tt>CurrentModel.per_page</tt> (which is 30 if not overridden)
|
|
58
|
-
# * <tt>:total_entries</tt> -- use only if you manually count total entries
|
|
59
|
-
# * <tt>:count</tt> -- additional options that are passed on to +count+
|
|
60
|
-
# * <tt>:finder</tt> -- name of the ActiveRecord finder used (default: "find")
|
|
61
|
-
#
|
|
62
|
-
# All other options (+conditions+, +order+, ...) are forwarded to +find+
|
|
63
|
-
# and +count+ calls.
|
|
64
|
-
def paginate(*args)
|
|
65
|
-
options = args.pop
|
|
66
|
-
page, per_page, total_entries = wp_parse_options(options)
|
|
67
|
-
finder = (options[:finder] || 'find').to_s
|
|
68
|
-
|
|
69
|
-
if finder == 'find'
|
|
70
|
-
# an array of IDs may have been given:
|
|
71
|
-
total_entries ||= (Array === args.first and args.first.size)
|
|
72
|
-
# :all is implicit
|
|
73
|
-
args.unshift(:all) if args.empty?
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
|
|
77
|
-
count_options = options.except :page, :per_page, :total_entries, :finder
|
|
78
|
-
find_options = count_options.except(:count).update(:offset => pager.offset, :limit => pager.per_page)
|
|
79
|
-
|
|
80
|
-
args << find_options
|
|
81
|
-
# @options_from_last_find = nil
|
|
82
|
-
pager.replace(send(finder, *args) { |*a| yield(*a) if block_given? })
|
|
83
|
-
|
|
84
|
-
# magic counting for user convenience:
|
|
85
|
-
pager.total_entries = wp_count(count_options, args, finder) unless pager.total_entries
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Iterates through all records by loading one page at a time. This is useful
|
|
90
|
-
# for migrations or any other use case where you don't want to load all the
|
|
91
|
-
# records in memory at once.
|
|
92
|
-
#
|
|
93
|
-
# It uses +paginate+ internally; therefore it accepts all of its options.
|
|
94
|
-
# You can specify a starting page with <tt>:page</tt> (default is 1). Default
|
|
95
|
-
# <tt>:order</tt> is <tt>"id"</tt>, override if necessary.
|
|
96
|
-
#
|
|
97
|
-
# See {Faking Cursors in ActiveRecord}[http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord]
|
|
98
|
-
# where Jamis Buck describes this and a more efficient way for MySQL.
|
|
99
|
-
def paginated_each(options = {})
|
|
100
|
-
options = { :order => 'id', :page => 1 }.merge options
|
|
101
|
-
options[:page] = options[:page].to_i
|
|
102
|
-
options[:total_entries] = 0 # skip the individual count queries
|
|
103
|
-
total = 0
|
|
104
|
-
|
|
105
|
-
begin
|
|
106
|
-
collection = paginate(options)
|
|
107
|
-
with_exclusive_scope(:find => {}) do
|
|
108
|
-
# using exclusive scope so that the block is yielded in scope-free context
|
|
109
|
-
total += collection.each { |item| yield item }.size
|
|
110
|
-
end
|
|
111
|
-
options[:page] += 1
|
|
112
|
-
end until collection.size < collection.per_page
|
|
113
|
-
|
|
114
|
-
total
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# Wraps +find_by_sql+ by simply adding LIMIT and OFFSET to your SQL string
|
|
118
|
-
# based on the params otherwise used by paginating finds: +page+ and
|
|
119
|
-
# +per_page+.
|
|
120
|
-
#
|
|
121
|
-
# Example:
|
|
122
|
-
#
|
|
123
|
-
# @developers = Developer.paginate_by_sql ['select * from developers where salary > ?', 80000],
|
|
124
|
-
# :page => params[:page], :per_page => 3
|
|
125
|
-
#
|
|
126
|
-
# A query for counting rows will automatically be generated if you don't
|
|
127
|
-
# supply <tt>:total_entries</tt>. If you experience problems with this
|
|
128
|
-
# generated SQL, you might want to perform the count manually in your
|
|
129
|
-
# application.
|
|
130
|
-
#
|
|
131
|
-
def paginate_by_sql(sql, options)
|
|
132
|
-
WillPaginate::Collection.create(*wp_parse_options(options)) do |pager|
|
|
133
|
-
query = sanitize_sql(sql.dup)
|
|
134
|
-
original_query = query.dup
|
|
135
|
-
# add limit, offset
|
|
136
|
-
add_limit! query, :offset => pager.offset, :limit => pager.per_page
|
|
137
|
-
# perfom the find
|
|
138
|
-
pager.replace find_by_sql(query)
|
|
139
|
-
|
|
140
|
-
unless pager.total_entries
|
|
141
|
-
count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, ''
|
|
142
|
-
count_query = "SELECT COUNT(*) FROM (#{count_query})"
|
|
143
|
-
|
|
144
|
-
unless self.connection.adapter_name =~ /^(oracle|oci$)/i
|
|
145
|
-
count_query << ' AS count_table'
|
|
146
|
-
end
|
|
147
|
-
# perform the count query
|
|
148
|
-
pager.total_entries = count_by_sql(count_query)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def respond_to?(method, include_priv = false) #:nodoc:
|
|
154
|
-
case method.to_sym
|
|
155
|
-
when :paginate, :paginate_by_sql
|
|
156
|
-
true
|
|
157
|
-
else
|
|
158
|
-
super || super(method.to_s.sub(/^paginate/, 'find'), include_priv)
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
protected
|
|
163
|
-
|
|
164
|
-
def method_missing_with_paginate(method, *args) #:nodoc:
|
|
165
|
-
# did somebody tried to paginate? if not, let them be
|
|
166
|
-
unless method.to_s.index('paginate') == 0
|
|
167
|
-
if block_given?
|
|
168
|
-
return method_missing_without_paginate(method, *args) { |*a| yield(*a) }
|
|
169
|
-
else
|
|
170
|
-
return method_missing_without_paginate(method, *args)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# paginate finders are really just find_* with limit and offset
|
|
175
|
-
finder = method.to_s.sub('paginate', 'find')
|
|
176
|
-
finder.sub!('find', 'find_all') if finder.index('find_by_') == 0
|
|
177
|
-
|
|
178
|
-
options = args.pop
|
|
179
|
-
raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys
|
|
180
|
-
options = options.dup
|
|
181
|
-
options[:finder] = finder
|
|
182
|
-
args << options
|
|
183
|
-
|
|
184
|
-
paginate(*args) { |*a| yield(*a) if block_given? }
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
# Does the not-so-trivial job of finding out the total number of entries
|
|
188
|
-
# in the database. It relies on the ActiveRecord +count+ method.
|
|
189
|
-
def wp_count(options, args, finder)
|
|
190
|
-
excludees = [:count, :order, :limit, :offset, :readonly]
|
|
191
|
-
excludees << :from unless ActiveRecord::Calculations::CALCULATIONS_OPTIONS.include?(:from)
|
|
192
|
-
|
|
193
|
-
# we may be in a model or an association proxy
|
|
194
|
-
klass = (@owner and @reflection) ? @reflection.klass : self
|
|
195
|
-
|
|
196
|
-
# Use :select from scope if it isn't already present.
|
|
197
|
-
options[:select] = scope(:find, :select) unless options[:select]
|
|
198
|
-
|
|
199
|
-
if options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
|
|
200
|
-
# Remove quoting and check for table_name.*-like statement.
|
|
201
|
-
if options[:select].gsub(/[`"]/, '') =~ /\w+\.\*/
|
|
202
|
-
options[:select] = "DISTINCT #{klass.table_name}.#{klass.primary_key}"
|
|
203
|
-
end
|
|
204
|
-
else
|
|
205
|
-
excludees << :select # only exclude the select param if it doesn't begin with DISTINCT
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
# count expects (almost) the same options as find
|
|
209
|
-
count_options = options.except *excludees
|
|
210
|
-
|
|
211
|
-
# merge the hash found in :count
|
|
212
|
-
# this allows you to specify :select, :order, or anything else just for the count query
|
|
213
|
-
count_options.update options[:count] if options[:count]
|
|
214
|
-
|
|
215
|
-
# forget about includes if they are irrelevant (Rails 2.1)
|
|
216
|
-
if count_options[:include] and
|
|
217
|
-
klass.private_methods.include_method?(:references_eager_loaded_tables?) and
|
|
218
|
-
!klass.send(:references_eager_loaded_tables?, count_options)
|
|
219
|
-
count_options.delete :include
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
# we may have to scope ...
|
|
223
|
-
counter = Proc.new { count(count_options) }
|
|
224
|
-
|
|
225
|
-
count = if finder.index('find_') == 0 and klass.respond_to?(scoper = finder.sub('find', 'with'))
|
|
226
|
-
# scope_out adds a 'with_finder' method which acts like with_scope, if it's present
|
|
227
|
-
# then execute the count with the scoping provided by the with_finder
|
|
228
|
-
send(scoper, &counter)
|
|
229
|
-
elsif finder =~ /^find_(all_by|by)_([_a-zA-Z]\w*)$/
|
|
230
|
-
# extract conditions from calls like "paginate_by_foo_and_bar"
|
|
231
|
-
attribute_names = $2.split('_and_')
|
|
232
|
-
conditions = construct_attributes_from_arguments(attribute_names, args)
|
|
233
|
-
with_scope(:find => { :conditions => conditions }, &counter)
|
|
234
|
-
else
|
|
235
|
-
counter.call
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
(!count.is_a?(Integer) && count.respond_to?(:length)) ? count.length : count
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
def wp_parse_options(options) #:nodoc:
|
|
242
|
-
raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys
|
|
243
|
-
options = options.symbolize_keys
|
|
244
|
-
raise ArgumentError, ':page parameter required' unless options.key? :page
|
|
245
|
-
|
|
246
|
-
if options[:count] and options[:total_entries]
|
|
247
|
-
raise ArgumentError, ':count and :total_entries are mutually exclusive'
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
page = options[:page] || 1
|
|
251
|
-
per_page = options[:per_page] || self.per_page
|
|
252
|
-
total = options[:total_entries]
|
|
253
|
-
[page, per_page, total]
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
private
|
|
257
|
-
|
|
258
|
-
# def find_every_with_paginate(options)
|
|
259
|
-
# @options_from_last_find = options
|
|
260
|
-
# find_every_without_paginate(options)
|
|
261
|
-
# end
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
end
|
data/lib/will_paginate/i18n.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module WillPaginate
|
|
2
|
-
module I18n
|
|
3
|
-
def self.locale_dir
|
|
4
|
-
File.expand_path('../locale', __FILE__)
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def self.load_path
|
|
8
|
-
Dir["#{locale_dir}/*.{rb,yml}"]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def will_paginate_translate(keys, options = {})
|
|
12
|
-
if defined? ::I18n
|
|
13
|
-
defaults = Array(keys).dup
|
|
14
|
-
if block_given?
|
|
15
|
-
if defined? ::I18n::Backend::Simple::MATCH
|
|
16
|
-
# procs in defaults array were not supported back then
|
|
17
|
-
defaults << yield(defaults.first, options)
|
|
18
|
-
else
|
|
19
|
-
defaults << Proc.new
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
|
|
23
|
-
else
|
|
24
|
-
key = Array === keys ? keys.first : keys
|
|
25
|
-
yield key, options
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
en:
|
|
2
|
-
will_paginate:
|
|
3
|
-
previous_label: "« Previous"
|
|
4
|
-
next_label: "Next »"
|
|
5
|
-
page_gap: "…"
|
|
6
|
-
|
|
7
|
-
page_entries_info:
|
|
8
|
-
single_page:
|
|
9
|
-
zero: "No %{model} found"
|
|
10
|
-
one: "Displaying 1 %{model}"
|
|
11
|
-
other: "Displaying all %{count} %{model}"
|
|
12
|
-
single_page_html:
|
|
13
|
-
zero: "No %{model} found"
|
|
14
|
-
one: "Displaying <b>1</b> %{model}"
|
|
15
|
-
other: "Displaying <b>all %{count}</b> %{model}"
|
|
16
|
-
|
|
17
|
-
multi_page: "Displaying %{model} %{from} - %{to} of %{count} in total"
|
|
18
|
-
multi_page_html: "Displaying %{model} <b>%{from} - %{to}</b> of <b>%{count}</b> in total"
|
|
19
|
-
|
|
20
|
-
# models:
|
|
21
|
-
# entry:
|
|
22
|
-
# zero: entries
|
|
23
|
-
# one: entry
|
|
24
|
-
# few: entries
|
|
25
|
-
# other: entries
|
|
26
|
-
|
|
27
|
-
# line_item:
|
|
28
|
-
# page_entries_info:
|
|
29
|
-
# single_page:
|
|
30
|
-
# zero: "Your shopping cart is empty"
|
|
31
|
-
# one: "Displaying one item in your cart"
|
|
32
|
-
# other: "Displaying all %{count} items"
|
|
33
|
-
# multi_page: "Displaying items %{from} - %{to} of %{count} in total"
|