# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the Ruby license. module Ramaze class Dispatcher # Generates a directory listing, see Ramaze::Controller::Directory for more # information and how to create your own directory listing page class Directory class << self # Entry point from Dispatcher::filter. # Just a forwarder to build_listing, automatticly exiting if there is # an error (defined by returning false in build_listing) def call(path) if Global.list_directories response = build_listing(path) Response.current.build(*response) if response end end # Makes a request for http://yourserver/dirlist/path and returns the # result. Due to this method, you can overwrite the action and create your # own page. See Ramaze::Controller::Directory for more. def build_listing(path) dir = ::File.expand_path(Global.public_root/::File.expand_path(path, '/')) if ::File.directory?(dir) Log.debug("Serving directory listing: #{dir}") Session.current.drop! if Session.current status = Ramaze::STATUS_CODE['OK'] header = {'Content-Type' => "text/html"} body = list_for(dir) [body, status, header] end end # Nicely formatted listing for given path, template is "stolen" from # lighttpd def list_for(path) root = ::File.expand_path(Global.public_root) display = path.gsub(/^#{Regexp.escape(root)}\/?/, '/') wrapper = %(
Name | Last Modified | Size | Type |
---|---|---|---|
Parent Directory/ | - | Directory |