diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 34 | ||||
-rw-r--r-- | app/controllers/pages_controller.rb | 4 |
2 files changed, 24 insertions, 14 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index da6cf3e..b2c5762 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,10 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale, :initialize_pages + class << self + attr_accessor :current_site # a class instance variable + end + if Rails.env.production? rescue_from Exception, :with => :render_500 rescue_from ActionController::RoutingError, :with => :render_404 @@ -81,25 +85,31 @@ class ApplicationController < ActionController::Base helper_method :page_body ## - ## INITIALIZATION + ## SITE ## # - # run every time in development mode, run once in production mode + # if we ever make this code support multiple sites, this should depend on the request's domain # - def initialize_pages - run_once(:initialize_pages, :unless => Rails.env.development?) do - StaticPage.load(PAGE_DIRECTORY) - Menu.load(PAGE_DIRECTORY + '/menu.txt') - end + def site + self.class.current_site ||= Site.new end + helper_method :site - def run_once(name, options={}) - key_name = "run_once_#{name}" - if !Thread.current[key_name] || options[:unless] - yield + def initialize_pages + if Rails.env.development? + site.load_pages + else + site.reload_pages_if_needed end - Thread.current[key_name] = true end + #def run_once(name, options={}) + # key_name = "run_once_#{name}" + # if !Thread.current[key_name] || options[:unless] + # yield + # end + # Thread.current[key_name] = true + #end + end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index d4fa09a..36c733b 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -7,7 +7,7 @@ class PagesController < ApplicationController rescue_from PageNotFound, :with => :render_404 def show - @page = StaticPage.find(params[:page]) + @page = site.find_pages(params[:page]) if @page respond_to do |format| format.atom { render_atom_feed(@page) } @@ -21,7 +21,7 @@ class PagesController < ApplicationController protected def choose_layout - if @page && @page.props.layout + if @page && @page.props && @page.props.layout @page.props.layout else 'application' |