require 'facet/kernel/constant' require 'facet/time/stamp' require 'nitro/controller' # Provides an automatically generated Administration # interface. class AdminController < Nitro::Controller # Run a simple security check function before each action before :check_security, :except => [ :denied ] # scaffold all the classes scaffold_all def self.setup_template_root(path) super @template_root << File.join(File.dirname(__FILE__), 'template') end # default method for controller def index @classes = self.class.scaffolding_classes.keys.sort { |c1, c2| c1.name <=> c2.name } @settings = Configuration.settings.sort { |s1, s2| "#{s1.owner}.#{s1.name}" <=> "#{s2.owner}.#{s2.name}" } end # Delete all instances of the class. # Useful in development mode. def delete_all(klass) constant(klass).delete_all redirect_to_referer end # Drop the schema (typically the DB tables) used to # store the class instances. def destroy(klass) constant(klass).destroy redirect_to_referer end # fetch the css for this controller # checks for a /system.css file and uses that if available # otherwise uses system.css from the part/admin dir def stylesheet(sheet='system') sheet << ".css" [Nitro::Server.public_root, File.dirname(__FILE__)].each do |path| css_file = File.join(path, sheet) if File.exists? css_file response.content_type = 'text/css' @out << File.read(css_file) raise Nitro::RenderExit end end raise RenderExit end alias_action :stylesheets, :stylesheet private # Overload in your application to suit your # needs. The default implementation does NOT apply security # in debug mode.The default implementation requires the # existense of an :ADMIN key in the session, so you can # easily integrate this in your user/roles management code. def check_security return true if Nitro::Runner.mode == :debug redirect 'denied' unless session[:ADMIN] end end # * George Moschovitis