refs #41 helper options are configurable now!

configurable values are: window, outer_window, left, right
This commit is contained in:
Akira Matsuda 2011-04-21 15:49:45 +09:00
parent 5a9303fe79
commit 4c73ad56db
3 changed files with 38 additions and 4 deletions

View File

@ -18,10 +18,18 @@ module Kaminari
class Configuration #:nodoc: class Configuration #:nodoc:
include ActiveSupport::Configurable include ActiveSupport::Configurable
config_accessor :default_per_page config_accessor :default_per_page
config_accessor :window
config_accessor :outer_window
config_accessor :left
config_accessor :right
end end
# this is ugly. why can't we pass the default value to config_accessor...? # this is ugly. why can't we pass the default value to config_accessor...?
configure do |config| configure do |config|
config.default_per_page = 25 config.default_per_page = 25
config.window = 4
config.outer_window = 0
config.left = 0
config.right = 0
end end
end end

View File

@ -6,10 +6,12 @@ module Kaminari
class Paginator < Tag class Paginator < Tag
def initialize(template, options) #:nodoc: def initialize(template, options) #:nodoc:
@window_options = {}.tap do |h| @window_options = {}.tap do |h|
h[:window] = options.delete(:window) || options.delete(:inner_window) || 4 h[:window] = options.delete(:window) || options.delete(:inner_window) || Kaminari.config.window
outer_window = options.delete(:outer_window) outer_window = options.delete(:outer_window) || Kaminari.config.outer_window
h[:left] = options.delete(:left) || outer_window || 0 h[:left] = options.delete(:left) || Kaminari.config.left
h[:right] = options.delete(:right) || outer_window || 0 h[:left] = outer_window if h[:left] == 0
h[:right] = options.delete(:right) || Kaminari.config.right
h[:right] = outer_window if h[:right] == 0
end end
@template, @options = template, options @template, @options = template, options
@options[:current_page] = PageProxy.new @window_options.merge(@options), @options[:current_page], nil @options[:current_page] = PageProxy.new @window_options.merge(@options), @options[:current_page], nil

View File

@ -16,4 +16,28 @@ describe Kaminari::Configuration do
end end
end end
end end
describe 'window' do
context 'by default' do
its(:window) { should == 4 }
end
end
describe 'outer_window' do
context 'by default' do
its(:outer_window) { should == 0 }
end
end
describe 'left' do
context 'by default' do
its(:left) { should == 0 }
end
end
describe 'right' do
context 'by default' do
its(:right) { should == 0 }
end
end
end end