File: lib/radiant/pagination/controller.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Radiant
  module: Pagination
  module: Controller#1
has properties
method: configure_pagination #4
method: pagination_parameters #16
module method: included / 1 #23

Code

   1  module Radiant::Pagination::Controller
   2    # for inclusion into public-facing controllers
   3 
   4    def configure_pagination
   5      # unconfigured parameters remain at will_paginate defaults
   6      # will_paginate controller options are not overridden by tag attribetus 
   7      WillPaginate::ViewHelpers.pagination_options[:param_name] = Radiant::Config["pagination.param_name"].to_sym unless Radiant::Config["pagination.param_name"].blank?
   8      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
   9 
  10      # will_paginate view options can be overridden by tag attributes
  11      [:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container].each do |opt|
  12        WillPaginate::ViewHelpers.pagination_options[opt] = Radiant::Config["pagination.#{opt}"] unless Radiant::Config["pagination.#{opt}"].blank?
  13      end
  14    end
  15 
  16    def pagination_parameters
  17      {
  18        :page => params[WillPaginate::ViewHelpers.pagination_options[:param_name]] || 1, 
  19        :per_page => params[WillPaginate::ViewHelpers.pagination_options[:per_page_param_name]] || Radiant::Config['pagination.per_page'] || 20
  20      }
  21    end
  22 
  23    def self.included(base)
  24      base.class_eval {
  25        helper_method :pagination_parameters
  26        before_filter :configure_pagination
  27      }
  28    end
  29 
  30  end
  31 
  32 
  33 
  34 
  35