Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Generate directory listings in the request's prefered format. Customize response via ERB templates and/or callbacks.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/rack
templates
test
README.rdoc
Rakefile
rack-directory-template.gemspec

README.rdoc

Rack::DirectoryTemplate

Generate directory listings in the request's prefered format. Customize response via ERB templates and/or callbacks.

Overview

run Rack::DirectoryTemplate.new "/var/www/html/yoursite"

curl -H 'Accept: application/json' 'http://yoursite/somedir'
curl -H 'Accept: application/xml'  'http://yoursite/somedir'

# Only accept requests for HTML and JSON 
run Rack::DirectoryTemplate.new, ".", :accept => [:html, :json]

# Get the directory from the "file" request parameter, e.g., for JavaScript file browsers.
run Rack::DirectoryTemplate.new, ".", :param => "file"

curl 'http://yoursite/somedir?file=path/to/dir'

# Custom templates
run Rack::DirectoryTemplate.new, ".", :templates => YourFactory
run Rack::DirectoryTemplate.new, ".", :templates => "/path/to/erb/templates"  
run Rack::DirectoryTemplate.new, ".", :templates => { :json => lambda { |listing| ... } }

# Recursive listings 
run Rack::DirectoryTemplate.new, ".", :recurse => true

# Recurse with a limit
run Rack::DirectoryTemplate.new, ".", :recurse => 10

Description

Rack::DirectoryTemplate is a Rack endpoint for directory listings that examines the request's Accept header and generates a reply in the prefered format. Directory names can also be given via a request parameter, great for JavaScript file tree plugins like jQuery File Tree.

Currently supports HTML, JSON, and XML. Suitable defaults are provided for each format. Customization is possible via ERB templates and/or callbacks.

Requests for files will be passed off to the handler given by the :app option, which defaults to Rack::File.

Creating Templates

Templates can be created via ERB, a Proc, or a class that responds to a html, xml, or json method. A directory listing for the request will be provided to these in the following format, either as an argument or as a template variable:

{ :url   => "/some/path"
  :name  => "path, 
  :user  => "sshaw", 
  :group => "sshaw",  
  :type  => "directory",
  :mtime => "Tue Jun 05 14:13:31 -0700 2012",
  :atime => "Tue Jun 05 14:13:31 -0700 2012",
  :ctime => "Tue Jun 05 14:13:31 -0700 2012",
  :mode  => 16877,
  :files => [ { 
    :url  => "/some/path/file1", 
    :name => "file", 
    # same fields as above 
   } ] }

Author

Skye Shaw [sshaw AT lucas.cis.temple.edu]

License

Released under the MIT License: www.opensource.org/licenses/MIT

Something went wrong with that request. Please try again.