! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-IN: file-responder
USING: calendar embedded errors html httpd io kernel math
namespaces parser sequences strings hashtables ;
+IN: file-responder
: serving-path ( filename -- filename )
[ "" ] unless* "doc-root" get swap path+ ;
dup mime-type dup "application/x-factor-server-page" =
[ drop serving-html run-page ] [ serve-static ] if ;
+: file. ( path name -- )
+ tuck path+
+ directory? "[DIR] " " " ? write
+ write-pathname terpri ;
+
+: directory. ( path -- )
+ dup directory natural-sort [ file. ] each-with ;
+
: list-directory ( directory -- )
serving-html
"method" get "head" = [
drop
] [
- "request" get [ dup log-message directory. ] simple-html-document
+ "request" get [
+ "" swap directory.
+ ] simple-html-document
] if ;
: find-index ( filename -- path )
: padding-css, ( padding -- ) "padding: " % # "px; " % ;
: pre-css, ( -- )
- "white-space: pre; font-family:monospace; " % ;
+ "white-space: pre; font-family: monospace; " % ;
: div-css-style ( style -- str )
[
M: object browser-link-href drop f ;
-: resolve-file-link ( path -- link )
- #! The file responder needs relative links not absolute
- #! links.
- "doc-root" get [
- ?head [ "/" ?head drop ] when
- ] when* "/" ?tail drop ;
-
-M: pathname browser-link-href
- pathname-string
- "/" swap resolve-file-link url-encode append ;
+M: pathname browser-link-href pathname-string url-encode ;
: object-link-tag ( style quot -- )
presented pick hash browser-link-href