Module: Radiant::Pagination::Controller

Included in:
SiteController
Defined in:
lib/radiant/pagination/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



23
24
25
26
27
# File 'lib/radiant/pagination/controller.rb', line 23

def self.included(base)
  base.class_eval {
    before_filter :configure_pagination
  }
end

Instance Method Details

#configure_paginationObject

for inclusion into public-facing controllers



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/radiant/pagination/controller.rb', line 4

def configure_pagination
  # unconfigured parameters remain at will_paginate defaults
  # will_paginate controller options are not overridden by tag attribetus 
  WillPaginate::ViewHelpers.pagination_options[:param_name] = Radiant::Config["pagination.param_name"].to_sym unless Radiant::Config["pagination.param_name"].blank?
  WillPaginate::ViewHelpers.pagination_options[:per_page_param_name] = Radiant::Config["pagination.per_page_param_name"].blank? ? :per_page : Radiant::Config["pagination.per_page_param_name"].to_sym

  # will_paginate view options can be overridden by tag attributes
  [:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container].each do |opt|
    WillPaginate::ViewHelpers.pagination_options[opt] = Radiant::Config["pagination.#{opt}"] unless Radiant::Config["pagination.#{opt}"].blank?
  end
end

#pagination_parametersObject



16
17
18
19
20
21
# File 'lib/radiant/pagination/controller.rb', line 16

def pagination_parameters
  {
    :page => params[WillPaginate::ViewHelpers.pagination_options[:param_name]] || 1, 
    :per_page => params[WillPaginate::ViewHelpers.pagination_options[:per_page_param_name]] || Radiant::Config['pagination.per_page'] || 20
  }
end