Sha256: 1050a01febdde6003bd0dc4024466703c5768344b8c8fa00a9d1411af69c3bf9

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

module Admin
  class BaseController < InheritedResources::Base

    include Locomotive::Routing::SiteDispatcher

    layout '/admin/layouts/application'

    before_filter :authenticate_admin!

    before_filter :require_site

    before_filter :validate_site_membership

    before_filter :set_locale

    helper_method :sections

    # https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in
    Dir[File.dirname(__FILE__) + "/../../helpers/**/*_helper.rb"].each do |file|
      helper "admin/#{File.basename(file, '.rb').gsub(/_helper$/, '')}"
    end

    self.responder = Locomotive::AdminResponder # custom responder

    defaults :route_prefix => 'admin'

    respond_to :html

    protected

    def begin_of_association_chain
      current_site
    end

    def self.sections(main, sub = nil)
      before_filter do |c|
        sub = sub.call(c) if sub.respond_to?(:call)
        sections = { :main => main, :sub => sub }
        c.instance_variable_set(:@admin_sections, sections)
      end
    end

    def sections(key = nil)
      if !key.nil? && key.to_sym == :sub
        @admin_sections[:sub] || self.controller_name.dasherize
      else
        @admin_sections[:main]
      end
    end

    def set_locale
      I18n.locale = current_admin.locale rescue Locomotive.config.default_locale
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 app/controllers/admin/base_controller.rb
locomotive_cms-1.0.0.beta app/controllers/admin/base_controller.rb
locomotive_cms-0.0.4.beta12 app/controllers/admin/base_controller.rb
locomotive_cms-0.0.4.beta11 app/controllers/admin/base_controller.rb
locomotive_cms-0.0.4.beta10 app/controllers/admin/base_controller.rb
locomotive_cms-0.0.4.beta9 app/controllers/admin/base_controller.rb
locomotive_cms-0.0.4.beta8 app/controllers/admin/base_controller.rb
locomotive_cms-0.0.4.beta7 app/controllers/admin/base_controller.rb