kaminari-core 1.0.1 → 1.1.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 +5 -5
- data/app/views/kaminari/_paginator.html.erb +1 -1
- data/lib/generators/kaminari/views_generator.rb +2 -0
- data/lib/kaminari/config.rb +26 -14
- data/lib/kaminari/core/version.rb +1 -1
- data/lib/kaminari/helpers/helper_methods.rb +3 -1
- data/lib/kaminari/helpers/paginator.rb +2 -5
- data/lib/kaminari/helpers/tags.rb +27 -1
- data/lib/kaminari/models/configuration_methods.rb +4 -1
- data/lib/kaminari/models/page_scope_methods.rb +6 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 13bfdf7c93e9183a36d3e99699eee59895948472c66d31f97bbb99a768ec89d0
         | 
| 4 | 
            +
              data.tar.gz: 44c167d6cfe80ecca307ee3a31ac3ebbd8766c09b259686442cf22d4968df9d3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 89492adf61154a7eeabd3eac4e4429dc82802596de85d04066f76523f5ca1b6a89d493814b30537dd29e245a2d92f88d263688fb0ed3ce7cdbb979d1ee2ccf71
         | 
| 7 | 
            +
              data.tar.gz: 25cc4d4c811c80e15cd271f49dd0de85ba83749a44411f3ce64de441b32de01f1122448e7d939831eb42cb5ba3269e4953b021a4f8abb29a949e717ee098c67b
         | 
| @@ -7,7 +7,7 @@ | |
| 7 7 | 
             
                paginator:     the paginator that renders the pagination tags inside
         | 
| 8 8 | 
             
            -%>
         | 
| 9 9 | 
             
            <%= paginator.render do -%>
         | 
| 10 | 
            -
              <nav class="pagination">
         | 
| 10 | 
            +
              <nav class="pagination" role="navigation" aria-label="pager">
         | 
| 11 11 | 
             
                <%= first_page_tag unless current_page.first? %>
         | 
| 12 12 | 
             
                <%= prev_page_tag unless current_page.first? %>
         | 
| 13 13 | 
             
                <% each_page do |page| -%>
         | 
| @@ -110,6 +110,8 @@ BANNER | |
| 110 110 | 
             
                end
         | 
| 111 111 |  | 
| 112 112 | 
             
                module GitHubApiHelper
         | 
| 113 | 
            +
                  require 'open-uri'
         | 
| 114 | 
            +
             | 
| 113 115 | 
             
                  def get_files_in_master
         | 
| 114 116 | 
             
                    master_tree_sha = open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
         | 
| 115 117 | 
             
                      ActiveSupport::JSON.decode(json.read)['object']['sha']
         | 
    
        data/lib/kaminari/config.rb
    CHANGED
    
    | @@ -1,28 +1,40 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            -
            require 'active_support/configurable'
         | 
| 3 2 |  | 
| 4 3 | 
             
            module Kaminari
         | 
| 5 4 | 
             
              # Configures global settings for Kaminari
         | 
| 6 5 | 
             
              #   Kaminari.configure do |config|
         | 
| 7 6 | 
             
              #     config.default_per_page = 10
         | 
| 8 7 | 
             
              #   end
         | 
| 9 | 
            -
               | 
| 8 | 
            +
              class << self
         | 
| 9 | 
            +
                def configure
         | 
| 10 | 
            +
                  yield config
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def config
         | 
| 14 | 
            +
                  @_config ||= Config.new
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              class Config
         | 
| 19 | 
            +
                attr_accessor :default_per_page, :max_per_page, :window, :outer_window, :left, :right, :page_method_name, :max_pages, :params_on_first_page
         | 
| 20 | 
            +
                attr_writer :param_name
         | 
| 10 21 |  | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            +
                def initialize
         | 
| 23 | 
            +
                  @default_per_page = 25
         | 
| 24 | 
            +
                  @max_per_page = nil
         | 
| 25 | 
            +
                  @window = 4
         | 
| 26 | 
            +
                  @outer_window = 0
         | 
| 27 | 
            +
                  @left = 0
         | 
| 28 | 
            +
                  @right = 0
         | 
| 29 | 
            +
                  @page_method_name = :page
         | 
| 30 | 
            +
                  @param_name = :page
         | 
| 31 | 
            +
                  @max_pages = nil
         | 
| 32 | 
            +
                  @params_on_first_page = false
         | 
| 33 | 
            +
                end
         | 
| 22 34 |  | 
| 23 35 | 
             
                # If param_name was given as a callable object, call it when returning
         | 
| 24 36 | 
             
                def param_name
         | 
| 25 | 
            -
                   | 
| 37 | 
            +
                  @param_name.respond_to?(:call) ? @param_name.call : @param_name
         | 
| 26 38 | 
             
                end
         | 
| 27 39 | 
             
              end
         | 
| 28 40 | 
             
            end
         | 
| @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Kaminari
         | 
| 2 4 | 
             
              module Helpers
         | 
| 3 5 | 
             
                module HelperMethods
         | 
| @@ -99,7 +101,7 @@ module Kaminari | |
| 99 101 | 
             
                  #   #-> Displaying items 6 - 10 of 26 in total
         | 
| 100 102 | 
             
                  def page_entries_info(collection, entry_name: nil)
         | 
| 101 103 | 
             
                    entry_name = if entry_name
         | 
| 102 | 
            -
                                   entry_name.pluralize(collection.size)
         | 
| 104 | 
            +
                                   entry_name.pluralize(collection.size, I18n.locale)
         | 
| 103 105 | 
             
                                 else
         | 
| 104 106 | 
             
                                   collection.entry_name(count: collection.size).downcase
         | 
| 105 107 | 
             
                                 end
         | 
| @@ -6,11 +6,8 @@ module Kaminari | |
| 6 6 | 
             
              module Helpers
         | 
| 7 7 | 
             
                # The main container tag
         | 
| 8 8 | 
             
                class Paginator < Tag
         | 
| 9 | 
            -
                  def initialize(template, window: nil, outer_window:  | 
| 10 | 
            -
                    outer_window  | 
| 11 | 
            -
                    left ||= Kaminari.config.left
         | 
| 12 | 
            -
                    right ||= Kaminari.config.right
         | 
| 13 | 
            -
                    @window_options = {window: window || inner_window || Kaminari.config.window, left: left.zero? ? outer_window : left, right: right.zero? ? outer_window : right}
         | 
| 9 | 
            +
                  def initialize(template, window: nil, outer_window: Kaminari.config.outer_window, left: Kaminari.config.left, right: Kaminari.config.right, inner_window: Kaminari.config.window, **options) #:nodoc:
         | 
| 10 | 
            +
                    @window_options = {window: window || inner_window, left: left.zero? ? outer_window : left, right: right.zero? ? outer_window : right}
         | 
| 14 11 |  | 
| 15 12 | 
             
                    @template, @options, @theme, @views_prefix, @last = template, options, options[:theme], options[:views_prefix], nil
         | 
| 16 13 | 
             
                    @window_options.merge! @options
         | 
| @@ -24,7 +24,7 @@ module Kaminari | |
| 24 24 | 
             
                    @params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
         | 
| 25 25 | 
             
                    @params = @params.with_indifferent_access
         | 
| 26 26 | 
             
                    @params.except!(*PARAM_KEY_BLACKLIST)
         | 
| 27 | 
            -
                    @params. | 
| 27 | 
            +
                    @params.reverse_merge! params
         | 
| 28 28 | 
             
                  end
         | 
| 29 29 |  | 
| 30 30 | 
             
                  def to_s(locals = {}) #:nodoc:
         | 
| @@ -117,6 +117,19 @@ module Kaminari | |
| 117 117 | 
             
                # The "previous" page of the current page
         | 
| 118 118 | 
             
                class PrevPage < Tag
         | 
| 119 119 | 
             
                  include Link
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                  # TODO: Remove this initializer before 1.3.0.
         | 
| 122 | 
            +
                  def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix: nil, **options) #:nodoc:
         | 
| 123 | 
            +
                    # params in Rails 5 may not be a Hash either,
         | 
| 124 | 
            +
                    # so it must be converted to a Hash to be merged into @params
         | 
| 125 | 
            +
                    if params && params.respond_to?(:to_unsafe_h)
         | 
| 126 | 
            +
                      ActiveSupport::Deprecation.warn 'Explicitly passing params to helpers could be omitted.'
         | 
| 127 | 
            +
                      params = params.to_unsafe_h
         | 
| 128 | 
            +
                    end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                    super(template, params: params, param_name: param_name, theme: theme, views_prefix: views_prefix, **options)
         | 
| 131 | 
            +
                  end
         | 
| 132 | 
            +
             | 
| 120 133 | 
             
                  def page #:nodoc:
         | 
| 121 134 | 
             
                    @options[:current_page] - 1
         | 
| 122 135 | 
             
                  end
         | 
| @@ -125,6 +138,19 @@ module Kaminari | |
| 125 138 | 
             
                # The "next" page of the current page
         | 
| 126 139 | 
             
                class NextPage < Tag
         | 
| 127 140 | 
             
                  include Link
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                  # TODO: Remove this initializer before 1.3.0.
         | 
| 143 | 
            +
                  def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix: nil, **options) #:nodoc:
         | 
| 144 | 
            +
                    # params in Rails 5 may not be a Hash either,
         | 
| 145 | 
            +
                    # so it must be converted to a Hash to be merged into @params
         | 
| 146 | 
            +
                    if params && params.respond_to?(:to_unsafe_h)
         | 
| 147 | 
            +
                      ActiveSupport::Deprecation.warn 'Explicitly passing params to helpers could be omitted.'
         | 
| 148 | 
            +
                      params = params.to_unsafe_h
         | 
| 149 | 
            +
                    end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                    super(template, params: params, param_name: param_name, theme: theme, views_prefix: views_prefix, **options)
         | 
| 152 | 
            +
                  end
         | 
| 153 | 
            +
             | 
| 128 154 | 
             
                  def page #:nodoc:
         | 
| 129 155 | 
             
                    @options[:current_page] + 1
         | 
| 130 156 | 
             
                  end
         | 
| @@ -1,7 +1,10 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 | 
             
            module Kaminari
         | 
| 3 3 | 
             
              module ConfigurationMethods #:nodoc:
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                def self.included(base)
         | 
| 5 | 
            +
                  base.extend ClassMethods
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 5 8 | 
             
                module ClassMethods #:nodoc:
         | 
| 6 9 | 
             
                  # Overrides the default +per_page+ value per model
         | 
| 7 10 | 
             
                  #   class Article < ActiveRecord::Base
         | 
| @@ -19,7 +19,7 @@ module Kaminari | |
| 19 19 |  | 
| 20 20 | 
             
                def max_paginates_per(new_max_per_page)
         | 
| 21 21 | 
             
                  @_max_per_page = new_max_per_page
         | 
| 22 | 
            -
                  per  | 
| 22 | 
            +
                  per current_per_page, max_per_page: new_max_per_page
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 25 | 
             
                def padding(num)
         | 
| @@ -52,6 +52,11 @@ module Kaminari | |
| 52 52 | 
             
                  raise ZeroPerPageOperation, "Current page was incalculable. Perhaps you called .per(0)?"
         | 
| 53 53 | 
             
                end
         | 
| 54 54 |  | 
| 55 | 
            +
                # Current per-page number
         | 
| 56 | 
            +
                def current_per_page
         | 
| 57 | 
            +
                  (defined?(@_per) && @_per) || default_per_page
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 55 60 | 
             
                # Next page number in the collection
         | 
| 56 61 | 
             
                def next_page
         | 
| 57 62 | 
             
                  current_page + 1 unless last_page? || out_of_range?
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kaminari-core
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0 | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Akira Matsuda
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-10-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 107 107 | 
             
                  version: '0'
         | 
| 108 108 | 
             
            requirements: []
         | 
| 109 109 | 
             
            rubyforge_project: 
         | 
| 110 | 
            -
            rubygems_version: 2.6. | 
| 110 | 
            +
            rubygems_version: 2.6.14
         | 
| 111 111 | 
             
            signing_key: 
         | 
| 112 112 | 
             
            specification_version: 4
         | 
| 113 113 | 
             
            summary: Kaminari's core pagination library
         |