Sha256: 040f437e2815f50cf9e11c11bca22c8ae96b22d8d34ffdc7d2ac6ad75e78edf4

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

class Guide::BaseController < Guide.configuration.controller_class_to_inherit.constantize
  helper Rails.application.routes.url_helpers
  layout 'guide/application'

  private

  around_filter :set_locale
  def set_locale
    I18n.with_locale(diplomat.negotiate_locale) { yield }
  end

  around_filter :handle_known_errors
  def handle_known_errors
    begin
      yield
    rescue Guide::Errors::Base => error
      raise error if Rails.env.development?

      case error
      when Guide::Errors::InvalidNode, Guide::Errors::PermissionDenied
        render :text => 'Nothing to see here.', :status => '404'
      else
        render :text => "Something's gone wrong. Sorry about that.", :status => '500'
      end
    end
  end

  def active_node
    @node ||= monkey.fetch_node(node_path)
  end

  def bouncer
    @bouncer ||= Guide::Bouncer.new(authorisation_system: injected_authorisation_system)
  end

  def injected_authentication_system
    if defined?(authentication_system)
      authentication_system
    else
      Guide::DefaultAuthenticationSystem.new
    end
  end

  def injected_authorisation_system
    if defined?(authorisation_system)
      authorisation_system
    else
      Guide::DefaultAuthorisationSystem.new
    end
  end

  def injected_html
    if defined?(html_injection)
      html_injection
    else
      ''
    end
  end

  def content
    @content ||= Guide::Content.new
  end

  def diplomat
    @diplomat ||= Guide::Diplomat.new(session, params, I18n.default_locale)
  end

  def monkey
    Guide::Monkey.new(content, bouncer)
  end

  def nobilizer
    Guide::Nobilizer.new
  end

  def active_node_visibility
    Guide::Scout.new(content).visibility_along_path(node_path)
  end

  def node_path
    params[:node_path] || ""
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
guide-0.3.2 app/controllers/guide/base_controller.rb
guide-0.3.1 app/controllers/guide/base_controller.rb