will_paginate 3.1.5 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +8 -11
  3. data/lib/will_paginate/active_record.rb +7 -11
  4. data/lib/will_paginate/deprecation.rb +2 -2
  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 +2 -0
  8. data/lib/will_paginate/page_number.rb +7 -11
  9. data/lib/will_paginate/railtie.rb +3 -4
  10. data/lib/will_paginate/version.rb +3 -3
  11. data/lib/will_paginate/view_helpers/action_view.rb +8 -4
  12. data/lib/will_paginate/view_helpers/hanami.rb +41 -0
  13. data/lib/will_paginate/view_helpers/link_renderer.rb +19 -14
  14. data/lib/will_paginate.rb +0 -12
  15. metadata +17 -48
  16. data/lib/will_paginate/data_mapper.rb +0 -100
  17. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  18. data/spec/collection_spec.rb +0 -139
  19. data/spec/console +0 -12
  20. data/spec/console_fixtures.rb +0 -28
  21. data/spec/database.yml +0 -29
  22. data/spec/fake_rubygems.rb +0 -18
  23. data/spec/finders/active_record_spec.rb +0 -418
  24. data/spec/finders/activerecord_test_connector.rb +0 -132
  25. data/spec/finders/data_mapper_spec.rb +0 -116
  26. data/spec/finders/data_mapper_test_connector.rb +0 -54
  27. data/spec/finders/mongoid_spec.rb +0 -140
  28. data/spec/finders/sequel_spec.rb +0 -67
  29. data/spec/finders/sequel_test_connector.rb +0 -15
  30. data/spec/fixtures/admin.rb +0 -3
  31. data/spec/fixtures/developer.rb +0 -9
  32. data/spec/fixtures/developers_projects.yml +0 -13
  33. data/spec/fixtures/project.rb +0 -13
  34. data/spec/fixtures/projects.yml +0 -6
  35. data/spec/fixtures/replies.yml +0 -29
  36. data/spec/fixtures/reply.rb +0 -8
  37. data/spec/fixtures/schema.rb +0 -38
  38. data/spec/fixtures/topic.rb +0 -8
  39. data/spec/fixtures/topics.yml +0 -30
  40. data/spec/fixtures/user.rb +0 -2
  41. data/spec/fixtures/users.yml +0 -35
  42. data/spec/matchers/deprecation_matcher.rb +0 -27
  43. data/spec/matchers/phrase_matcher.rb +0 -19
  44. data/spec/matchers/query_count_matcher.rb +0 -36
  45. data/spec/page_number_spec.rb +0 -83
  46. data/spec/per_page_spec.rb +0 -41
  47. data/spec/spec_helper.rb +0 -46
  48. data/spec/view_helpers/action_view_spec.rb +0 -468
  49. data/spec/view_helpers/base_spec.rb +0 -143
  50. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  51. data/spec/view_helpers/view_example_group.rb +0 -146
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5b9c92a0ce3f9e697334ea1bf11c0b57bdfd9fe2
4
- data.tar.gz: b2794b2de86ceaa34f86d06f2c1952484b5409f9
2
+ SHA256:
3
+ metadata.gz: 147ccc8d263975ac53363e03b1ac0e8721a0d2dc3384541b12396335063dbdd5
4
+ data.tar.gz: 5dc1129aadadf3d861c99cebd6b664b9becf1113ec97f3ae6c2dfb58531b570d
5
5
  SHA512:
6
- metadata.gz: fe7a7e48c35bda6cd6648f5243f3992ebe576f586afd5d140066fa05ecdd83862681245f44e554f5483e5dc4fe9f957e3b84b6208cc91a8e1dd1804c8593a49b
7
- data.tar.gz: 5c388ced4fd0b8ad3da2ce6c5e9b2323b4cff1b950fdf3b35cc6e148b1e12509e8b6c0b83156b483d1a732ce4fe2497a4c09553b2650775cc922803699bf4347
6
+ metadata.gz: 3ebb1d0564768b4380bd06fceb2f9284065c292812a26c521b401b911bb7561dde76a90ce50024a39a22b63a40fc6f20ebac43364fc989f68bca70f57f39aa20
7
+ data.tar.gz: f021cb3e9fbbc704439323d41e93897f40d536fc2adfa5ee9c9101e56e4f1a65e1ad0c9cb268ed1a4f3d1eb1d485dbe1bf5d4fd7d082a1bef2c914cbb4970970
data/README.md CHANGED
@@ -1,25 +1,23 @@
1
1
  # will_paginate
2
2
 
3
- will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Merb, DataMapper and Sequel.
4
-
5
- Installation:
3
+ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, and Sequel.
6
4
 
7
5
  ``` ruby
8
- ## Gemfile for Rails 3+, Sinatra, and Merb
9
- gem 'will_paginate', '~> 3.1.0'
6
+ gem 'will_paginate', '~> 4.0'
10
7
  ```
11
8
 
12
9
  See [installation instructions][install] on the wiki for more info.
13
10
 
11
+ ℹ️ will_paginate is now in _maintenance mode_ and it will not be receiving new features. [See alternatives](https://www.ruby-toolbox.com/categories/pagination)
14
12
 
15
13
  ## Basic will_paginate use
16
14
 
17
15
  ``` ruby
18
16
  ## perform a paginated query:
19
- @posts = Post.paginate(:page => params[:page])
17
+ @posts = Post.paginate(page: params[:page])
20
18
 
21
19
  # or, use an explicit "per page" limit:
22
- Post.paginate(:page => params[:page], :per_page => 30)
20
+ Post.paginate(page: params[:page], per_page: 30)
23
21
 
24
22
  ## render page links in the view:
25
23
  <%= will_paginate @posts %>
@@ -43,19 +41,18 @@ New in Active Record 3:
43
41
 
44
42
  ``` ruby
45
43
  # paginate in Active Record now returns a Relation
46
- Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')
44
+ Post.where(published: true).paginate(page: params[:page]).order(id: :desc)
47
45
 
48
46
  # the new, shorter page() method
49
- Post.page(params[:page]).order('created_at DESC')
47
+ Post.page(params[:page]).order(created_at: :desc)
50
48
  ```
51
49
 
52
- See [the wiki][wiki] for more documentation. [Ask on the group][group] if you have usage questions. [Report bugs][issues] on GitHub.
50
+ See [the wiki][wiki] for more documentation. [Report bugs][issues] on GitHub.
53
51
 
54
52
  Happy paginating.
55
53
 
56
54
 
57
55
  [wiki]: https://github.com/mislav/will_paginate/wiki
58
56
  [install]: https://github.com/mislav/will_paginate/wiki/Installation "will_paginate installation"
59
- [group]: http://groups.google.com/group/will_paginate "will_paginate discussion and support group"
60
57
  [issues]: https://github.com/mislav/will_paginate/issues
61
58
  [css]: http://mislav.github.io/will_paginate/
@@ -83,7 +83,10 @@ module WillPaginate
83
83
  excluded = [:order, :limit, :offset, :reorder]
84
84
  excluded << :includes unless eager_loading?
85
85
  rel = self.except(*excluded)
86
- column_name = (select_for_count(rel) || :all)
86
+ column_name = if rel.select_values.present?
87
+ select = rel.select_values.join(", ")
88
+ select if select !~ /[,*]/
89
+ end || :all
87
90
  rel.count(column_name)
88
91
  else
89
92
  super(*args)
@@ -102,9 +105,7 @@ module WillPaginate
102
105
  # overloaded to be pagination-aware
103
106
  def empty?
104
107
  if !loaded? and offset_value
105
- result = count
106
- result = result.size if result.respond_to?(:size) and !result.is_a?(Integer)
107
- result <= offset_value
108
+ total_entries <= offset_value
108
109
  else
109
110
  super
110
111
  end
@@ -136,13 +137,6 @@ module WillPaginate
136
137
  other.total_entries = nil if defined? @total_entries_queried
137
138
  other
138
139
  end
139
-
140
- def select_for_count(rel)
141
- if rel.select_values.present?
142
- select = rel.select_values.join(", ")
143
- select if select !~ /[,*]/
144
- end
145
- end
146
140
  end
147
141
 
148
142
  module Pagination
@@ -216,6 +210,8 @@ module WillPaginate
216
210
  WHERE rownum <= #{pager.offset + pager.per_page}
217
211
  ) WHERE rnum >= #{pager.offset}
218
212
  SQL
213
+ elsif (self.connection.adapter_name =~ /^sqlserver/i)
214
+ query << " OFFSET #{pager.offset} ROWS FETCH NEXT #{pager.per_page} ROWS ONLY"
219
215
  else
220
216
  query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
221
217
  end
@@ -31,8 +31,8 @@ module WillPaginate::Deprecation
31
31
  super
32
32
  end
33
33
 
34
- def deprecate_key(*keys)
35
- message = block_given? ? Proc.new : keys.pop
34
+ def deprecate_key(*keys, &block)
35
+ message = block_given? ? block : keys.pop
36
36
  Array(keys).each { |key| @deprecated[key] = message }
37
37
  end
38
38
 
@@ -8,11 +8,11 @@ module WillPaginate
8
8
  Dir["#{locale_dir}/*.{rb,yml}"]
9
9
  end
10
10
 
11
- def will_paginate_translate(keys, options = {})
11
+ def will_paginate_translate(keys, options = {}, &block)
12
12
  if defined? ::I18n
13
13
  defaults = Array(keys).dup
14
- defaults << Proc.new if block_given?
15
- ::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
14
+ defaults << block if block_given?
15
+ ::I18n.translate(defaults.shift, **options.merge(:default => defaults, :scope => :will_paginate))
16
16
  else
17
17
  key = Array === keys ? keys.first : keys
18
18
  yield key, options
@@ -1,8 +1,12 @@
1
1
  en:
2
2
  will_paginate:
3
3
  previous_label: "&#8592; Previous"
4
+ previous_aria_label: "Previous page"
4
5
  next_label: "Next &#8594;"
6
+ next_aria_label: "Next page"
5
7
  page_gap: "&hellip;"
8
+ container_aria_label: "Pagination"
9
+ page_aria_label: "Page %{page}"
6
10
 
7
11
  page_entries_info:
8
12
  single_page:
@@ -8,6 +8,8 @@ module WillPaginate
8
8
  extend CollectionMethods
9
9
  @current_page = WillPaginate::PageNumber(options[:page] || @current_page || 1)
10
10
  @page_multiplier = current_page - 1
11
+ @total_entries = options.delete(:total_entries)
12
+
11
13
  pp = (options[:per_page] || per_page || WillPaginate.per_page).to_i
12
14
  limit(pp).skip(@page_multiplier * pp)
13
15
  end
@@ -1,4 +1,3 @@
1
- require 'delegate'
2
1
  require 'forwardable'
3
2
 
4
3
  module WillPaginate
@@ -6,7 +5,7 @@ module WillPaginate
6
5
  module InvalidPage; end
7
6
 
8
7
  # integer representing a page number
9
- class PageNumber < DelegateClass(Integer)
8
+ class PageNumber < Numeric
10
9
  # a value larger than this is not supported in SQL queries
11
10
  BIGINT = 9223372036854775807
12
11
 
@@ -18,13 +17,17 @@ module WillPaginate
18
17
  raise RangeError, "invalid #{name}: #{value.inspect}"
19
18
  end
20
19
  @name = name
21
- super(value)
20
+ @value = value
22
21
  rescue ArgumentError, TypeError, RangeError => error
23
22
  error.extend InvalidPage
24
23
  raise error
25
24
  end
26
25
 
27
- alias_method :to_i, :__getobj__
26
+ def to_i
27
+ @value
28
+ end
29
+
30
+ def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/, :to_json
28
31
 
29
32
  def inspect
30
33
  "#{@name} #{to_i}"
@@ -40,13 +43,6 @@ module WillPaginate
40
43
  alias is_a? kind_of?
41
44
  end
42
45
 
43
- # Ultrahax: makes `Fixnum === current_page` checks pass
44
- Numeric.extend Module.new {
45
- def ===(obj)
46
- obj.instance_of? PageNumber or super
47
- end
48
- }
49
-
50
46
  # An idemptotent coercion method
51
47
  def self.PageNumber(value, name = 'page')
52
48
  case value
@@ -1,4 +1,3 @@
1
- require 'will_paginate'
2
1
  require 'will_paginate/page_number'
3
2
  require 'will_paginate/collection'
4
3
  require 'will_paginate/i18n'
@@ -39,7 +38,7 @@ module WillPaginate
39
38
  end
40
39
  def status_code_with_paginate(exception = @exception)
41
40
  actual_exception = if exception.respond_to?(:cause)
42
- exception.cause
41
+ exception.cause || exception
43
42
  elsif exception.respond_to?(:original_exception)
44
43
  exception.original_exception
45
44
  else
@@ -60,11 +59,11 @@ module WillPaginate
60
59
  end
61
60
 
62
61
  module ControllerRescuePatch
63
- def rescue_from(*args, &block)
62
+ def rescue_from(*args, **kwargs, &block)
64
63
  if idx = args.index(WillPaginate::InvalidPage)
65
64
  args[idx] = args[idx].name
66
65
  end
67
- super(*args, &block)
66
+ super(*args, **kwargs, &block)
68
67
  end
69
68
  end
70
69
  end
@@ -1,8 +1,8 @@
1
1
  module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 1
5
- TINY = 5
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -43,7 +43,7 @@ module WillPaginate
43
43
  # Wrapper for rendering pagination links at both top and bottom of a block
44
44
  # of content.
45
45
  #
46
- # <% paginated_section @posts do %>
46
+ # <%= paginated_section @posts do %>
47
47
  # <ol id="posts">
48
48
  # <% for post in @posts %>
49
49
  # <li> ... </li>
@@ -80,7 +80,7 @@ module WillPaginate
80
80
  defaults = nil
81
81
  key = keys
82
82
  end
83
- translate(key, options.merge(:default => defaults, :scope => :will_paginate))
83
+ translate(key, **options.merge(:default => defaults, :scope => :will_paginate))
84
84
  else
85
85
  super
86
86
  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
@@ -0,0 +1,41 @@
1
+ require 'hanami/view'
2
+ require 'will_paginate/view_helpers'
3
+ require 'will_paginate/view_helpers/link_renderer'
4
+
5
+ module WillPaginate
6
+ module Hanami
7
+ module Helpers
8
+ include ViewHelpers
9
+
10
+ def will_paginate(collection, options = {}) #:nodoc:
11
+ options = options.merge(:renderer => LinkRenderer) unless options[:renderer]
12
+ str = super(collection, options)
13
+ str && raw(str)
14
+ end
15
+ end
16
+
17
+ class LinkRenderer < ViewHelpers::LinkRenderer
18
+ protected
19
+
20
+ def url(page)
21
+ str = File.join(request_env['SCRIPT_NAME'].to_s, request_env['PATH_INFO'])
22
+ params = request_env['rack.request.query_hash'].merge(param_name.to_s => page.to_s)
23
+ params.update @options[:params] if @options[:params]
24
+ str << '?' << build_query(params)
25
+ end
26
+
27
+ def request_env
28
+ @template.params.env
29
+ end
30
+
31
+ def build_query(params)
32
+ Rack::Utils.build_nested_query params
33
+ end
34
+ end
35
+
36
+ def self.included(base)
37
+ base.include Helpers
38
+ end
39
+
40
+ end
41
+ end
@@ -24,7 +24,7 @@ module WillPaginate
24
24
  # method as you see fit.
25
25
  def to_html
26
26
  html = pagination.map do |item|
27
- item.is_a?(Fixnum) ?
27
+ item.is_a?(Integer) ?
28
28
  page_number(item) :
29
29
  send(item)
30
30
  end.join(@options[:link_separator])
@@ -35,16 +35,20 @@ module WillPaginate
35
35
  # Returns the subset of +options+ this instance was initialized with that
36
36
  # represent HTML attributes for the container element of pagination links.
37
37
  def container_attributes
38
- @container_attributes ||= @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
38
+ @container_attributes ||= {
39
+ :role => 'navigation',
40
+ :"aria-label" => @template.will_paginate_translate(:container_aria_label) { 'Pagination' }
41
+ }.update @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
39
42
  end
40
43
 
41
44
  protected
42
45
 
43
46
  def page_number(page)
47
+ aria_label = @template.will_paginate_translate(:page_aria_label, :page => page.to_i) { "Page #{page}" }
44
48
  if page == current_page
45
- tag(:em, page, :class => 'current')
49
+ tag(:em, page, :class => 'current', :"aria-label" => aria_label, :"aria-current" => 'page')
46
50
  else
47
- link(page, page, :rel => rel_value(page))
51
+ link(page, page, :rel => rel_value(page), :"aria-label" => aria_label)
48
52
  end
49
53
  end
50
54
 
@@ -55,19 +59,21 @@ module WillPaginate
55
59
 
56
60
  def previous_page
57
61
  num = @collection.current_page > 1 && @collection.current_page - 1
58
- 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)
59
64
  end
60
65
 
61
66
  def next_page
62
67
  num = @collection.current_page < total_pages && @collection.current_page + 1
63
- 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)
64
70
  end
65
71
 
66
- def previous_or_next_page(page, text, classname)
72
+ def previous_or_next_page(page, text, classname, aria_label = nil)
67
73
  if page
68
- link(text, page, :class => classname)
74
+ link(text, page, :class => classname, :'aria-label' => aria_label)
69
75
  else
70
- tag(:span, text, :class => classname + ' disabled')
76
+ tag(:span, text, :class => classname + ' disabled', :'aria-label' => aria_label)
71
77
  end
72
78
  end
73
79
 
@@ -88,7 +94,7 @@ module WillPaginate
88
94
  end
89
95
 
90
96
  def link(text, target, attributes = {})
91
- if target.is_a? Fixnum
97
+ if target.is_a?(Integer)
92
98
  attributes[:rel] = rel_value(target)
93
99
  target = url(target)
94
100
  end
@@ -97,13 +103,12 @@ module WillPaginate
97
103
  end
98
104
 
99
105
  def tag(name, value, attributes = {})
100
- string_attributes = attributes.inject('') do |attrs, pair|
106
+ string_attributes = attributes.map do |pair|
101
107
  unless pair.last.nil?
102
- attrs << %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
108
+ %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
103
109
  end
104
- attrs
105
110
  end
106
- "<#{name}#{string_attributes}>#{value}</#{name}>"
111
+ "<#{name}#{string_attributes.compact.join("")}>#{value}</#{name}>"
107
112
  end
108
113
 
109
114
  def rel_value(page)
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.1.5
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Marohnić
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-15 00:00:00.000000000 Z
11
+ date: 2024-06-10 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 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
@@ -39,49 +38,20 @@ files:
39
38
  - lib/will_paginate/version.rb
40
39
  - lib/will_paginate/view_helpers.rb
41
40
  - lib/will_paginate/view_helpers/action_view.rb
41
+ - lib/will_paginate/view_helpers/hanami.rb
42
42
  - lib/will_paginate/view_helpers/link_renderer.rb
43
43
  - lib/will_paginate/view_helpers/link_renderer_base.rb
44
- - lib/will_paginate/view_helpers/merb.rb
45
44
  - lib/will_paginate/view_helpers/sinatra.rb
46
- - spec/collection_spec.rb
47
- - spec/console
48
- - spec/console_fixtures.rb
49
- - spec/database.yml
50
- - spec/fake_rubygems.rb
51
- - spec/finders/active_record_spec.rb
52
- - spec/finders/activerecord_test_connector.rb
53
- - spec/finders/data_mapper_spec.rb
54
- - spec/finders/data_mapper_test_connector.rb
55
- - spec/finders/mongoid_spec.rb
56
- - spec/finders/sequel_spec.rb
57
- - spec/finders/sequel_test_connector.rb
58
- - spec/fixtures/admin.rb
59
- - spec/fixtures/developer.rb
60
- - spec/fixtures/developers_projects.yml
61
- - spec/fixtures/project.rb
62
- - spec/fixtures/projects.yml
63
- - spec/fixtures/replies.yml
64
- - spec/fixtures/reply.rb
65
- - spec/fixtures/schema.rb
66
- - spec/fixtures/topic.rb
67
- - spec/fixtures/topics.yml
68
- - spec/fixtures/user.rb
69
- - spec/fixtures/users.yml
70
- - spec/matchers/deprecation_matcher.rb
71
- - spec/matchers/phrase_matcher.rb
72
- - spec/matchers/query_count_matcher.rb
73
- - spec/page_number_spec.rb
74
- - spec/per_page_spec.rb
75
- - spec/spec_helper.rb
76
- - spec/view_helpers/action_view_spec.rb
77
- - spec/view_helpers/base_spec.rb
78
- - spec/view_helpers/link_renderer_base_spec.rb
79
- - spec/view_helpers/view_example_group.rb
80
- homepage: https://github.com/mislav/will_paginate/wiki
45
+ homepage: https://github.com/mislav/will_paginate
81
46
  licenses:
82
47
  - MIT
83
- metadata: {}
84
- post_install_message:
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.1
51
+ documentation_uri: https://www.rubydoc.info/gems/will_paginate/4.0.1
52
+ source_code_uri: https://github.com/mislav/will_paginate/tree/v4.0.1
53
+ wiki_uri: https://github.com/mislav/will_paginate/wiki
54
+ post_install_message:
85
55
  rdoc_options:
86
56
  - "--main"
87
57
  - README.md
@@ -92,16 +62,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
62
  requirements:
93
63
  - - ">="
94
64
  - !ruby/object:Gem::Version
95
- version: '0'
65
+ version: '2.0'
96
66
  required_rubygems_version: !ruby/object:Gem::Requirement
97
67
  requirements:
98
68
  - - ">="
99
69
  - !ruby/object:Gem::Version
100
70
  version: '0'
101
71
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.5.1
104
- signing_key:
72
+ rubygems_version: 3.5.4
73
+ signing_key:
105
74
  specification_version: 4
106
75
  summary: Pagination plugin for web frameworks and other apps
107
76
  test_files: []
@@ -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
-