kaminari 0.17.0 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kaminari might be problematic. Click here for more details.

Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +20 -39
  4. data/CHANGELOG.md +560 -0
  5. data/CONTRIBUTING.md +16 -0
  6. data/Gemfile +1 -0
  7. data/README.md +545 -0
  8. data/Rakefile +21 -24
  9. data/gemfiles/active_record_41.gemfile +2 -4
  10. data/gemfiles/active_record_42.gemfile +2 -4
  11. data/gemfiles/active_record_50.gemfile +20 -0
  12. data/gemfiles/active_record_edge.gemfile +5 -6
  13. data/kaminari.gemspec +11 -17
  14. data/lib/kaminari.rb +4 -39
  15. data/lib/kaminari/version.rb +2 -1
  16. metadata +44 -186
  17. data/.gemtest +0 -0
  18. data/.rspec +0 -2
  19. data/CHANGELOG.rdoc +0 -480
  20. data/README.rdoc +0 -336
  21. data/app/views/kaminari/_first_page.html.erb +0 -11
  22. data/app/views/kaminari/_first_page.html.haml +0 -9
  23. data/app/views/kaminari/_first_page.html.slim +0 -10
  24. data/app/views/kaminari/_gap.html.erb +0 -8
  25. data/app/views/kaminari/_gap.html.haml +0 -8
  26. data/app/views/kaminari/_gap.html.slim +0 -9
  27. data/app/views/kaminari/_last_page.html.erb +0 -11
  28. data/app/views/kaminari/_last_page.html.haml +0 -9
  29. data/app/views/kaminari/_last_page.html.slim +0 -10
  30. data/app/views/kaminari/_next_page.html.erb +0 -11
  31. data/app/views/kaminari/_next_page.html.haml +0 -9
  32. data/app/views/kaminari/_next_page.html.slim +0 -10
  33. data/app/views/kaminari/_page.html.erb +0 -12
  34. data/app/views/kaminari/_page.html.haml +0 -10
  35. data/app/views/kaminari/_page.html.slim +0 -11
  36. data/app/views/kaminari/_paginator.html.erb +0 -23
  37. data/app/views/kaminari/_paginator.html.haml +0 -18
  38. data/app/views/kaminari/_paginator.html.slim +0 -19
  39. data/app/views/kaminari/_prev_page.html.erb +0 -11
  40. data/app/views/kaminari/_prev_page.html.haml +0 -9
  41. data/app/views/kaminari/_prev_page.html.slim +0 -10
  42. data/config/locales/kaminari.yml +0 -19
  43. data/gemfiles/active_record_30.gemfile +0 -28
  44. data/gemfiles/active_record_31.gemfile +0 -26
  45. data/gemfiles/active_record_32.gemfile +0 -25
  46. data/gemfiles/active_record_40.gemfile +0 -26
  47. data/gemfiles/data_mapper_12.gemfile +0 -32
  48. data/gemfiles/mongo_mapper.gemfile +0 -25
  49. data/gemfiles/mongoid_30.gemfile +0 -22
  50. data/gemfiles/mongoid_31.gemfile +0 -21
  51. data/gemfiles/mongoid_40.gemfile +0 -19
  52. data/gemfiles/mongoid_50.gemfile +0 -23
  53. data/gemfiles/sinatra_13.gemfile +0 -36
  54. data/gemfiles/sinatra_14.gemfile +0 -33
  55. data/lib/generators/kaminari/config_generator.rb +0 -16
  56. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  57. data/lib/generators/kaminari/views_generator.rb +0 -119
  58. data/lib/kaminari/config.rb +0 -51
  59. data/lib/kaminari/engine.rb +0 -4
  60. data/lib/kaminari/grape.rb +0 -4
  61. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  62. data/lib/kaminari/helpers/paginator.rb +0 -195
  63. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  64. data/lib/kaminari/helpers/tags.rb +0 -108
  65. data/lib/kaminari/hooks.rb +0 -53
  66. data/lib/kaminari/models/active_record_extension.rb +0 -22
  67. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  68. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  69. data/lib/kaminari/models/array_extension.rb +0 -66
  70. data/lib/kaminari/models/configuration_methods.rb +0 -48
  71. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  72. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  73. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  74. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  75. data/lib/kaminari/models/mongoid_extension.rb +0 -26
  76. data/lib/kaminari/models/page_scope_methods.rb +0 -73
  77. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  78. data/lib/kaminari/railtie.rb +0 -7
  79. data/lib/kaminari/sinatra.rb +0 -7
  80. data/spec/config/config_spec.rb +0 -91
  81. data/spec/fake_app/active_record/config.rb +0 -3
  82. data/spec/fake_app/active_record/models.rb +0 -65
  83. data/spec/fake_app/data_mapper/config.rb +0 -1
  84. data/spec/fake_app/data_mapper/models.rb +0 -27
  85. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  86. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  87. data/spec/fake_app/mongoid/config.rb +0 -20
  88. data/spec/fake_app/mongoid/models.rb +0 -38
  89. data/spec/fake_app/rails_app.rb +0 -56
  90. data/spec/fake_app/sinatra_app.rb +0 -22
  91. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  92. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  93. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  94. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  95. data/spec/fake_gem.rb +0 -20
  96. data/spec/generators/views_generator_spec.rb +0 -18
  97. data/spec/helpers/action_view_extension_spec.rb +0 -318
  98. data/spec/helpers/helpers_spec.rb +0 -144
  99. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  100. data/spec/helpers/tags_spec.rb +0 -140
  101. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  102. data/spec/models/active_record/inherited_spec.rb +0 -9
  103. data/spec/models/active_record/scopes_spec.rb +0 -265
  104. data/spec/models/array_spec.rb +0 -172
  105. data/spec/models/configuration_methods_spec.rb +0 -125
  106. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  107. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  108. data/spec/models/mongoid/mongoid_spec.rb +0 -228
  109. data/spec/requests/users_spec.rb +0 -53
  110. data/spec/spec_helper.rb +0 -34
  111. data/spec/spec_helper_for_sinatra.rb +0 -34
  112. data/spec/support/database_cleaner.rb +0 -19
  113. data/spec/support/matchers.rb +0 -52
@@ -1,176 +0,0 @@
1
- require 'active_support/core_ext/object'
2
- require 'active_support/core_ext/string'
3
- require 'action_dispatch/http/mime_type'
4
-
5
- begin
6
-
7
- require 'padrino-helpers'
8
- module Kaminari::Helpers
9
- module SinatraHelpers
10
- class << self
11
- def registered(app)
12
- app.register Padrino::Helpers
13
- app.helpers HelperMethods
14
- @app = app
15
- end
16
-
17
- def view_paths
18
- @app.views
19
- end
20
-
21
- alias included registered
22
- end
23
-
24
- class ActionViewTemplateProxy
25
- include Padrino::Helpers::OutputHelpers
26
- include Padrino::Helpers::TagHelpers
27
- include Padrino::Helpers::AssetTagHelpers
28
- include Padrino::Helpers::FormatHelpers
29
- include Padrino::Helpers::TranslationHelpers
30
-
31
- def initialize(opts={})
32
- @current_path = opts[:current_path]
33
- @param_name = (opts[:param_name] || :page).to_sym
34
- @current_params = opts[:current_params]
35
- @current_params.delete(@param_name)
36
- end
37
-
38
- def render(*args)
39
- base = ActionView::Base.new.tap do |a|
40
- a.view_paths << SinatraHelpers.view_paths
41
- a.view_paths << File.expand_path('../../../../app/views', __FILE__)
42
- end
43
- base.render(*args)
44
- end
45
-
46
- def url_for(params)
47
- extra_params = {}
48
- if page = params[@param_name] and page != 1
49
- extra_params[@param_name] = page
50
- end
51
- query = @current_params.merge(extra_params)
52
- @current_path + (query.empty? ? '' : "?#{query.to_query}")
53
- end
54
-
55
- def link_to_unless(condition, name, options = {}, html_options = {}, &block)
56
- options = url_for(options) if options.is_a? Hash
57
- if condition
58
- if block_given?
59
- block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
60
- else
61
- name
62
- end
63
- else
64
- link_to(name, options, html_options)
65
- end
66
- end
67
-
68
- def params
69
- @current_params
70
- end
71
- end
72
-
73
- module HelperMethods
74
- # A helper that renders the pagination links - for Sinatra.
75
- #
76
- # <%= paginate @articles %>
77
- #
78
- # ==== Options
79
- # * <tt>:window</tt> - The "inner window" size (4 by default).
80
- # * <tt>:outer_window</tt> - The "outer window" size (0 by default).
81
- # * <tt>:left</tt> - The "left outer window" size (0 by default).
82
- # * <tt>:right</tt> - The "right outer window" size (0 by default).
83
- # * <tt>:params</tt> - url_for parameters for the links (:id, :locale, etc.)
84
- # * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
85
- # * <tt>:remote</tt> - Ajax? (false by default)
86
- # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
87
- def paginate(scope, options = {}, &block)
88
- current_path = env['PATH_INFO'] rescue nil
89
- current_params = Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {}
90
- paginator = Kaminari::Helpers::Paginator.new(
91
- ActionViewTemplateProxy.new(:current_params => current_params, :current_path => current_path, :param_name => options[:param_name] || Kaminari.config.param_name),
92
- options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
93
- )
94
- paginator.to_s
95
- end
96
-
97
- # A simple "Twitter like" pagination link that creates a link to the previous page.
98
- # Works on Sinatra.
99
- #
100
- # ==== Examples
101
- # Basic usage:
102
- #
103
- # <%= link_to_previous_page @items, 'Previous Page' %>
104
- #
105
- # Ajax:
106
- #
107
- # <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
108
- #
109
- # By default, it renders nothing if there are no more results on the previous page.
110
- # You can customize this output by passing a parameter <tt>:placeholder</tt>.
111
- #
112
- # <%= link_to_previous_page @users, 'Previous Page', :placeholder => %{<span>At the Beginning</span>} %>
113
- #
114
- def link_to_previous_page(scope, name, options = {})
115
- params = options.delete(:params) || (Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
116
- param_name = options.delete(:param_name) || Kaminari.config.param_name
117
- placeholder = options.delete(:placeholder)
118
-
119
- unless scope.first_page?
120
- query = params.merge(param_name => scope.prev_page)
121
- link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'previous')
122
- else
123
- placeholder.to_s.html_safe
124
- end
125
- end
126
-
127
- # A simple "Twitter like" pagination link that creates a link to the next page.
128
- # Works on Sinatra.
129
- #
130
- # ==== Examples
131
- # Basic usage:
132
- #
133
- # <%= link_to_next_page @items, 'Next Page' %>
134
- #
135
- # Ajax:
136
- #
137
- # <%= link_to_next_page @items, 'Next Page', :remote => true %>
138
- #
139
- # By default, it renders nothing if there are no more results on the next page.
140
- # You can customize this output by passing a parameter <tt>:placeholder</tt>.
141
- #
142
- # <%= link_to_next_page @items, 'Next Page', :placeholder => %{<span>No More Pages</span>} %>
143
- #
144
- def link_to_next_page(scope, name, options = {})
145
- params = options.delete(:params) || (Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
146
- param_name = options.delete(:param_name) || Kaminari.config.param_name
147
- placeholder = options.delete(:placeholder)
148
-
149
- unless scope.last_page?
150
- query = params.merge(param_name => scope.next_page)
151
- link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'next')
152
- else
153
- placeholder.to_s.html_safe
154
- end
155
- end
156
- end
157
- end
158
- end
159
-
160
- if defined? I18n
161
- I18n.load_path += Dir.glob(File.expand_path('../../../../config/locales/*.yml', __FILE__))
162
- end
163
-
164
- rescue LoadError
165
-
166
- $stderr.puts "[!]You should install `padrino-helpers' gem if you want to use kaminari's pagination helpers with Sinatra."
167
- $stderr.puts "[!]Kaminari::Helpers::SinatraHelper does nothing now..."
168
-
169
- module Kaminari::Helpers
170
- module SinatraHelper
171
- def self.registered(*)
172
- end
173
- end
174
- end
175
-
176
- end
@@ -1,108 +0,0 @@
1
- module Kaminari
2
- module Helpers
3
- # A tag stands for an HTML tag inside the paginator.
4
- # Basically, a tag has its own partial template file, so every tag can be
5
- # rendered into String using its partial template.
6
- #
7
- # The template file should be placed in your app/views/kaminari/ directory
8
- # with underscored class name (besides the "Tag" class. Tag is an abstract
9
- # class, so _tag parital is not needed).
10
- # e.g.) PrevLink -> app/views/kaminari/_prev_link.html.erb
11
- #
12
- # When no matching template were found in your app, the engine's pre
13
- # installed template will be used.
14
- # e.g.) Paginator -> $GEM_HOME/kaminari-x.x.x/app/views/kaminari/_paginator.html.erb
15
- class Tag
16
- def initialize(template, options = {}) #:nodoc:
17
- @template, @options = template, options.dup
18
- @param_name = @options.delete(:param_name) || Kaminari.config.param_name
19
- @theme = @options.delete(:theme)
20
- @views_prefix = @options.delete(:views_prefix)
21
- @params = template.params
22
- # @params in Rails 5 no longer inherits from Hash
23
- @params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
24
- @params = @params.except(:script_name).merge(@options.delete(:params) || {})
25
- end
26
-
27
- def to_s(locals = {}) #:nodoc:
28
- @template.render :partial => partial_path, :locals => @options.merge(locals), :formats => [:html]
29
- end
30
-
31
- def page_url_for(page)
32
- @template.url_for @params.merge(@param_name => (page <= 1 ? nil : page), :only_path => true)
33
- end
34
-
35
- def partial_path
36
- [
37
- @views_prefix,
38
- "kaminari",
39
- @theme,
40
- self.class.name.demodulize.underscore
41
- ].compact.join("/")
42
- end
43
- end
44
-
45
- # Tag that contains a link
46
- module Link
47
- # target page number
48
- def page
49
- raise 'Override page with the actual page value to be a Page.'
50
- end
51
- # the link's href
52
- def url
53
- page_url_for page
54
- end
55
- def to_s(locals = {}) #:nodoc:
56
- super locals.merge(:url => url)
57
- end
58
- end
59
-
60
- # A page
61
- class Page < Tag
62
- include Link
63
- # target page number
64
- def page
65
- @options[:page]
66
- end
67
- def to_s(locals = {}) #:nodoc:
68
- super locals.merge(:page => page)
69
- end
70
- end
71
-
72
- # Link with page number that appears at the leftmost
73
- class FirstPage < Tag
74
- include Link
75
- def page #:nodoc:
76
- 1
77
- end
78
- end
79
-
80
- # Link with page number that appears at the rightmost
81
- class LastPage < Tag
82
- include Link
83
- def page #:nodoc:
84
- @options[:total_pages]
85
- end
86
- end
87
-
88
- # The "previous" page of the current page
89
- class PrevPage < Tag
90
- include Link
91
- def page #:nodoc:
92
- @options[:current_page] - 1
93
- end
94
- end
95
-
96
- # The "next" page of the current page
97
- class NextPage < Tag
98
- include Link
99
- def page #:nodoc:
100
- @options[:current_page] + 1
101
- end
102
- end
103
-
104
- # Non-link tag that stands for skipped pages...
105
- class Gap < Tag
106
- end
107
- end
108
- end
@@ -1,53 +0,0 @@
1
- module Kaminari
2
- class Hooks
3
- def self.init
4
- ActiveSupport.on_load(:active_record) do
5
- require 'kaminari/models/active_record_extension'
6
- ::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension
7
- end
8
-
9
- # data_mapper
10
- begin
11
- require 'kaminari/data_mapper'
12
- rescue LoadError
13
- begin; require 'data_mapper'; rescue LoadError; end
14
- if defined? ::DataMapper
15
- require 'dm-aggregates'
16
- require 'kaminari/models/data_mapper_extension'
17
- ::DataMapper::Collection.send :include, Kaminari::DataMapperExtension::Collection
18
- ::DataMapper::Model.append_extensions Kaminari::DataMapperExtension::Model
19
- # ::DataMapper::Model.send :extend, Kaminari::DataMapperExtension::Model
20
- end
21
- end
22
-
23
- ## mongoid
24
- begin
25
- require 'kaminari/mongoid'
26
- rescue LoadError
27
- begin; require 'mongoid'; rescue LoadError; end
28
- if defined? ::Mongoid
29
- ActiveSupport::Deprecation.warn 'Kaminari Mongoid support has been extracted to a separate gem, and will be removed in the next 1.0 release. Please bundle kaminari-mongoid gem.'
30
- require 'kaminari/models/mongoid_extension'
31
- ::Mongoid::Document.send :include, Kaminari::MongoidExtension::Document
32
- end
33
- end
34
-
35
- ## mongo_mapper
36
- ActiveSupport.on_load(:mongo_mapper) do
37
- begin
38
- require 'kaminari/mongo_mapper'
39
- rescue LoadError
40
- ActiveSupport::Deprecation.warn 'Kaminari MongoMapper support has been extracted to a separate gem, and will be removed in the next 1.0 release. Please bundle kaminari-mongo_mapper gem.'
41
- require 'kaminari/models/mongo_mapper_extension'
42
- ::MongoMapper::Document.send :include, Kaminari::MongoMapperExtension::Document
43
- ::Plucky::Query.send :include, Kaminari::PluckyCriteriaMethods
44
- end
45
- end
46
- require 'kaminari/models/array_extension'
47
-
48
- ActiveSupport.on_load(:action_view) do
49
- ::ActionView::Base.send :include, Kaminari::ActionViewExtension
50
- end
51
- end
52
- end
53
- end
@@ -1,22 +0,0 @@
1
- require 'kaminari/models/active_record_model_extension'
2
-
3
- module Kaminari
4
- module ActiveRecordExtension
5
- extend ActiveSupport::Concern
6
-
7
- module ClassMethods
8
- # Future subclasses will pick up the model extension
9
- def inherited(kls) #:nodoc:
10
- super
11
- kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ::ActiveRecord::Base
12
- end
13
- end
14
-
15
- included do
16
- # Existing subclasses pick up the model extension as well
17
- self.descendants.each do |kls|
18
- kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ::ActiveRecord::Base
19
- end
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- require 'kaminari/models/active_record_relation_methods'
2
-
3
- module Kaminari
4
- module ActiveRecordModelExtension
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- self.send(:include, Kaminari::ConfigurationMethods)
9
-
10
- # Fetch the values at the specified page number
11
- # Model.page(5)
12
- eval <<-RUBY
13
- def self.#{Kaminari.config.page_method_name}(num = nil)
14
- limit(default_per_page).offset(default_per_page * ((num = num.to_i - 1) < 0 ? 0 : num)).extending do
15
- include Kaminari::ActiveRecordRelationMethods
16
- include Kaminari::PageScopeMethods
17
- end
18
- end
19
- RUBY
20
- end
21
- end
22
- end
@@ -1,42 +0,0 @@
1
- module Kaminari
2
- module ActiveRecordRelationMethods
3
- # a workaround for AR 3.0.x that returns 0 for #count when page > 1
4
- # if +limit_value+ is specified, load all the records and count them
5
- if ActiveRecord::VERSION::STRING < '3.1'
6
- def count(column_name = nil, options = {}) #:nodoc:
7
- limit_value && !options[:distinct] ? length : super(column_name, options)
8
- end
9
- end
10
-
11
- def entry_name
12
- model_name.human.downcase
13
- end
14
-
15
- def reset #:nodoc:
16
- @total_count = nil
17
- super
18
- end
19
-
20
- def total_count(column_name = :all, options = {}) #:nodoc:
21
- # #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
22
- @total_count ||= begin
23
- c = except(:offset, :limit, :order)
24
-
25
- # Remove includes only if they are irrelevant
26
- c = c.except(:includes) unless references_eager_loaded_tables?
27
-
28
- # Rails 4.1 removes the `options` argument from AR::Relation#count
29
- args = [column_name]
30
- args << options if ActiveRecord::VERSION::STRING < '4.1.0'
31
-
32
- # .group returns an OrderdHash that responds to #count
33
- c = c.count(*args)
34
- if c.is_a?(Hash) || c.is_a?(ActiveSupport::OrderedHash)
35
- c.count
36
- else
37
- c.respond_to?(:count) ? c.count(*args) : c
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,66 +0,0 @@
1
- require 'active_support/core_ext/module'
2
- module Kaminari
3
- # Kind of Array that can paginate
4
- class PaginatableArray < Array
5
- include Kaminari::ConfigurationMethods::ClassMethods
6
-
7
- attr_internal_accessor :limit_value, :offset_value
8
-
9
- # ==== Options
10
- # * <tt>:limit</tt> - limit
11
- # * <tt>:offset</tt> - offset
12
- # * <tt>:total_count</tt> - total_count
13
- def initialize(original_array = [], options = {})
14
- @_original_array, @_limit_value, @_offset_value, @_total_count, @_padding = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count], options[:padding].to_i
15
-
16
- if options[:limit] && options[:offset]
17
- extend Kaminari::PageScopeMethods
18
- end
19
-
20
- if @_total_count.present? && @_total_count <= original_array.count
21
- original_array = original_array.first(@_total_count)[@_offset_value, @_limit_value]
22
- end
23
-
24
- if @_total_count.nil?
25
- original_array = original_array[@_offset_value, @_limit_value]
26
- end
27
-
28
- super(original_array || [])
29
- end
30
-
31
- def entry_name
32
- "entry"
33
- end
34
-
35
- # items at the specified "page"
36
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
37
- def #{Kaminari.config.page_method_name}(num = 1)
38
- offset(limit_value * ((num = num.to_i - 1) < 0 ? 0 : num))
39
- end
40
- RUBY
41
-
42
- # returns another chunk of the original array
43
- def limit(num)
44
- self.class.new @_original_array, :limit => num, :offset => @_offset_value, :total_count => @_total_count, :padding => @_padding
45
- end
46
-
47
- # total item numbers of the original array
48
- def total_count
49
- @_total_count || @_original_array.count
50
- end
51
-
52
- # returns another chunk of the original array
53
- def offset(num)
54
- self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count, :padding => @_padding
55
- end
56
- end
57
-
58
- # Wrap an Array object to make it paginatable
59
- # ==== Options
60
- # * <tt>:limit</tt> - limit
61
- # * <tt>:offset</tt> - offset
62
- # * <tt>:total_count</tt> - total_count
63
- def self.paginate_array(array, options = {})
64
- PaginatableArray.new array, options
65
- end
66
- end