lib/magic_grid/helpers.rb in magic_grid-0.9.3.1 vs lib/magic_grid/helpers.rb in magic_grid-0.10.0
- old
+ new
@@ -1,8 +1,11 @@
require 'magic_grid/definition'
-require 'will_paginate/array'
+if Module.const_defined? :WillPaginate
+ require 'will_paginate/array'
+end
+
module MagicGrid
module Helpers
def normalize_magic(collection, columns = [], options = {})
if collection.is_a? MagicGrid::Definition
collection
@@ -60,11 +63,11 @@
end
if grid.options[:per_page] and grid.options[:top_pager]
thead << content_tag('tr') do
content_tag('td', :class => 'full-width ui-widget-header',
:colspan => grid.columns.count) do
- pager = will_paginate(grid.collection,
+ pager = magic_paginate(grid.collection,
:param_name => grid.param_key(:page),
:params => base_params
)
unless has_spinner
has_spinner = true
@@ -94,11 +97,11 @@
tfoot = ''.html_safe
if grid.options[:per_page] and grid.options[:bottom_pager]
tfoot << content_tag('tr') do
content_tag('td', :class => 'full-width ui-widget-header',
:colspan => grid.columns.count) do
- will_paginate(grid.collection,
+ magic_paginate(grid.collection,
:param_name => grid.param_key(:page),
:params => base_params
)
end
end
@@ -239,9 +242,24 @@
if grid.options[:search_button]
searcher << button_tag(grid.options[:searcher_button],
:class => 'magic-grid-search-button')
end
searcher
+ end
+
+ def magic_paginate(collection, opts={})
+ if respond_to? :will_paginate
+ # WillPaginate
+ will_paginate collection, opts
+ #alias_method :magic_paginate, :will_paginate
+ elsif respond_to? :paginate
+ #Kaminari, or something else..
+ paginate collection, opts
+ #alias_method :magic_paginate, :paginate
+ else
+ ("<!-- page #{collection.current_page} of #{collection.total_pages} -->" +
+ '<!-- INSTALL WillPaginate or Kaminari for a pager! -->').html_safe
+ end
end
::ActionView::Base.send :include, self
end
end