will_paginate 3.1.8 → 3.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7e2f95ebf19f3cb09fca66deb17fbc5cafe985b102642b40ee9ca330f8228c7
4
- data.tar.gz: f9eecffdda2bdf6a08b9ff44090025725277898bb3410fc963c390c5e2e73724
3
+ metadata.gz: 751b354f97d844f6679cec31ce90298e6d6ff77217446d77e729421caa52c8da
4
+ data.tar.gz: 5a18d970f3e6b0ca1e1949aa3eb14856ee80f1feea4b919f808e5d02f623bf58
5
5
  SHA512:
6
- metadata.gz: 0aae93122e8e72caff23c32c6332a959dabad21f72db562f5098dc5bb707197be11afb63eaf82a290a32a34fe3808a9eff1b3c5550e3f51c0f594d4de5abc3f4
7
- data.tar.gz: fd4e932326cea4561cf7fffba6a1a643481b00d37f7b274067ccc54be03fc820512a52fbba1075c52ff30cec1c91e3fb071d78e8754bb9d9ca19327b7bc6ad7c
6
+ metadata.gz: 1196350bf1e40de517c21fd8f085df09c682709894d1edd688402d33fab8d15c2b9af91b84c0df5dc5aad2eda9e6e8fbc006474b8ee3829af13879a6c66f24ed
7
+ data.tar.gz: 5ef9ce7f70c5cc3ba0b1e024e4c4cfeb8e8afbb20cea2b983abfb31cb29eb850931b652f68d95579acaa5b69b71ffdfc384716640e4168e49c108fe3a525441d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # will_paginate
2
2
 
3
- will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Merb, DataMapper and Sequel.
3
+ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, Merb, DataMapper and Sequel.
4
4
 
5
5
  Installation:
6
6
 
@@ -3,6 +3,8 @@ en:
3
3
  previous_label: "← Previous"
4
4
  next_label: "Next →"
5
5
  page_gap: "…"
6
+ container_aria_label: "Pagination"
7
+ page_aria_label: "Page %{page}"
6
8
 
7
9
  page_entries_info:
8
10
  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
@@ -6,7 +6,7 @@ module WillPaginate
6
6
  module InvalidPage; end
7
7
 
8
8
  # integer representing a page number
9
- class PageNumber < DelegateClass(Integer)
9
+ class PageNumber < Numeric
10
10
  # a value larger than this is not supported in SQL queries
11
11
  BIGINT = 9223372036854775807
12
12
 
@@ -18,13 +18,17 @@ module WillPaginate
18
18
  raise RangeError, "invalid #{name}: #{value.inspect}"
19
19
  end
20
20
  @name = name
21
- super(value)
21
+ @value = value
22
22
  rescue ArgumentError, TypeError, RangeError => error
23
23
  error.extend InvalidPage
24
24
  raise error
25
25
  end
26
26
 
27
- alias_method :to_i, :__getobj__
27
+ def to_i
28
+ @value
29
+ end
30
+
31
+ def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/
28
32
 
29
33
  def inspect
30
34
  "#{@name} #{to_i}"
@@ -40,13 +44,6 @@ module WillPaginate
40
44
  alias is_a? kind_of?
41
45
  end
42
46
 
43
- # Ultrahax: makes `Integer === current_page` checks pass
44
- Numeric.extend Module.new {
45
- def ===(obj)
46
- obj.instance_of? PageNumber or super
47
- end
48
- }
49
-
50
47
  # An idemptotent coercion method
51
48
  def self.PageNumber(value, name = 'page')
52
49
  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
@@ -1,8 +1,8 @@
1
1
  module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
- MINOR = 1
5
- TINY = 8
4
+ MINOR = 2
5
+ TINY = 0
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>
@@ -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
@@ -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
 
@@ -37,7 +37,6 @@ describe WillPaginate::PageNumber do
37
37
 
38
38
  it "passes the Numeric=== type check" do |variable|
39
39
  (Numeric === num).should be
40
- (Integer === num).should be
41
40
  end
42
41
  end
43
42
 
@@ -14,7 +14,8 @@ Routes.draw do
14
14
  get 'ibocorp(/:page)' => 'ibocorp#index',
15
15
  :constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
16
16
 
17
- get ':controller(/:action(/:id(.:format)))'
17
+ get 'foo/bar' => 'foo#bar'
18
+ get 'baz/list' => 'baz#list'
18
19
  end
19
20
 
20
21
  describe WillPaginate::ActionView do
@@ -38,7 +39,14 @@ describe WillPaginate::ActionView do
38
39
  attr_reader :assigns, :controller, :request
39
40
 
40
41
  def render(locals)
41
- @view = ActionView::Base.new([], @assigns, @controller)
42
+ lookup_context = []
43
+ if defined? ActionView::LookupContext
44
+ lookup_context = ActionView::LookupContext.new(lookup_context)
45
+ end
46
+
47
+ klass = ActionView::Base
48
+ klass = klass.with_empty_template_cache if klass.respond_to?(:with_empty_template_cache)
49
+ @view = klass.new(lookup_context, @assigns, @controller)
42
50
  @view.request = @request
43
51
  @view.singleton_class.send(:include, @controller._routes.url_helpers)
44
52
  @view.render(:inline => @template, :locals => locals)
@@ -120,16 +128,20 @@ describe WillPaginate::ActionView do
120
128
  it "should match expected markup" do
121
129
  paginate
122
130
  expected = <<-HTML
123
- <div class="pagination"><span class="previous_page disabled">&#8592; Previous</span>
124
- <em class="current">1</em>
125
- <a href="/foo/bar?page=2" rel="next">2</a>
126
- <a href="/foo/bar?page=3">3</a>
131
+ <div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled">&#8592; Previous</span>
132
+ <em class="current" aria-label="Page 1" aria-current="page">1</em>
133
+ <a href="/foo/bar?page=2" aria-label="Page 2" rel="next">2</a>
134
+ <a href="/foo/bar?page=3" aria-label="Page 3">3</a>
127
135
  <a href="/foo/bar?page=2" class="next_page" rel="next">Next &#8594;</a></div>
128
136
  HTML
129
137
  expected.strip!.gsub!(/\s{2,}/, ' ')
130
- expected_dom = parse_html_document(expected).root
138
+ expected_dom = parse_html_document(expected)
131
139
 
132
- html_document.root.should == expected_dom
140
+ if expected_dom.respond_to?(:canonicalize)
141
+ html_document.canonicalize.should == expected_dom.canonicalize
142
+ else
143
+ html_document.root.should == expected_dom.root
144
+ end
133
145
  end
134
146
 
135
147
  it "should output escaped URLs" do
@@ -50,7 +50,7 @@ module ViewExampleGroup
50
50
  end
51
51
 
52
52
  def parse_html_document(html)
53
- @html_document ||= if defined?(Rails::Dom::Testing::Assertions)
53
+ if defined?(Rails::Dom::Testing::Assertions)
54
54
  Nokogiri::HTML::Document.parse(html)
55
55
  else
56
56
  HTML::Document.new(html, true, false)
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.8
4
+ version: 3.2.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: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2019-10-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: will_paginate provides a simple API for performing paginated queries
14
14
  with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
15
- links in Rails, Sinatra and Merb web apps.
15
+ links in Rails, Sinatra, Hanami, and Merb web apps.
16
16
  email: mislav.marohnic@gmail.com
17
17
  executables: []
18
18
  extensions: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/will_paginate/version.rb
40
40
  - lib/will_paginate/view_helpers.rb
41
41
  - lib/will_paginate/view_helpers/action_view.rb
42
+ - lib/will_paginate/view_helpers/hanami.rb
42
43
  - lib/will_paginate/view_helpers/link_renderer.rb
43
44
  - lib/will_paginate/view_helpers/link_renderer_base.rb
44
45
  - lib/will_paginate/view_helpers/merb.rb
@@ -77,10 +78,15 @@ files:
77
78
  - spec/view_helpers/base_spec.rb
78
79
  - spec/view_helpers/link_renderer_base_spec.rb
79
80
  - spec/view_helpers/view_example_group.rb
80
- homepage: https://github.com/mislav/will_paginate/wiki
81
+ homepage: https://github.com/mislav/will_paginate
81
82
  licenses:
82
83
  - MIT
83
- metadata: {}
84
+ metadata:
85
+ bug_tracker_uri: https://github.com/mislav/will_paginate/issues
86
+ changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v3.2.0
87
+ documentation_uri: https://www.rubydoc.info/gems/will_paginate/3.2.0
88
+ source_code_uri: https://github.com/mislav/will_paginate/tree/v3.2.0
89
+ wiki_uri: https://github.com/mislav/will_paginate/wiki
84
90
  post_install_message:
85
91
  rdoc_options:
86
92
  - "--main"