Removed dependency on imported merjislib.
[cocanwiki.git] / scripts / cocanwiki_template.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: cocanwiki_template.ml,v 1.2 2004/09/07 14:58:34 rich Exp $
5  *)
6
7 open Apache
8 open Cgi
9
10 open Cocanwiki_files
11
12 (* Wrapper around [Cgi.Template.template] function which loads the
13  * template from a pre-defined path and sets up some default variables.
14  *)
15 let get_template =
16   let path =
17     try Sys.getenv "COCANWIKI_TEMPLATES"
18     with Not_found -> "/usr/share/cocanwiki/templates" in
19   let is_dir path =
20     try (Unix.stat path).Unix.st_kind = Unix.S_DIR
21     with Unix.Unix_error _ -> false in
22   if not (is_dir path) then
23     failwith ("environment variable $COCANWIKI_TEMPLATES " ^
24               "must be set to point to my 'templates' directory " ^
25               "(see README file for more details)");
26   fun filename ->
27     Template.template (path // filename)