File: app/controllers/site_controller.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: SiteController#1
includes
  Controller ( Radiant::Pagination )
inherits from
  ApplicationController   
has properties
class method: cache_timeout #8
method: show_page #12
method: batch_page_status_refresh #32
method: set_cache_control #46
method: find_page / 1 #55
method: process_page / 1 #60
method: dev? #65
method: live? #69

Class Hierarchy

Code

   1  class SiteController < ApplicationController
   2    include Radiant::Pagination::Controller
   3 
   4    skip_before_filter :verify_authenticity_token
   5    no_login_required
   6    cattr_writer :cache_timeout
   7 
   8    def self.cache_timeout
   9      @@cache_timeout ||= 5.minutes
  10    end
  11 
  12    def show_page
  13      url = params[:url]
  14      if Array === url
  15        url = url.join('/')
  16      else
  17        url = url.to_s
  18      end
  19      if @page = find_page(url)
  20        batch_page_status_refresh if (url == "/" || url == "")
  21        process_page(@page)
  22        set_cache_control
  23        @performed_render ||= true
  24      else
  25        render :template => 'site/not_found', :status => 404
  26      end
  27    rescue Page::MissingRootPageError
  28      redirect_to welcome_url
  29    end
  30 
  31    private
  32      def batch_page_status_refresh
  33        @changed_pages = []
  34        @pages = Page.find(:all, :conditions => {:status_id => Status[:scheduled].id})
  35        @pages.each do |page|
  36          if page.published_at <= Time.now
  37             page.status_id = Status[:published].id
  38             page.save
  39             @changed_pages << page.id
  40          end
  41        end
  42 
  43        expires_in nil, :private=>true, "no-cache" => true if @changed_pages.length > 0
  44      end
  45 
  46      def set_cache_control
  47        if (request.head? || request.get?) && @page.cache? && live?
  48          expires_in self.class.cache_timeout, :public => true, :private => false
  49        else
  50          expires_in nil, :private => true, "no-cache" => true
  51          headers['ETag'] = ''
  52        end
  53      end
  54 
  55      def find_page(url)
  56        found = Page.find_by_path(url, live?)
  57        found if found and (found.published? or dev?)
  58      end
  59 
  60      def process_page(page)
  61        page.pagination_parameters = pagination_parameters
  62        page.process(request, response)
  63      end
  64 
  65      def dev?
  66        request.host == @config['dev.host'] || request.host =~ /^dev\./
  67      end
  68 
  69      def live?
  70        not dev?
  71      end
  72  end