diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/cgi/nex.go | 10 | ||||
-rw-r--r-- | contrib/fs/nex.go | 48 |
2 files changed, 58 insertions, 0 deletions
diff --git a/contrib/cgi/nex.go b/contrib/cgi/nex.go new file mode 100644 index 0000000..60d487d --- /dev/null +++ b/contrib/cgi/nex.go @@ -0,0 +1,10 @@ +package cgi + +import ( + "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/nex" +) + +func NexCGIDirectory(fsroot, urlroot, cmd string) sliderule.Handler { + return cgiDirectory(nex.ServerProtocol, fsroot, urlroot, cmd) +} diff --git a/contrib/fs/nex.go b/contrib/fs/nex.go new file mode 100644 index 0000000..47eb83e --- /dev/null +++ b/contrib/fs/nex.go @@ -0,0 +1,48 @@ +package fs + +import ( + "text/template" + + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/nex" +) + +// NexFileHandler builds a handler which serves up files from a file system. +// +// It only serves responses for paths which correspond to files, not directories. +func NexFileHandler(fsroot, urlroot string) sr.Handler { + return fileHandler(nex.ServerProtocol, fsroot, urlroot) +} + +// NexDirectoryDefault serves up default files for directory path requests. +// +// If any of the supported filenames are found in the requested directory, the +// contents of that file is returned as the nex response. +// +// It returns nil for any paths which don't correspond to a directory. +func NexDirectoryDefault(fsroot, urlroot string, filenames ...string) sr.Handler { + return directoryDefault(nex.ServerProtocol, fsroot, urlroot, false, filenames...) +} + +// NexDirectoryListing produces a listing of the contents of any requested directories. +// +// It returns a nil response for any paths which don't correspond to a filesystem directory. +// +// When it encounters a directory path which doesn't end in a trailing slash (/) it returns +// a nil response. Trailing slashes are necessary for relative links to work properly. +// +// The template may be nil, in which case DefaultNexDirectoryList is used instead. The +// template is then processed with RenderDirectoryListing. +func NexDirectoryListing(fsroot, urlroot string, tmpl *template.Template) sr.Handler { + if tmpl == nil { + tmpl = DefaultNexDirectoryList + } + return directoryListing(nex.ServerProtocol, fsroot, urlroot, "", false, tmpl) +} + +var DefaultNexDirectoryList = template.Must(template.New("nex_dirlist").Parse(` +{{ .DirName }} directory: +{{ range .Entries }} +=> ./{{ .Name }}{{ if .IsDir }}/{{ end -}} +{{ end }} +`[1:])) |