- In the database, contents.sectionname is no longer 'not null'.
- Edit script has been changed to allow first section name to be
empty (setting contents.sectionname to null). Only for the
first section, however.
- Create script now creates an empty first sectionname by default.
- Page has been changed to render empty sectionnames properly (no
<h2> title or anchor).
id serial NOT NULL,
pageid integer NOT NULL,
ordering integer NOT NULL,
- sectionname text NOT NULL,
+ sectionname text,
content text NOT NULL,
divname text
);
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_diff.ml,v 1.3 2004/09/09 12:21:22 rich Exp $
+ * $Id: cocanwiki_diff.ml,v 1.4 2004/09/20 10:56:47 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
let css = sth#fetch1string () in
- let sth = dbh#prepare_cached "select sectionname, content
+ let sth = dbh#prepare_cached "select coalesce (sectionname, ''), content
from contents where pageid = ?
order by ordering" in
sth#execute [`Int version];
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: create.ml,v 1.5 2004/09/09 12:21:22 rich Exp $
+ * $Id: create.ml,v 1.6 2004/09/20 10:56:47 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
let pageid = sth#serial "pages_id_seq" in
(* Create a single section. *)
- let sectionname = "Section title - change this" in
let content = "Write some content here." in
let sth = dbh#prepare_cached "insert into contents (pageid, ordering,
sectionname, content) values (?, 1, ?, ?)" in
- sth#execute [`Int pageid; `String sectionname; `String content];
+ sth#execute [`Int pageid; `Null; `String content];
(* Commit. *)
dbh#commit ();
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: edit.ml,v 1.8 2004/09/09 12:21:22 rich Exp $
+ * $Id: edit.ml,v 1.9 2004/09/20 10:56:47 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
"(ie. not to a page which is itself a redirect).")
);
- (* All sections have sectionnames? *)
- List.iter (function (sectionnames, _, _)
- when string_is_whitespace sectionnames ->
- add_error ("Every section must have a title.");
- | _ -> ())
- model.contents;
+ (* All sections after the first one have sectionnames? The first
+ * section ONLY is allowed to have an empty title.
+ *)
+ if model.contents <> [] then
+ List.iter (function (sectionnames, _, _)
+ when string_is_whitespace sectionnames ->
+ add_error
+ ("Every section except the first must have a title.");
+ | _ -> ())
+ (List.tl model.contents);
get_errors ()
in
| _ -> assert false in
(* Get the sections. *)
- let sth = dbh#prepare_cached "select sectionname, content,
+ let sth = dbh#prepare_cached "select coalesce (sectionname, ''),
+ content,
coalesce (divname, '')
from contents
where pageid = ?
let divname =
if string_is_whitespace divname then `Null
else `String divname in
+ let sectionname =
+ if string_is_whitespace sectionname then `Null
+ else `String sectionname in
incr ordering; let ordering = !ordering in
sth#execute [`Int pageid; `Int ordering;
- `String sectionname; divname;
+ sectionname; divname;
`String content])
model.contents;
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.12 2004/09/17 15:24:54 rich Exp $
+ * $Id: page.ml,v 1.13 2004/09/20 10:56:47 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
let sections =
sth#map
- (function [`Int ordering; `String sectionname; `String content;
+ (function [`Int ordering;
+ (`Null | `String _) as sectionname;
+ `String content;
(`Null | `String _) as divname] ->
let divname, has_divname =
match divname with
`Null -> "", false
| `String divname -> divname, true in
+ let sectionname, has_sectionname =
+ match sectionname with
+ `Null -> "", false
+ | `String sectionname -> sectionname, true in
[ "ordering", Template.VarString (string_of_int ordering);
+ "has_sectionname", Template.VarConditional has_sectionname;
"sectionname", Template.VarString sectionname;
"content",
Template.VarString
::end::
::table(sections)::
-::if(has_divname)::<div id="::divname_html_tag::">::end::::if(can_edit)::<p class="edit_link">[<a href="/::page_html_tag::/edit#::ordering::" title="Edit this section">edit</a>]</p>::end::<a name="::sectionname_html_tag::"></a><h2>::sectionname_html::</h2>
+::if(has_divname)::<div id="::divname_html_tag::">::end::::if(can_edit)::<p class="edit_link">[<a href="/::page_html_tag::/edit#::ordering::" title="Edit this section">edit</a>]</p>::end::::if(has_sectionname)::<a name="::sectionname_html_tag::"></a><h2>::sectionname_html::</h2>::end::
::content::
::if(has_divname)::</div>::end::::end::