mod_autoindex
authorAdam Chlipala <adamc@hcoop.net>
Sat, 26 Aug 2006 22:36:55 +0000 (22:36 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sat, 26 Aug 2006 22:36:55 +0000 (22:36 +0000)
lib/mod_autoindex.dtl [new file with mode: 0644]
src/plugins/apache.sml
tests/testApache.dtl

diff --git a/lib/mod_autoindex.dtl b/lib/mod_autoindex.dtl
new file mode 100644 (file)
index 0000000..fc7742e
--- /dev/null
@@ -0,0 +1,52 @@
+{{Support for Apache's mod_autoindex, which generates pretty default directory
+  index pages}}
+
+extern val addDescription : string -> [no_spaces] -> [^Vhost];
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#adddescription">the
+  Apache documentation</a> for <tt>AddDescription</tt>.}}
+
+extern type autoindex_width;
+{{A setting for how wide some column should be}}
+extern val autofit : autoindex_width;
+extern val characters : int -> autoindex_width;
+
+extern type autoindex_option;
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#indexoptions">the
+  Apache documentation</a> for what the options mean.}}
+
+extern val descriptionWidth : autoindex_width -> autoindex_option;
+extern val fancyIndexing : autoindex_option;
+extern val foldersFirst : autoindex_option;
+extern val htmlTable : autoindex_option;
+extern val iconsAreLinks : autoindex_option;
+extern val iconHeight : int -> autoindex_option;
+extern val iconWidth : int -> autoindex_option;
+extern val ignoreCase : autoindex_option;
+extern val ignoreClient : autoindex_option;
+extern val nameWidth : autoindex_width -> autoindex_option;
+extern val scanHtmlTitles : autoindex_option;
+extern val suppressColumnSorting : autoindex_option;
+extern val suppressDescription : autoindex_option;
+extern val suppressHtmlPreamble : autoindex_option;
+extern val suppressIcon : autoindex_option;
+extern val suppressLastModified : autoindex_option;
+extern val suppressRules : autoindex_option;
+extern val suppressSize : autoindex_option;
+extern val trackModified : autoindex_option;
+extern val versionSort : autoindex_option;
+extern val xhtml : autoindex_option;
+
+extern val indexOptions : [autoindex_option] -> [^Vhost];
+{{Declare exactly the set of options in effect for the current scope.}}
+
+extern val set_indexOptions : [autoindex_option] -> [^Vhost];
+extern val unset_indexOptions : [autoindex_option] -> [^Vhost];
+{{Specify some options to be set or unset, leaving the rest as they are.}}
+
+extern val headerName : no_spaces -> [^Vhost];
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#headername">the
+  Apache documentation</a>.}}
+
+extern val readmeName : no_spaces -> [^Vhost];
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#readmename">the
+  Apache documentation</a>.}}
index d706de9..1f61476 100644 (file)
@@ -131,6 +131,42 @@ val apache_option = fn (EVar "execCGI", _) => SOME "ExecCGI"
                     | (EVar "indexes", _) => SOME "Indexes"
                     | _ => NONE
 
+val autoindex_width = fn (EVar "autofit", _) => SOME "*"
+                      | (EApp ((EVar "characters", _), n), _) =>
+                        Option.map Int.toString (Env.int n)
+                      | _ => NONE
+
+val autoindex_option = fn (EApp ((EVar "descriptionWidth", _), w), _) =>
+                         Option.map (fn w => ("DescriptionWidth", SOME w))
+                         (autoindex_width w)
+                       | (EVar "fancyIndexing", _) => SOME ("FancyIndexing", NONE)
+                       | (EVar "foldersFirst", _) => SOME ("FoldersFirst", NONE)
+                       | (EVar "htmlTable", _) => SOME ("HTMLTable", NONE)
+                       | (EVar "iconsAreLinks", _) => SOME ("IconsAreLinks", NONE)
+                       | (EApp ((EVar "iconHeight", _), n), _) =>
+                         Option.map (fn w => ("IconHeight", SOME (Int.toString w)))
+                                    (Env.int n)
+                       | (EApp ((EVar "iconWidth", _), n), _) =>
+                         Option.map (fn w => ("IconWidth", SOME (Int.toString w)))
+                                    (Env.int n)
+                       | (EVar "ignoreCase", _) => SOME ("IgnoreCase", NONE)
+                       | (EVar "ignoreClient", _) => SOME ("IgnoreClient", NONE)
+                       | (EApp ((EVar "nameWidth", _), w), _) =>
+                         Option.map (fn w => ("NameWidth", SOME w))
+                                    (autoindex_width w)
+                       | (EVar "scanHtmlTitles", _) => SOME ("ScanHTMLTitles", NONE)
+                       | (EVar "suppressColumnSorting", _) => SOME ("SuppressColumnSorting", NONE)
+                       | (EVar "suppressDescription", _) => SOME ("SuppressDescription", NONE)
+                       | (EVar "suppressHtmlPreamble", _) => SOME ("SuppressHTMLPreamble", NONE)
+                       | (EVar "suppressIcon", _) => SOME ("SuppressIcon", NONE)
+                       | (EVar "suppressLastModified", _) => SOME ("SuppressLastModified", NONE)
+                       | (EVar "suppressRules", _) => SOME ("SuppressRules", NONE)
+                       | (EVar "suppressSize", _) => SOME ("SuppressSize", NONE)
+                       | (EVar "trackModified", _) => SOME ("TrackModified", NONE)
+                       | (EVar "versionSort", _) => SOME ("VersionSort", NONE)
+                       | (EVar "xhtml", _) => SOME ("XHTML", NONE)
+
+                       | _ => NONE
 
 val vhostsChanged = ref false
 
@@ -521,4 +557,64 @@ val () = Env.action_one "authzSvnAccessFile"
                      write path;
                      write "\n"))
 
+val () = Env.action_two "addDescription"
+        ("description", Env.string, "patterns", Env.list Env.string)
+        (fn (desc, pats) =>
+            case pats of
+                [] => ()
+              | _ => (write "\tAddDescription \"";
+                      write (String.toString desc);
+                      write "\"";
+                      app (fn pat => (write " "; write pat)) pats;
+                      write "\n"))
+
+val () = Env.action_one "indexOptions"
+        ("options", Env.list autoindex_option)
+        (fn opts =>
+            case opts of
+                [] => ()
+              | _ => (write "\tIndexOptions";
+                      app (fn (opt, arg) =>
+                              (write " ";
+                               write opt;
+                               Option.app (fn arg =>
+                                              (write "="; write arg)) arg)) opts;
+                      write "\n"))
+
+val () = Env.action_one "set_indexOptions"
+        ("options", Env.list autoindex_option)
+        (fn opts =>
+            case opts of
+                [] => ()
+              | _ => (write "\tIndexOptions";
+                      app (fn (opt, arg) =>
+                              (write " +";
+                               write opt;
+                               Option.app (fn arg =>
+                                              (write "="; write arg)) arg)) opts;
+                      write "\n"))
+
+val () = Env.action_one "unset_indexOptions"
+        ("options", Env.list autoindex_option)
+        (fn opts =>
+            case opts of
+                [] => ()
+              | _ => (write "\tIndexOptions";
+                      app (fn (opt, _) =>
+                              (write " -";
+                               write opt)) opts;
+                      write "\n"))
+
+val () = Env.action_one "headerName"
+        ("name", Env.string)
+        (fn name => (write "\tHeaderName ";
+                     write name;
+                     write "\n"))
+
+val () = Env.action_one "readmeName"
+        ("name", Env.string)
+        (fn name => (write "\tReadmeName ";
+                     write name;
+                     write "\n"))
+
 end
index 3987492..293a21d 100644 (file)
@@ -77,6 +77,17 @@ domain "hcoop.net" with
                location "/" with
                        davSvn "/home/adamc/svn";
                        authzSvnAccessFile "/home/adamc/svn/acl";
-               end
+               end;
+
+               addDescription "nada" [];
+               addDescription "Ultimate \"Awesome\" file" ["awesome.txt"];
+               addDescription "Runners up" ["prettyNeat.txt", "somewhatFunky.odp"];
+
+               indexOptions [iconsAreLinks, scanHtmlTitles, iconWidth 45];
+               set_indexOptions [descriptionWidth autofit, nameWidth (characters 13)];
+               unset_indexOptions [iconHeight 32, fancyIndexing];
+
+               headerName "header.html";
+               readmeName "readme.txt"
        end;
 end