Sha256: 592b34c1a0b1ab92f8749fd3ed0e3af633716bbe8e4d430abe63b3d587b32877

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

class ForgeController < ApplicationController
  before_filter :require_admin, :load_help, :get_menu_items, :set_crumbs, :set_title
  layout 'forge'

  rescue_from CanCan::AccessDenied do |exception|
    flash[:warning] = exception.message
    redirect_to '/forge'
  end

  def uses_ckeditor
    @uses_ckeditor = true
  end

  def load_help
    @help_slug = "#{params[:controller].split('/')[1]}_#{params[:action]}"
  end

  def get_menu_items
    # TODO: we're really not supposed to be reading the routes like this
    # Read the routes to find out which partials to load to build the menu
    routes = Rails.application.routes.routes
    inspector = ActionDispatch::Routing::RoutesInspector.new(routes)
    formatter = ActionDispatch::Routing::ConsoleFormatter.new
    controllers = inspector.format(formatter).split("\n").select do |route|
      route.match('forge')
    end.map do |route|
      route.gsub(/.*\)\s+/,'').gsub("forge/","").gsub(/#.*/, "")
    end
    @menu_items = controllers.reject {|c| c == "index"}.uniq!
  end

  def set_crumbs
    @controller_crumb = params[:controller]
    @action_crumb = params[:action]
  end

  def set_title
    case params[:action]
      when "new", "create"
        @page_title = "New #{params[:controller].gsub('forge/', '').singularize.humanize} - Forge".titleize
      when "edit", "update"
        @page_title = "Edit #{params[:controller].gsub('forge/', '').singularize.humanize} - Forge".titleize
      else
        @page_title = params[:controller].gsub('forge/', '').humanize.titleize + " - Forge"
      end
    @page_title = "Forge" if params[:controller].gsub('forge/', '') == "index"
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.9 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.8 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.7 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.6 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.5 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.4 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.3 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.2 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.1 lib/forge/app/controllers/forge_controller.rb
forge-cli-0.1.0 lib/forge/app/controllers/forge_controller.rb