config.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. require 'active_support/configurable'
  2. module Kaminari
  3. # Configures global settings for Kaminari
  4. # Kaminari.configure do |config|
  5. # config.default_per_page = 10
  6. # end
  7. def self.configure(&block)
  8. yield @config ||= Kaminari::Configuration.new
  9. end
  10. # Global settings for Kaminari
  11. def self.config
  12. @config
  13. end
  14. # need a Class for 3.0
  15. class Configuration #:nodoc:
  16. include ActiveSupport::Configurable
  17. config_accessor :default_per_page
  18. config_accessor :window
  19. config_accessor :outer_window
  20. config_accessor :left
  21. config_accessor :right
  22. config_accessor :page_method_name
  23. config_accessor :param_name
  24. def param_name
  25. config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
  26. end
  27. end
  28. # this is ugly. why can't we pass the default value to config_accessor...?
  29. configure do |config|
  30. config.default_per_page = 25
  31. config.window = 4
  32. config.outer_window = 0
  33. config.left = 0
  34. config.right = 0
  35. config.page_method_name = :page
  36. config.param_name = :page
  37. end
  38. end