From a4a6d811563406c446e4bcbdc6cf0d692bd9c219 Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 8 Sep 2004 17:07:24 +0000 Subject: [PATCH] Templating package now adds the standard stuff to every page. Added outline script and template to use as starting points. Switchable themes - added an 'easyweb' theme. --- html/_css/easyweb.css | 6 ++++++ html/_css/standard.css | 4 ++-- scripts/00-TEMPLATE.ml | 25 +++++++++++++++++++++++++ scripts/Makefile | 5 +++-- scripts/cocanwiki_template.ml | 37 +++++++++++++++++++++++++++++++++++-- scripts/page.ml | 28 +--------------------------- templates/00-TEMPLATE.html | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 html/_css/easyweb.css create mode 100644 scripts/00-TEMPLATE.ml create mode 100644 templates/00-TEMPLATE.html diff --git a/html/_css/easyweb.css b/html/_css/easyweb.css new file mode 100644 index 0000000..574ede7 --- /dev/null +++ b/html/_css/easyweb.css @@ -0,0 +1,6 @@ +/* Stylesheet for EWM. + * $Id: easyweb.css,v 1.1 2004/09/08 17:07:24 rich Exp $ + */ + +/* Based on the standard stylesheet. */ +@import url("/_css/standard.css"); \ No newline at end of file diff --git a/html/_css/standard.css b/html/_css/standard.css index 83ba185..efcdfbd 100644 --- a/html/_css/standard.css +++ b/html/_css/standard.css @@ -1,5 +1,5 @@ -/* Stylesheet for COCANWIKI, derived from EWM. - * $Id: standard.css,v 1.2 2004/09/08 14:01:17 rich Exp $ +/* Stylesheet for COCANWIKI. + * $Id: standard.css,v 1.3 2004/09/08 17:07:24 rich Exp $ */ body { diff --git a/scripts/00-TEMPLATE.ml b/scripts/00-TEMPLATE.ml new file mode 100644 index 0000000..50a4c41 --- /dev/null +++ b/scripts/00-TEMPLATE.ml @@ -0,0 +1,25 @@ +(* COCANWIKI scripts. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: 00-TEMPLATE.ml,v 1.1 2004/09/08 17:07:24 rich Exp $ + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = + let template = get_template dbh hostid "00-TEMPLATE.html" in + + + + + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/scripts/Makefile b/scripts/Makefile index 423e712..3d87b3f 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.9 2004/09/08 14:47:47 rich Exp $ +# $Id: Makefile,v 1.10 2004/09/08 17:07:24 rich Exp $ include ../Makefile.config @@ -21,7 +21,8 @@ LIB_OBJS := \ wikilib.cmo \ cgi_expires.cmo -OBJS := create.cmo \ +OBJS := 00-TEMPLATE.cmo \ + create.cmo \ create_form.cmo \ delete_file.cmo \ delete_file_form.cmo \ diff --git a/scripts/cocanwiki_template.ml b/scripts/cocanwiki_template.ml index 9e267da..58d45bb 100644 --- a/scripts/cocanwiki_template.ml +++ b/scripts/cocanwiki_template.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_template.ml,v 1.3 2004/09/08 15:46:52 rich Exp $ + * $Id: cocanwiki_template.ml,v 1.4 2004/09/08 17:07:24 rich Exp $ * * This module wraps around the Template library. It provides caching * of templates and fills in standard fields on a host-specific basis. @@ -25,6 +25,10 @@ let base = "(see README file for more details)"); base +(* The webserver gets restarted regularly enough that this is reasonable. *) +let { tm_year = year } = gmtime (time ()) +let year = year + 1900 + (* Cache of precompiled templates, arranged by full path. *) let cache = Hashtbl.create 32 @@ -53,6 +57,35 @@ let get_template (dbh : Dbi.connection) hostid filename = let template = _get_template filename in (* Get standard fields concerning this host from the database. *) - (* XXX *) + let sth = dbh#prepare_cached "select theme_css from hosts + where id = ?" in + sth#execute [`Int hostid]; + + let theme_css = + match sth#fetch1 () with + [ `Null ] -> "/_css/standard.css" + | [ `String file ] -> file + | _ -> assert false in + + template#set "theme_css" theme_css; + + (* Site menu. *) + let sth = dbh#prepare_cached "select url, label, ordering from sitemenu + where hostid = ? order by ordering" in + sth#execute [`Int hostid]; + + let table = sth#map (function [`String url; `String label; _] -> + [ "url", Template.VarString url; + "label", Template.VarString label ] + | _ -> assert false) in + + template#table "sitemenu" table; + + (* Wiki version. *) + template#set "cocanwiki_package" Cocanwiki_version.package; + template#set "cocanwiki_version" Cocanwiki_version.version; + + (* Copyright year. *) + template#set "year" (string_of_int year); template diff --git a/scripts/page.ml b/scripts/page.ml index 38eb595..c0979f0 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.8 2004/09/08 15:46:53 rich Exp $ + * $Id: page.ml,v 1.9 2004/09/08 17:07:24 rich Exp $ *) open Apache @@ -51,8 +51,6 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user = t#set "description" description; t#set "pageid" (string_of_int pageid); t#set "last_modified_date" (printable_date last_modified_date); - t#set "cocanwiki_package" Cocanwiki_version.package; - t#set "cocanwiki_version" Cocanwiki_version.version; if page <> page' then (* redirection *) ( t#set "page" page'; @@ -112,18 +110,6 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user = t#conditional "user_logged_in" true; t#set "username" username); - (* Site menu. *) - let sth = dbh#prepare_cached "select url, label, ordering from sitemenu - where hostid = ? order by ordering" in - sth#execute [`Int hostid]; - - let table = sth#map (function [`String url; `String label; _] -> - [ "url", Template.VarString url; - "label", Template.VarString label ] - | _ -> assert false) in - - t#table "sitemenu" table; - q#template t in @@ -147,18 +133,6 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user = t#conditional "can_edit" can_edit; t#conditional "can_manage_users" can_manage_users; - (* Site menu. *) - let sth = dbh#prepare_cached "select url, label, ordering from sitemenu - where hostid = ? order by ordering" in - sth#execute [`Int hostid]; - - let table = sth#map (function [`String url; `String label; _] -> - [ "url", Template.VarString url; - "label", Template.VarString label ] - | _ -> assert false) in - - t#table "sitemenu" table; - q#template t in diff --git a/templates/00-TEMPLATE.html b/templates/00-TEMPLATE.html new file mode 100644 index 0000000..4d9b283 --- /dev/null +++ b/templates/00-TEMPLATE.html @@ -0,0 +1,33 @@ + + + +XXX TITLE XXX + + + + + +

XXX TITLE XXX

+ + + + + +
+ + + + + \ No newline at end of file -- 1.8.3.1