will_paginate 3.3.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/will_paginate/locale/en.yml +2 -0
  4. data/lib/will_paginate/version.rb +3 -3
  5. data/lib/will_paginate/view_helpers/action_view.rb +6 -2
  6. data/lib/will_paginate/view_helpers/link_renderer.rb +7 -5
  7. data/lib/will_paginate.rb +0 -12
  8. metadata +8 -38
  9. data/lib/will_paginate/data_mapper.rb +0 -100
  10. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  11. data/spec/collection_spec.rb +0 -139
  12. data/spec/console +0 -12
  13. data/spec/console_fixtures.rb +0 -28
  14. data/spec/database.yml +0 -29
  15. data/spec/finders/active_record_spec.rb +0 -424
  16. data/spec/finders/activerecord_test_connector.rb +0 -107
  17. data/spec/fixtures/admin.rb +0 -3
  18. data/spec/fixtures/developer.rb +0 -9
  19. data/spec/fixtures/developers_projects.yml +0 -13
  20. data/spec/fixtures/project.rb +0 -13
  21. data/spec/fixtures/projects.yml +0 -6
  22. data/spec/fixtures/replies.yml +0 -29
  23. data/spec/fixtures/reply.rb +0 -8
  24. data/spec/fixtures/schema.rb +0 -38
  25. data/spec/fixtures/topic.rb +0 -8
  26. data/spec/fixtures/topics.yml +0 -30
  27. data/spec/fixtures/user.rb +0 -2
  28. data/spec/fixtures/users.yml +0 -35
  29. data/spec/matchers/deprecation_matcher.rb +0 -27
  30. data/spec/matchers/phrase_matcher.rb +0 -19
  31. data/spec/matchers/query_count_matcher.rb +0 -36
  32. data/spec/page_number_spec.rb +0 -91
  33. data/spec/per_page_spec.rb +0 -41
  34. data/spec/spec_helper.rb +0 -41
  35. data/spec/view_helpers/action_view_spec.rb +0 -481
  36. data/spec/view_helpers/base_spec.rb +0 -143
  37. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  38. data/spec/view_helpers/view_example_group.rb +0 -105
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3015c2c4a4d84d48b8a9c60a5ad19297e4ccbd515682df95399badb293386536
4
- data.tar.gz: d28dd41a8fe68e9f5e43649978cb8a49b8ff03fc6fcdab303c04fcbe654a6894
3
+ metadata.gz: 95d6a838948c59686c5768a47e8e7e52b99c55868775645285022bc0d7c0e280
4
+ data.tar.gz: c92449392a8191a656e19d5e722314a2f2c1c50d646f5d98359b0d8193539dd2
5
5
  SHA512:
6
- metadata.gz: b6c6843a2f26883a439520ef4106124c1706c8f5deae59c16d1fee074d74a8eb50e39ef3ea8ae8dc0bd6a18331dd618c0f18079f3834b0ebda45a13f050d3f62
7
- data.tar.gz: 5479f100b92648394d8074d2d34be19120008955ce5f5e289073eafac35389890f044d4a66fe0e54d5331fc7d6a82c17497fa800f4fee44c743939560a71af8c
6
+ metadata.gz: 4511c22cbbf023ab6e32fc457c487ec393c2fdf6f8a3910ee0c0d8385061a98307b6a8a8f02a25af33f9f648f735c5d20d942412b3a7ff5a40d2d7ba67491917
7
+ data.tar.gz: a062b0bce8e25a24b818b926957b98f970e86b79f89fbb1e2cdfbce382a030d02b3f02800cce6dd1671d84d3251e33879095a1bbe669a7348df90a3664be95ec
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # will_paginate
2
2
 
3
- will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, Merb, DataMapper and Sequel.
3
+ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, and Sequel.
4
4
 
5
5
  ``` ruby
6
- gem 'will_paginate', '~> 3.1.0'
6
+ gem 'will_paginate', '~> 3.3'
7
7
  ```
8
8
 
9
9
  See [installation instructions][install] on the wiki for more info.
@@ -1,7 +1,9 @@
1
1
  en:
2
2
  will_paginate:
3
3
  previous_label: "← Previous"
4
+ previous_aria_label: "Previous page"
4
5
  next_label: "Next →"
6
+ next_aria_label: "Next page"
5
7
  page_gap: "…"
6
8
  container_aria_label: "Pagination"
7
9
  page_aria_label: "Page %{page}"
@@ -1,8 +1,8 @@
1
1
  module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 3
5
- TINY = 1
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -119,8 +119,12 @@ module WillPaginate
119
119
  end
120
120
 
121
121
  def merge_get_params(url_params)
122
- if @template.respond_to? :request and @template.request and @template.request.get?
123
- symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
122
+ if @template.respond_to?(:request) and @template.request
123
+ if @template.request.get?
124
+ symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
125
+ elsif @template.request.respond_to?(:query_parameters)
126
+ symbolized_update(url_params, @template.request.query_parameters, GET_PARAMS_BLACKLIST)
127
+ end
124
128
  end
125
129
  url_params
126
130
  end
@@ -59,19 +59,21 @@ module WillPaginate
59
59
 
60
60
  def previous_page
61
61
  num = @collection.current_page > 1 && @collection.current_page - 1
62
- previous_or_next_page(num, @options[:previous_label], 'previous_page')
62
+ aria_label = @template.will_paginate_translate(:previous_aria_label) { "Previous page" }
63
+ previous_or_next_page(num, @options[:previous_label], 'previous_page', aria_label)
63
64
  end
64
65
 
65
66
  def next_page
66
67
  num = @collection.current_page < total_pages && @collection.current_page + 1
67
- previous_or_next_page(num, @options[:next_label], 'next_page')
68
+ aria_label = @template.will_paginate_translate(:next_aria_label) { "Next page" }
69
+ previous_or_next_page(num, @options[:next_label], 'next_page', aria_label)
68
70
  end
69
71
 
70
- def previous_or_next_page(page, text, classname)
72
+ def previous_or_next_page(page, text, classname, aria_label = nil)
71
73
  if page
72
- link(text, page, :class => classname)
74
+ link(text, page, :class => classname, :'aria-label' => aria_label)
73
75
  else
74
- tag(:span, text, :class => classname + ' disabled', :"aria-disabled" => true)
76
+ tag(:span, text, :class => classname + ' disabled', :'aria-label' => aria_label)
75
77
  end
76
78
  end
77
79
 
data/lib/will_paginate.rb CHANGED
@@ -8,18 +8,6 @@ elsif defined?(Rails::Initializer)
8
8
  raise "will_paginate 3.0 is not compatible with Rails 2.3 or older"
9
9
  end
10
10
 
11
- if defined?(Merb::AbstractController)
12
- require 'will_paginate/view_helpers/merb'
13
-
14
- Merb::BootLoader.before_app_loads do
15
- adapters = { :datamapper => 'data_mapper', :activerecord => 'active_record', :sequel => 'sequel' }
16
- # auto-load the right ORM adapter
17
- if adapter = adapters[Merb.orm]
18
- require "will_paginate/#{adapter}"
19
- end
20
- end
21
- end
22
-
23
11
  if defined?(Sinatra) and Sinatra.respond_to? :register
24
12
  require 'will_paginate/view_helpers/sinatra'
25
13
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-12 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: will_paginate provides a simple API for performing paginated queries
14
- with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
15
- links in Rails, Sinatra, Hanami, 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.
16
16
  email: mislav.marohnic@gmail.com
17
17
  executables: []
18
18
  extensions: []
@@ -27,7 +27,6 @@ files:
27
27
  - lib/will_paginate/array.rb
28
28
  - lib/will_paginate/collection.rb
29
29
  - lib/will_paginate/core_ext.rb
30
- - lib/will_paginate/data_mapper.rb
31
30
  - lib/will_paginate/deprecation.rb
32
31
  - lib/will_paginate/i18n.rb
33
32
  - lib/will_paginate/locale/en.yml
@@ -42,44 +41,15 @@ files:
42
41
  - lib/will_paginate/view_helpers/hanami.rb
43
42
  - lib/will_paginate/view_helpers/link_renderer.rb
44
43
  - lib/will_paginate/view_helpers/link_renderer_base.rb
45
- - lib/will_paginate/view_helpers/merb.rb
46
44
  - lib/will_paginate/view_helpers/sinatra.rb
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/activerecord_test_connector.rb
53
- - spec/fixtures/admin.rb
54
- - spec/fixtures/developer.rb
55
- - spec/fixtures/developers_projects.yml
56
- - spec/fixtures/project.rb
57
- - spec/fixtures/projects.yml
58
- - spec/fixtures/replies.yml
59
- - spec/fixtures/reply.rb
60
- - spec/fixtures/schema.rb
61
- - spec/fixtures/topic.rb
62
- - spec/fixtures/topics.yml
63
- - spec/fixtures/user.rb
64
- - spec/fixtures/users.yml
65
- - spec/matchers/deprecation_matcher.rb
66
- - spec/matchers/phrase_matcher.rb
67
- - spec/matchers/query_count_matcher.rb
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
45
  homepage: https://github.com/mislav/will_paginate
76
46
  licenses:
77
47
  - MIT
78
48
  metadata:
79
49
  bug_tracker_uri: https://github.com/mislav/will_paginate/issues
80
- changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v3.3.1
81
- documentation_uri: https://www.rubydoc.info/gems/will_paginate/3.3.1
82
- source_code_uri: https://github.com/mislav/will_paginate/tree/v3.3.1
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
83
53
  wiki_uri: https://github.com/mislav/will_paginate/wiki
84
54
  post_install_message:
85
55
  rdoc_options:
@@ -99,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
69
  - !ruby/object:Gem::Version
100
70
  version: '0'
101
71
  requirements: []
102
- rubygems_version: 3.1.4
72
+ rubygems_version: 3.4.6
103
73
  signing_key:
104
74
  specification_version: 4
105
75
  summary: Pagination plugin for web frameworks and other apps
@@ -1,100 +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
- total = options.delete(:total_entries)
25
-
26
- options.delete(:page)
27
- options[:limit] = per_page.to_i
28
-
29
-
30
- col = all(options).page(pagenum)
31
- col.total_entries = total.to_i unless total.nil? || (total.kind_of?(String) && total.strip.empty?)
32
- col
33
- end
34
- end
35
-
36
- module CollectionMethods
37
- include WillPaginate::CollectionMethods
38
-
39
- attr_accessor :current_page
40
- attr_writer :total_entries
41
-
42
- def paginated?
43
- !current_page.nil?
44
- end
45
-
46
- def per_page
47
- query.limit || model.per_page
48
- end
49
-
50
- def offset
51
- query.offset
52
- end
53
-
54
- def total_entries
55
- @total_entries ||= begin
56
- if loaded? and @array.size < per_page and (current_page == 1 or @array.size > 0)
57
- offset + @array.size
58
- else
59
- # :reload prevents Collection.filter from being run, which
60
- # would cause a stack overflow
61
- clean_query = query.merge(:reload => true)
62
- # seems like the only way
63
- clean_query.instance_variable_set('@limit', nil)
64
- clean_query.instance_variable_set('@offset', 0)
65
- new_collection(clean_query).count
66
- end
67
- end
68
- end
69
-
70
- def to_a
71
- if paginated?
72
- ::WillPaginate::Collection.create(current_page, per_page) do |col|
73
- col.replace super
74
- col.total_entries ||= total_entries
75
- end
76
- else
77
- super
78
- end
79
- end
80
-
81
- private
82
-
83
- def new_collection(query, resources = nil)
84
- col = super
85
- col.current_page = self.current_page
86
- col
87
- end
88
-
89
- def initialize_copy(original)
90
- super
91
- @total_entries = nil
92
- end
93
- end
94
-
95
- ::DataMapper::Model.append_extensions PerPage
96
- ::DataMapper::Model.append_extensions Pagination
97
- ::DataMapper::Collection.send(:include, Pagination)
98
- ::DataMapper::Collection.send(:include, CollectionMethods)
99
- end
100
- 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
-
@@ -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,29 +0,0 @@
1
- sqlite3:
2
- database: ":memory:"
3
- adapter: sqlite3
4
- timeout: 500
5
-
6
- mysql:
7
- adapter: mysql2
8
- database: will_paginate
9
- username: <%= ENV["MYSQL_USER"] || "root" %>
10
- encoding: utf8
11
- <% if ENV["MYSQL_PORT"] %>
12
- host: <%= ENV["MYSQL_HOST"] %>
13
- port: <%= ENV["MYSQL_PORT"] %>
14
- <% elsif File.exist?("/var/run/mysql5/mysqld.sock") %>
15
- host: localhost
16
- socket: /var/run/mysql5/mysqld.sock
17
- <% elsif File.exist? "/tmp/mysql.sock" %>
18
- host: localhost
19
- socket: /tmp/mysql.sock
20
- <% end %>
21
-
22
- postgres:
23
- adapter: postgresql
24
- database: will_paginate
25
- min_messages: warning
26
- username: <%= ENV["POSTGRES_USER"] %>
27
- password: <%= ENV["POSTGRES_PASSWORD"] %>
28
- host: <%= ENV["POSTGRES_HOST"] %>
29
- port: <%= ENV["POSTGRES_PORT"] %>