will_paginate 3.0.4 → 4.0.0

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +7 -10
  3. data/lib/will_paginate/active_record.rb +18 -17
  4. data/lib/will_paginate/deprecation.rb +3 -3
  5. data/lib/will_paginate/i18n.rb +3 -3
  6. data/lib/will_paginate/locale/en.yml +4 -0
  7. data/lib/will_paginate/mongoid.rb +48 -0
  8. data/lib/will_paginate/page_number.rb +7 -11
  9. data/lib/will_paginate/railtie.rb +19 -13
  10. data/lib/will_paginate/version.rb +2 -2
  11. data/lib/will_paginate/view_helpers/action_view.rb +12 -5
  12. data/lib/will_paginate/view_helpers/hanami.rb +41 -0
  13. data/lib/will_paginate/view_helpers/link_renderer.rb +23 -17
  14. data/lib/will_paginate/view_helpers/link_renderer_base.rb +1 -1
  15. data/lib/will_paginate/view_helpers.rb +3 -1
  16. data/lib/will_paginate.rb +0 -12
  17. metadata +29 -58
  18. data/Rakefile +0 -25
  19. data/lib/will_paginate/data_mapper.rb +0 -95
  20. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  21. data/spec/ci.rb +0 -29
  22. data/spec/collection_spec.rb +0 -139
  23. data/spec/console +0 -12
  24. data/spec/console_fixtures.rb +0 -28
  25. data/spec/database.yml +0 -22
  26. data/spec/finders/active_record_spec.rb +0 -556
  27. data/spec/finders/activerecord_test_connector.rb +0 -115
  28. data/spec/finders/data_mapper_spec.rb +0 -103
  29. data/spec/finders/data_mapper_test_connector.rb +0 -54
  30. data/spec/finders/sequel_spec.rb +0 -67
  31. data/spec/finders/sequel_test_connector.rb +0 -15
  32. data/spec/fixtures/admin.rb +0 -3
  33. data/spec/fixtures/developer.rb +0 -13
  34. data/spec/fixtures/developers_projects.yml +0 -13
  35. data/spec/fixtures/project.rb +0 -15
  36. data/spec/fixtures/projects.yml +0 -6
  37. data/spec/fixtures/replies.yml +0 -29
  38. data/spec/fixtures/reply.rb +0 -9
  39. data/spec/fixtures/schema.rb +0 -38
  40. data/spec/fixtures/topic.rb +0 -7
  41. data/spec/fixtures/topics.yml +0 -30
  42. data/spec/fixtures/user.rb +0 -2
  43. data/spec/fixtures/users.yml +0 -35
  44. data/spec/page_number_spec.rb +0 -65
  45. data/spec/per_page_spec.rb +0 -41
  46. data/spec/spec_helper.rb +0 -71
  47. data/spec/view_helpers/action_view_spec.rb +0 -423
  48. data/spec/view_helpers/base_spec.rb +0 -130
  49. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  50. data/spec/view_helpers/view_example_group.rb +0 -121
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
5
- prerelease:
4
+ version: 4.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mislav Marohnić
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: will_paginate provides a simple API for performing paginated queries
15
- with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
16
- links in Rails, Sinatra and Merb web apps.
14
+ with Active Record and Sequel, and includes helpers for rendering pagination links
15
+ in Rails, Sinatra, and Hanami web apps.
17
16
  email: mislav.marohnic@gmail.com
18
17
  executables: []
19
18
  extensions: []
@@ -21,85 +20,57 @@ extra_rdoc_files:
21
20
  - README.md
22
21
  - LICENSE
23
22
  files:
24
- - Rakefile
23
+ - LICENSE
24
+ - README.md
25
+ - lib/will_paginate.rb
25
26
  - lib/will_paginate/active_record.rb
26
27
  - lib/will_paginate/array.rb
27
28
  - lib/will_paginate/collection.rb
28
29
  - lib/will_paginate/core_ext.rb
29
- - lib/will_paginate/data_mapper.rb
30
30
  - lib/will_paginate/deprecation.rb
31
31
  - lib/will_paginate/i18n.rb
32
32
  - lib/will_paginate/locale/en.yml
33
+ - lib/will_paginate/mongoid.rb
33
34
  - lib/will_paginate/page_number.rb
34
35
  - lib/will_paginate/per_page.rb
35
36
  - lib/will_paginate/railtie.rb
36
37
  - lib/will_paginate/sequel.rb
37
38
  - lib/will_paginate/version.rb
39
+ - lib/will_paginate/view_helpers.rb
38
40
  - lib/will_paginate/view_helpers/action_view.rb
41
+ - lib/will_paginate/view_helpers/hanami.rb
39
42
  - lib/will_paginate/view_helpers/link_renderer.rb
40
43
  - lib/will_paginate/view_helpers/link_renderer_base.rb
41
- - lib/will_paginate/view_helpers/merb.rb
42
44
  - lib/will_paginate/view_helpers/sinatra.rb
43
- - lib/will_paginate/view_helpers.rb
44
- - lib/will_paginate.rb
45
- - spec/ci.rb
46
- - spec/collection_spec.rb
47
- - spec/console
48
- - spec/console_fixtures.rb
49
- - spec/database.yml
50
- - spec/finders/active_record_spec.rb
51
- - spec/finders/activerecord_test_connector.rb
52
- - spec/finders/data_mapper_spec.rb
53
- - spec/finders/data_mapper_test_connector.rb
54
- - spec/finders/sequel_spec.rb
55
- - spec/finders/sequel_test_connector.rb
56
- - spec/fixtures/admin.rb
57
- - spec/fixtures/developer.rb
58
- - spec/fixtures/developers_projects.yml
59
- - spec/fixtures/project.rb
60
- - spec/fixtures/projects.yml
61
- - spec/fixtures/replies.yml
62
- - spec/fixtures/reply.rb
63
- - spec/fixtures/schema.rb
64
- - spec/fixtures/topic.rb
65
- - spec/fixtures/topics.yml
66
- - spec/fixtures/user.rb
67
- - spec/fixtures/users.yml
68
- - spec/page_number_spec.rb
69
- - spec/per_page_spec.rb
70
- - spec/spec_helper.rb
71
- - spec/view_helpers/action_view_spec.rb
72
- - spec/view_helpers/base_spec.rb
73
- - spec/view_helpers/link_renderer_base_spec.rb
74
- - spec/view_helpers/view_example_group.rb
75
- - README.md
76
- - LICENSE
77
- homepage: https://github.com/mislav/will_paginate/wiki
78
- licenses: []
79
- post_install_message:
45
+ homepage: https://github.com/mislav/will_paginate
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ bug_tracker_uri: https://github.com/mislav/will_paginate/issues
50
+ changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v4.0.0
51
+ documentation_uri: https://www.rubydoc.info/gems/will_paginate/4.0.0
52
+ source_code_uri: https://github.com/mislav/will_paginate/tree/v4.0.0
53
+ wiki_uri: https://github.com/mislav/will_paginate/wiki
54
+ post_install_message:
80
55
  rdoc_options:
81
- - --main
56
+ - "--main"
82
57
  - README.md
83
- - --charset=UTF-8
58
+ - "--charset=UTF-8"
84
59
  require_paths:
85
60
  - lib
86
61
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
62
  requirements:
89
- - - ! '>='
63
+ - - ">="
90
64
  - !ruby/object:Gem::Version
91
- version: '0'
65
+ version: '2.0'
92
66
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
67
  requirements:
95
- - - ! '>='
68
+ - - ">="
96
69
  - !ruby/object:Gem::Version
97
70
  version: '0'
98
71
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 1.8.23
101
- signing_key:
102
- specification_version: 3
72
+ rubygems_version: 3.4.6
73
+ signing_key:
74
+ specification_version: 4
103
75
  summary: Pagination plugin for web frameworks and other apps
104
76
  test_files: []
105
- has_rdoc:
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- begin
2
- require 'rspec/core/rake_task'
3
- rescue LoadError
4
- # no spec tasks
5
- else
6
- task :default => :spec
7
-
8
- desc 'Run ALL OF the specs'
9
- RSpec::Core::RakeTask.new(:spec) do |t|
10
- # t.ruby_opts = '-w'
11
- t.pattern = 'spec/finders/active_record_spec.rb' if ENV['DB'] and ENV['DB'] != 'sqlite3'
12
- end
13
-
14
- namespace :spec do
15
- desc "Run Rails specs"
16
- RSpec::Core::RakeTask.new(:rails) do |t|
17
- t.pattern = %w'spec/finders/active_record_spec.rb spec/view_helpers/action_view_spec.rb'
18
- end
19
- end
20
- end
21
-
22
- desc 'Run specs against both Rails 3.1 and Rails 3.0'
23
- task :rails3 do |variable|
24
- system 'bundle exec rake spec && BUNDLE_GEMFILE=Gemfile.rails3.0 bundle exec rake spec:rails'
25
- end
@@ -1,95 +0,0 @@
1
- require 'dm-core'
2
- require 'dm-aggregates'
3
- require 'will_paginate/per_page'
4
- require 'will_paginate/page_number'
5
- require 'will_paginate/collection'
6
-
7
- module WillPaginate
8
- module DataMapper
9
- module Pagination
10
- def page(num)
11
- pagenum = ::WillPaginate::PageNumber(num.nil? ? 1 : num)
12
- per_page = query.limit || self.per_page
13
- options = {:offset => pagenum.to_offset(per_page).to_i}
14
- options[:limit] = per_page unless query.limit
15
- col = new_collection(query.merge(options))
16
- col.current_page = pagenum
17
- col
18
- end
19
-
20
- def paginate(options)
21
- options = options.dup
22
- pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
23
- per_page = options.delete(:per_page) || self.per_page
24
-
25
- options.delete(:page)
26
- options[:limit] = per_page.to_i
27
-
28
- all(options).page(pagenum)
29
- end
30
- end
31
-
32
- module CollectionMethods
33
- include WillPaginate::CollectionMethods
34
-
35
- attr_accessor :current_page
36
-
37
- def paginated?
38
- !current_page.nil?
39
- end
40
-
41
- def per_page
42
- query.limit || model.per_page
43
- end
44
-
45
- def offset
46
- query.offset
47
- end
48
-
49
- def total_entries
50
- @total_entries ||= begin
51
- if loaded? and @array.size < per_page and (current_page == 1 or @array.size > 0)
52
- offset + @array.size
53
- else
54
- # :reload prevents Collection.filter from being run, which
55
- # would cause a stack overflow
56
- clean_query = query.merge(:reload => true)
57
- # seems like the only way
58
- clean_query.instance_variable_set('@limit', nil)
59
- clean_query.instance_variable_set('@offset', 0)
60
- new_collection(clean_query).count
61
- end
62
- end
63
- end
64
-
65
- def to_a
66
- if paginated?
67
- ::WillPaginate::Collection.create(current_page, per_page) do |col|
68
- col.replace super
69
- col.total_entries ||= total_entries
70
- end
71
- else
72
- super
73
- end
74
- end
75
-
76
- private
77
-
78
- def new_collection(query, resources = nil)
79
- col = super
80
- col.current_page = self.current_page
81
- col
82
- end
83
-
84
- def initialize_copy(original)
85
- super
86
- @total_entries = nil
87
- end
88
- end
89
-
90
- ::DataMapper::Model.append_extensions PerPage
91
- ::DataMapper::Model.append_extensions Pagination
92
- ::DataMapper::Collection.send(:include, Pagination)
93
- ::DataMapper::Collection.send(:include, CollectionMethods)
94
- end
95
- end
@@ -1,26 +0,0 @@
1
- require 'will_paginate/core_ext'
2
- require 'will_paginate/view_helpers'
3
- require 'will_paginate/view_helpers/link_renderer'
4
-
5
- module WillPaginate
6
- module Merb
7
- include ViewHelpers
8
-
9
- def will_paginate(collection, options = {}) #:nodoc:
10
- options = options.merge(:renderer => LinkRenderer) unless options[:renderer]
11
- super(collection, options)
12
- end
13
-
14
- class LinkRenderer < ViewHelpers::LinkRenderer
15
- protected
16
-
17
- def url(page)
18
- params = @template.request.params.except(:action, :controller).merge(param_name => page)
19
- @template.url(:this, params)
20
- end
21
- end
22
-
23
- ::Merb::AbstractController.send(:include, self)
24
- end
25
- end
26
-
data/spec/ci.rb DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- databases = %w[ sqlite3 mysql mysql2 postgres ]
3
- databases.delete 'mysql2' if ENV['BUNDLE_GEMFILE'].to_s.include? 'rails3.0'
4
-
5
- def announce(name, msg)
6
- puts "\n\e[1;33m[#{name}] #{msg}\e[m\n"
7
- end
8
-
9
- def system(*args)
10
- puts "$ #{args.join(' ')}"
11
- super
12
- end
13
-
14
- if ENV['TRAVIS']
15
- system "mysql -e 'create database will_paginate;' >/dev/null"
16
- abort "failed to create mysql database" unless $?.success?
17
- system "psql -c 'create database will_paginate;' -U postgres >/dev/null"
18
- abort "failed to create postgres database" unless $?.success?
19
- end
20
-
21
- failed = false
22
-
23
- for db in databases
24
- announce "DB", db
25
- ENV['DB'] = db
26
- failed = true unless system %(rake)
27
- end
28
-
29
- exit 1 if failed
@@ -1,139 +0,0 @@
1
- require 'will_paginate/array'
2
- require 'spec_helper'
3
-
4
- describe WillPaginate::Collection do
5
-
6
- before :all do
7
- @simple = ('a'..'e').to_a
8
- end
9
-
10
- it "should be a subset of original collection" do
11
- @simple.paginate(:page => 1, :per_page => 3).should == %w( a b c )
12
- end
13
-
14
- it "can be shorter than per_page if on last page" do
15
- @simple.paginate(:page => 2, :per_page => 3).should == %w( d e )
16
- end
17
-
18
- it "should include whole collection if per_page permits" do
19
- @simple.paginate(:page => 1, :per_page => 5).should == @simple
20
- end
21
-
22
- it "should be empty if out of bounds" do
23
- @simple.paginate(:page => 2, :per_page => 5).should be_empty
24
- end
25
-
26
- it "should default to 1 as current page and 30 per-page" do
27
- result = (1..50).to_a.paginate
28
- result.current_page.should == 1
29
- result.size.should == 30
30
- end
31
-
32
- it "should give total_entries precedence over actual size" do
33
- %w(a b c).paginate(:total_entries => 5).total_entries.should == 5
34
- end
35
-
36
- it "should be an augmented Array" do
37
- entries = %w(a b c)
38
- collection = create(2, 3, 10) do |pager|
39
- pager.replace(entries).should == entries
40
- end
41
-
42
- collection.should == entries
43
- for method in %w(total_pages each offset size current_page per_page total_entries)
44
- collection.should respond_to(method)
45
- end
46
- collection.should be_kind_of(Array)
47
- collection.entries.should be_instance_of(Array)
48
- # TODO: move to another expectation:
49
- collection.offset.should == 3
50
- collection.total_pages.should == 4
51
- collection.should_not be_out_of_bounds
52
- end
53
-
54
- describe "previous/next pages" do
55
- it "should have previous_page nil when on first page" do
56
- collection = create(1, 1, 3)
57
- collection.previous_page.should be_nil
58
- collection.next_page.should == 2
59
- end
60
-
61
- it "should have both prev/next pages" do
62
- collection = create(2, 1, 3)
63
- collection.previous_page.should == 1
64
- collection.next_page.should == 3
65
- end
66
-
67
- it "should have next_page nil when on last page" do
68
- collection = create(3, 1, 3)
69
- collection.previous_page.should == 2
70
- collection.next_page.should be_nil
71
- end
72
- end
73
-
74
- describe "out of bounds" do
75
- it "is out of bounds when page number is too high" do
76
- create(2, 3, 2).should be_out_of_bounds
77
- end
78
-
79
- it "isn't out of bounds when inside collection" do
80
- create(1, 3, 2).should_not be_out_of_bounds
81
- end
82
-
83
- it "isn't out of bounds when the collection is empty" do
84
- collection = create(1, 3, 0)
85
- collection.should_not be_out_of_bounds
86
- collection.total_pages.should == 1
87
- end
88
- end
89
-
90
- describe "guessing total count" do
91
- it "can guess when collection is shorter than limit" do
92
- collection = create { |p| p.replace array }
93
- collection.total_entries.should == 8
94
- end
95
-
96
- it "should allow explicit total count to override guessed" do
97
- collection = create(2, 5, 10) { |p| p.replace array }
98
- collection.total_entries.should == 10
99
- end
100
-
101
- it "should not be able to guess when collection is same as limit" do
102
- collection = create { |p| p.replace array(5) }
103
- collection.total_entries.should be_nil
104
- end
105
-
106
- it "should not be able to guess when collection is empty" do
107
- collection = create { |p| p.replace array(0) }
108
- collection.total_entries.should be_nil
109
- end
110
-
111
- it "should be able to guess when collection is empty and this is the first page" do
112
- collection = create(1) { |p| p.replace array(0) }
113
- collection.total_entries.should == 0
114
- end
115
- end
116
-
117
- it "should not respond to page_count anymore" do
118
- Proc.new { create.page_count }.should raise_error(NoMethodError)
119
- end
120
-
121
- it "inherits per_page from global value" do
122
- collection = described_class.new(1)
123
- collection.per_page.should == 30
124
- end
125
-
126
- private
127
-
128
- def create(page = 2, limit = 5, total = nil, &block)
129
- if block_given?
130
- described_class.create(page, limit, total, &block)
131
- else
132
- described_class.new(page, limit, total)
133
- end
134
- end
135
-
136
- def array(size = 3)
137
- Array.new(size)
138
- end
139
- end
data/spec/console DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
3
- opts = %w[ --simple-prompt -rirb/completion ]
4
- if ARGV.include? '-dm'
5
- opts << '-rwill_paginate/data_mapper' << '-rfinders/data_mapper_test_connector'
6
- elsif ARGV.include? '-seq'
7
- opts << '-rwill_paginate/sequel' << '-rfinders/sequel_test_connector'
8
- else
9
- opts << '-rconsole_fixtures'
10
- end
11
-
12
- exec 'bundle', 'exec', irb, '-Ilib:spec', *opts
@@ -1,28 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'will_paginate/active_record'
5
- require 'finders/activerecord_test_connector'
6
-
7
- ActiverecordTestConnector.setup
8
-
9
- windows = RUBY_PLATFORM =~ /(:?mswin|mingw)/
10
- # used just for the `color` method
11
- log_subscriber = ActiveSupport::LogSubscriber.log_subscribers.first
12
-
13
- IGNORE_SQL = /\b(sqlite_master|sqlite_version)\b|^(CREATE TABLE|PRAGMA)\b/
14
-
15
- ActiveSupport::Notifications.subscribe(/^sql\./) do |*args|
16
- data = args.last
17
- unless data[:name] =~ /^Fixture/ or data[:sql] =~ IGNORE_SQL
18
- if windows
19
- puts data[:sql]
20
- else
21
- puts log_subscriber.send(:color, data[:sql], :cyan)
22
- end
23
- end
24
- end
25
-
26
- # load all fixtures
27
- ActiverecordTestConnector::Fixtures.create_fixtures \
28
- ActiverecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables
data/spec/database.yml DELETED
@@ -1,22 +0,0 @@
1
- sqlite3:
2
- database: ":memory:"
3
- adapter: sqlite3
4
- timeout: 500
5
-
6
- mysql:
7
- adapter: mysql
8
- database: will_paginate
9
- username:
10
- encoding: utf8
11
-
12
- mysql2:
13
- adapter: mysql2
14
- database: will_paginate
15
- username:
16
- encoding: utf8
17
-
18
- postgres:
19
- adapter: postgresql
20
- database: will_paginate
21
- username: postgres
22
- min_messages: warning