Allow empty <h2> first.
authorrich <rich>
Mon, 20 Sep 2004 10:56:46 +0000 (10:56 +0000)
committerrich <rich>
Mon, 20 Sep 2004 10:56:46 +0000 (10:56 +0000)
 - 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).

cocanwiki.sql
scripts/cocanwiki_diff.ml
scripts/create.ml
scripts/edit.ml
scripts/page.ml
templates/page.html

index ac84730..32b0387 100644 (file)
@@ -73,7 +73,7 @@ CREATE TABLE contents (
     id serial NOT NULL,
     pageid integer NOT NULL,
     ordering integer NOT NULL,
-    sectionname text NOT NULL,
+    sectionname text,
     content text NOT NULL,
     divname text
 );
index 8bfd4af..97f4b65 100644 (file)
@@ -1,7 +1,7 @@
 (* 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
@@ -59,7 +59,7 @@ let get_version_for_diff (dbh : Dbi.connection) version =
 
     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];
index d33dd5c..a1d1d72 100644 (file)
@@ -1,7 +1,7 @@
 (* 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
@@ -69,12 +69,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
   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 ();
index 47ab1fc..bf7b482 100644 (file)
@@ -1,7 +1,7 @@
 (* 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
@@ -118,12 +118,16 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
                   "(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
@@ -247,7 +251,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
        | _ -> 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 = ?
@@ -429,9 +434,12 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
                   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;
 
index 70c25b3..b219afa 100644 (file)
@@ -1,7 +1,7 @@
 (* 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
@@ -94,13 +94,20 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user =
 
     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
index e32169e..c5011b1 100644 (file)
@@ -31,7 +31,7 @@
 ::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::