Sha256: fef96352bae5aebbab00bae9f1e57a1ac607a5b2c3e42a72d2461ef741028617

Contents?: true

Size: 1.92 KB

Versions: 19

Compression:

Stored size: 1.92 KB

Contents

class Comfy::Admin::Cms::BaseController < ComfortableMexicanSofa.config.base_controller.to_s.constantize

  include Comfy::Paginate

  # Authentication module must have `authenticate` method
  include ComfortableMexicanSofa.config.admin_auth.to_s.constantize

  # Authorization module must have `authorize` method
  include ComfortableMexicanSofa.config.admin_authorization.to_s.constantize

  protect_from_forgery

  before_action :authenticate,
                :load_admin_site,
                :set_locale,
                :load_fixtures,
                :except => :jump

  layout 'comfy/admin/cms'

  if ComfortableMexicanSofa.config.admin_cache_sweeper.present?
    cache_sweeper *ComfortableMexicanSofa.config.admin_cache_sweeper
  end

  def jump
    path = ComfortableMexicanSofa.config.admin_route_redirect
    return redirect_to(path) unless path.blank?
    load_admin_site
    redirect_to comfy_admin_cms_site_pages_path(@site) if @site
  end

protected

  def load_admin_site
    if @site = ::Comfy::Cms::Site.find_by_id(params[:site_id] || session[:site_id]) || ::Comfy::Cms::Site.first
      session[:site_id] = @site.id
    else
      I18n.locale = ComfortableMexicanSofa.config.admin_locale || I18n.default_locale
      flash[:danger] = I18n.t('comfy.admin.cms.base.site_not_found')
      return redirect_to(new_comfy_admin_cms_site_path)
    end
  end
  
  def set_locale
    super
  rescue
    I18n.locale = cms_locale
  end

  def cms_locale
    ComfortableMexicanSofa.config.admin_locale || (@site && @site.locale)
  end

  def load_fixtures
    return unless ComfortableMexicanSofa.config.enable_fixtures

    controllers = %w(layouts pages snippets files).collect{|c| 'comfy/admin/cms/' + c}
    if controllers.member?(params[:controller]) && params[:action] == 'index'
      ComfortableMexicanSofa::Fixture::Importer.new(@site.identifier).import!
      flash.now[:danger] = I18n.t('comfy.admin.cms.base.fixtures_enabled')
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
comfortable_mexican_loveseat-0.1.1 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.1.0 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.23 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.22 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.21 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.20 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.19 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.18 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.17 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.16 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.15 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.14 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.13 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.12 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.11 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.10 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.9 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.8 app/controllers/comfy/admin/cms/base_controller.rb
comfortable_mexican_loveseat-0.0.7 app/controllers/comfy/admin/cms/base_controller.rb