Sha256: 4a89b085dd5addf3b3a19f83f18b4acb311fd6022fc8d3368ddbb540e42fc38c

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

class SiteController < ApplicationController
  include Radiant::Pagination::Controller

  skip_before_filter :verify_authenticity_token
  no_login_required
  cattr_writer :cache_timeout

  def self.cache_timeout
    @@cache_timeout ||= 5.minutes
  end

  def show_page
    url = params[:url]
    if Array === url
      url = url.join('/')
    else
      url = url.to_s
    end
    if @page = find_page(url)
      batch_page_status_refresh if (url == "/" || url == "")
      process_page(@page)
      set_cache_control
      @performed_render ||= true
    else
      render :template => 'site/not_found', :status => 404
    end
  rescue Page::MissingRootPageError
    redirect_to welcome_url
  end

  private
    def batch_page_status_refresh
      @changed_pages = []
      @pages = Page.find(:all, :conditions => {:status_id => Status[:scheduled].id})
      @pages.each do |page|
        if page.published_at <= Time.now
           page.status_id = Status[:published].id
           page.save
           @changed_pages << page.id
        end
      end

      expires_in nil, :private=>true, "no-cache" => true if @changed_pages.length > 0
    end

    def set_cache_control
      if (request.head? || request.get?) && @page.cache? && live?
        expires_in self.class.cache_timeout, :public => true, :private => false
      else
        expires_in nil, :private => true, "no-cache" => true
        headers['ETag'] = ''
      end
    end

    def find_page(url)
      found = Page.find_by_path(url, live?)
      found if found and (found.published? or dev?)
    end

    def process_page(page)
      page.pagination_parameters = pagination_parameters
      page.process(request, response)
    end

    def dev?
      request.host == @config['dev.host'] || request.host =~ /^dev\./
    end

    def live?
      not dev?
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
radiant-1.1.0.beta app/controllers/site_controller.rb
radiant-1.0.1 app/controllers/site_controller.rb
radiant-1.1.0.alpha app/controllers/site_controller.rb
radiant-1.0.0 app/controllers/site_controller.rb
radiant-1.0.0.rc5 app/controllers/site_controller.rb
radiant-1.0.0.rc4 app/controllers/site_controller.rb
radiant-1.0.0.rc3 app/controllers/site_controller.rb