diff --git a/lib/kaminari/helpers/action_view_extension.rb b/lib/kaminari/helpers/action_view_extension.rb new file mode 100644 index 0000000..aaaf225 --- /dev/null +++ b/lib/kaminari/helpers/action_view_extension.rb @@ -0,0 +1,24 @@ +module Kaminari + module ActionViewExtension + extend ActiveSupport::Concern + module InstanceMethods + # = Helpers + # + # A helper that renders the pagination links. + # + # <%= paginate @articles %> + # + # ==== Options + # * :window - The "inner window" size (2 by default). + # * :outer_window - The "outer window" size (1 by default). + # * :left - The "left outer window" size (1 by default). + # * :right - The "right outer window" size (1 by default). + # * :params - url_for parameters for the links (:controller, :action, etc.) + # * :remote - Ajax? (false by default) + # * :ANY_OTHER_VALUES - Any other hash key & values would be directly passed into each tag as :locals value. + def paginate(scope, options = {}, &block) + Kaminari::Helpers::PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :remote => false) + end + end + end +end diff --git a/lib/kaminari/helpers/helpers.rb b/lib/kaminari/helpers/helpers.rb index 323a6ac..c6eea6d 100644 --- a/lib/kaminari/helpers/helpers.rb +++ b/lib/kaminari/helpers/helpers.rb @@ -75,23 +75,5 @@ module Kaminari end end end - - # = Helpers - # - # A helper that renders the pagination links. - # - # <%= paginate @articles %> - # - # ==== Options - # * :window - The "inner window" size (2 by default). - # * :outer_window - The "outer window" size (1 by default). - # * :left - The "left outer window" size (1 by default). - # * :right - The "right outer window" size (1 by default). - # * :params - url_for parameters for the links (:controller, :action, etc.) - # * :remote - Ajax? (false by default) - # * :ANY_OTHER_VALUES - Any other hash key & values would be directly passed into each tag as :locals value. - def paginate(scope, options = {}, &block) - PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :remote => false) - end end end diff --git a/lib/kaminari/railtie.rb b/lib/kaminari/railtie.rb index cb082cb..b02ae8e 100644 --- a/lib/kaminari/railtie.rb +++ b/lib/kaminari/railtie.rb @@ -2,6 +2,7 @@ require 'rails' # ensure ORMs are loaded *before* initializing Kaminari begin; require 'mongoid'; rescue LoadError; end +require File.join(File.dirname(__FILE__), 'helpers/action_view_extension') require File.join(File.dirname(__FILE__), 'helpers/helpers') require File.join(File.dirname(__FILE__), 'models/page_scope_methods') require File.join(File.dirname(__FILE__), 'models/configuration_methods') @@ -20,7 +21,7 @@ module Kaminari ::Mongoid::Criteria.send :include, Kaminari::MongoidExtension::Criteria end ActiveSupport.on_load(:action_view) do - ::ActionView::Base.send :include, Kaminari::Helpers + ::ActionView::Base.send :include, Kaminari::ActionViewExtension end end end