From 7130fa13b57c8f83e30781ad9030f8759a0dedbe Mon Sep 17 00:00:00 2001 From: rich Date: Sun, 17 Oct 2004 19:43:19 +0000 Subject: [PATCH] Fixes a couple of personal bugbears: (1) On the sitemenu, each
  • has an automatically generated, unique ID, to ease styling. (2) Sitemenu entries are no longer linked if they refer to the currently displayed page. --- scripts/.depend | 8 ++++---- scripts/Makefile | 4 ++-- scripts/cocanwiki_template.ml | 31 ++++++++++++++++++++++++++++--- scripts/cocanwiki_template.mli | 8 +++++--- scripts/page.ml | 8 ++++---- templates/page.html | 4 ++-- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/scripts/.depend b/scripts/.depend index f7211ea..e29f997 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -31,10 +31,10 @@ cocanwiki_pages.cmo: cocanwiki.cmo cocanwiki_links.cmi cocanwiki_strings.cmo \ wikilib.cmi cocanwiki_pages.cmi cocanwiki_pages.cmx: cocanwiki.cmx cocanwiki_links.cmx cocanwiki_strings.cmx \ wikilib.cmx cocanwiki_pages.cmi -cocanwiki_template.cmo: cocanwiki_files.cmo cocanwiki_version.cmo \ - cocanwiki_template.cmi -cocanwiki_template.cmx: cocanwiki_files.cmx cocanwiki_version.cmx \ - cocanwiki_template.cmi +cocanwiki_template.cmo: cocanwiki.cmo cocanwiki_files.cmo \ + cocanwiki_strings.cmo cocanwiki_version.cmo cocanwiki_template.cmi +cocanwiki_template.cmx: cocanwiki.cmx cocanwiki_files.cmx \ + cocanwiki_strings.cmx cocanwiki_version.cmx cocanwiki_template.cmi contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx contact_show.cmo: cocanwiki.cmo cocanwiki_template.cmi diff --git a/scripts/Makefile b/scripts/Makefile index 39afce8..af48c84 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.40 2004/10/14 15:57:15 rich Exp $ +# $Id: Makefile,v 1.41 2004/10/17 19:43:19 rich Exp $ include ../Makefile.config @@ -16,9 +16,9 @@ LIB_OBJS := \ cocanwiki_files.cmo \ cocanwiki_strings.cmo \ cocanwiki_images.cmo \ + cocanwiki_server_settings.cmo \ cocanwiki_template.cmo \ cocanwiki_ok.cmo \ - cocanwiki_server_settings.cmo \ cocanwiki.cmo \ cocanwiki_diff.cmo \ cocanwiki_emailnotify.cmo \ diff --git a/scripts/cocanwiki_template.ml b/scripts/cocanwiki_template.ml index 9759cd5..1ad7695 100644 --- a/scripts/cocanwiki_template.ml +++ b/scripts/cocanwiki_template.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_template.ml,v 1.5 2004/09/09 12:21:22 rich Exp $ + * $Id: cocanwiki_template.ml,v 1.6 2004/10/17 19:43:19 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,16 @@ open Unix open Cocanwiki_files +open Cocanwiki_strings +open Cocanwiki + +(* This is used to generate the id fields from URLs on the site menu. *) +let id_of_url str = + let str = String.copy str in + for i = 0 to String.length str - 1 do + if not (isalnum str.[i]) then str.[i] <- '_' + done; + str let base = let base = @@ -68,7 +78,7 @@ let _get_template filename = Hashtbl.replace cache path (template, mtime); template -let get_template (dbh : Dbi.connection) hostid filename = +let get_template ?page (dbh : Dbi.connection) hostid filename = let template = _get_template filename in (* Get standard fields concerning this host from the database. *) @@ -89,9 +99,24 @@ let get_template (dbh : Dbi.connection) hostid filename = where hostid = ? order by ordering" in sth#execute [`Int hostid]; + let is_homepage = + match page with + | None -> false + | Some "index" -> true + | _ -> false in + template#conditional "is_homepage" is_homepage; + let table = sth#map (function [`String url; `String label; _] -> + let is_linked = + match page with + | None -> true + | Some page when page = url -> false + | _ -> true in + let id = id_of_url url in [ "url", Template.VarString url; - "label", Template.VarString label ] + "label", Template.VarString label; + "is_linked", Template.VarConditional is_linked; + "id", Template.VarString id ] | _ -> assert false) in template#table "sitemenu" table; diff --git a/scripts/cocanwiki_template.mli b/scripts/cocanwiki_template.mli index c633185..782b4f7 100644 --- a/scripts/cocanwiki_template.mli +++ b/scripts/cocanwiki_template.mli @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_template.mli,v 1.2 2004/09/09 12:21:22 rich Exp $ + * $Id: cocanwiki_template.mli,v 1.3 2004/10/17 19:43:19 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,5 +22,7 @@ (** Get template from filename, with no host-specific substitutions. *) val _get_template : string -> Template.template -(** Get template from filename, with host-specific substitutions. *) -val get_template : Dbi.connection -> int -> string -> Template.template +(** Get template from filename, with host-specific substitutions. + * The special ~page parameter is only used by [page.ml]. + *) +val get_template : ?page:string -> Dbi.connection -> int -> string -> Template.template diff --git a/scripts/page.ml b/scripts/page.ml index bfd7bd6..3657919 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.32 2004/10/10 19:19:58 rich Exp $ + * $Id: page.ml,v 1.33 2004/10/17 19:43:19 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,12 +56,12 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid ({ edit_anon = edit_anon; view_anon = view_anon } as host) user = - let template_page = get_template dbh hostid "page.html" in - let template_404 = get_template dbh hostid "page_404.html" in - let page = q#param "page" in let page = if page = "" then "index" else page in + let template_page = get_template ~page dbh hostid "page.html" in + let template_404 = get_template dbh hostid "page_404.html" in + (* Host-specific fields. *) let sth = dbh#prepare_cached "select css is not null, feedback_email is not null, diff --git a/templates/page.html b/templates/page.html index 7ecd188..97efd3d 100644 --- a/templates/page.html +++ b/templates/page.html @@ -54,8 +54,8 @@