Sha256: af7405dfc01a9709f17dbcacde05955c7bfc6c418186609e57b6159f47dff212
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 KB
Contents
module LucyCms::ControllerMethods def self.included(base) # If application controller doesn't have template associated with it # CMS will attempt to find one. This is so you don't have to explicitly # call render :cms_page => '/something' base.rescue_from 'ActionView::MissingTemplate' do |e| begin render :cms_page => request.path rescue ActionView::MissingTemplate raise e end end # Now you can render cms_page simply by calling: # render :cms_page => '/path/to/page' # This way application controllers can use CMS content while populating # instance variables that can be used in partials (that are included by # by the cms page and/or layout) def render(options = {}, locals = {}, &block) if options.is_a?(Hash) && path = options.delete(:cms_page) site = CmsSite.find_by_hostname(request.host.downcase) page = CmsPage.load_from_file(site, path) if site && LucyCms.configuration.seed_data_path page ||= site && site.cms_pages.find_by_full_path(path) if page cms_app_layout = page.cms_layout.try(:app_layout) options[:layout] ||= cms_app_layout.blank?? nil : cms_app_layout options[:inline] = page.content @cms_page = page super(options, locals, &block) else raise ActionView::MissingTemplate.new([path], path, "CMS page not found", nil) end else super(options, locals, &block) end end end end ActionController::Base.send :include, LucyCms::ControllerMethods
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lucy_cms-0.0.6 | lib/LucyCMS/controller_methods.rb |
lucy_cms-0.0.5 | lib/LucyCMS/controller_methods.rb |
lucy_cms-0.0.4 | lib/LucyCMS/controller_methods.rb |