From 5b8b76078ca1eb04ad787b1884b1c1e79b2273c8 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 16 Mar 2013 16:25:45 -0400 Subject: Decouple a bunch of stuff into Config and Template --- config.ur | 24 ++++++++++++++++++++++++ config.urs | 27 +++++++++++++++++++++++++++ main.ur | 43 +++---------------------------------------- menu.ur | 19 +++++++------------ menu.urs | 8 +++----- site.urp | 2 ++ template.ur | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ template.urs | 21 +++++++++++++++++++++ 8 files changed, 142 insertions(+), 57 deletions(-) create mode 100644 config.ur create mode 100644 config.urs create mode 100644 template.ur create mode 100644 template.urs diff --git a/config.ur b/config.ur new file mode 100644 index 0000000..387dd81 --- /dev/null +++ b/config.ur @@ -0,0 +1,24 @@ +(* Config -- site-wide configuration +Copyright (C) 2013 Benjamin Barenblat + +This file is a part of 6.947. + +6.947 is is free software: you can redistribute it and/or modify it under the +terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +6.947 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more +details. + +You should have received a copy of the GNU Affero General Public License along +with 6.947. If not, see . *) + +val baseUrlS = "/urweb/6.947" + +val siteTitle = 6.947 – Functional Programming Project Laboratory + +con pageName = variant (mapU unit [Main, Forum]) + diff --git a/config.urs b/config.urs new file mode 100644 index 0000000..5cc552c --- /dev/null +++ b/config.urs @@ -0,0 +1,27 @@ +(* Config -- site-wide configuration +Copyright (C) 2013 Benjamin Barenblat + +This file is a part of 6.947. + +6.947 is is free software: you can redistribute it and/or modify it under the +terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +6.947 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more +details. + +You should have received a copy of the GNU Affero General Public License along +with 6.947. If not, see . *) + +(* The base URL for the site *) +val baseUrlS : string + +(* The name of the site *) +val siteTitle : xbody + +(* The menu scheme in this app is based on a variant 'pageName', which +describes the name of the page. There's one value for each page. *) +con pageName = variant (mapU unit [Main, Forum]) diff --git a/main.ur b/main.ur index 1d3483b..7fe5845 100644 --- a/main.ur +++ b/main.ur @@ -18,45 +18,8 @@ with 6.947. If not, see . *) open Styles - -(********************************* Template **********************************) - -fun generic (pageName : option string) (content : xbody) : xhtml [] [] = - let val titleString : string = - case pageName of - | None => "6.947 – Functional Programming Project Laboratory" - | Some s => "6.947 – " ^ s - in - - - {[titleString]} - - - - {content} -
-

- 6.947 is free software: you can redistribute it and/or modify it under the terms of the gnu Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -

- -

- 6.947 is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. - See the gnu Affero General Public License for more details. -

- -

- You can get the 6.947 source code via AFS. -

-
- -
- end - - -(*********************************** Pages ***********************************) - -and main () = - return (generic None +fun main () = + return (Template.generic None {Menu.header (make [#Main] ())}

@@ -69,7 +32,7 @@ and main () = and forum () = forumWorker Forum.main and forumWorker (f : unit -> xbody) = - return (generic (Some "Forum") + return (Template.generic (Some "Forum") {Menu.header (make [#Forum] ())} {f ()} ) diff --git a/menu.ur b/menu.ur index 4be6d3d..83d6176 100644 --- a/menu.ur +++ b/menu.ur @@ -25,30 +25,25 @@ and it's no more unsafe than anything you'd do in a "normal" Web framework. *) open Styles -con pageName = variant (mapU unit [Main, Forum]) - (* Generates the link text *) -fun getName (n : pageName) : xbody = +fun getName (n : Config.pageName) : xbody = match n { Main = fn () => Main, Forum = fn () => Forum } (* Generates the link URL *) -fun getUrl (n : pageName) : url = - let val base = "/urweb/6.947" - in - match n { Main = fn () => bless (base ^ "/index"), - Forum = fn () => bless (base ^ "/forum") } - end +fun getUrl (n : Config.pageName) : url = + match n { Main = fn () => bless (Config.baseUrlS ^ "/index"), + Forum = fn () => bless (Config.baseUrlS ^ "/forum") } (* Actual title and menu generation code *) -fun header (current : pageName) : xbody = - let fun item (target : pageName) = +fun header (current : Config.pageName) : xbody = + let fun item (target : Config.pageName) = if Variant.eq current target then

  • {getName target}
  • else
  • {getName target}
  • in -

    6.947 – Functional Programming Project Laboratory

    +

    {Config.siteTitle}

      {item (make [#Main] ())} {item (make [#Forum] ())} diff --git a/menu.urs b/menu.urs index 0372aab..59f02f1 100644 --- a/menu.urs +++ b/menu.urs @@ -16,8 +16,6 @@ details. You should have received a copy of the GNU Affero General Public License along with 6.947. If not, see . *) -(* The menu scheme in this app is based on a variant 'pageName', which -describes the name of the page. There's one value for each page. *) -con pageName = variant (mapU unit [Main, Forum]) - -val header : pageName -> xbody +(* Given the name of the page we're currently on, produces a header and menu +for the site. *) +val header : Config.pageName -> xbody diff --git a/site.urp b/site.urp index 03d4efe..2996194 100644 --- a/site.urp +++ b/site.urp @@ -17,6 +17,8 @@ rewrite url Main/* library meta library forum +config styles +template menu main diff --git a/template.ur b/template.ur new file mode 100644 index 0000000..0ba4c18 --- /dev/null +++ b/template.ur @@ -0,0 +1,55 @@ +(* Template -- site templates +Copyright (C) 2013 Benjamin Barenblat + +This file is a part of 6.947. + +6.947 is is free software: you can redistribute it and/or modify it under the +terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +6.947 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more +details. + +You should have received a copy of the GNU Affero General Public License along +with 6.947. If not, see . *) + +open Styles + +fun pageTitleTag nameOpt = + let val titleString = + case nameOpt of + | None => "6.947 – Functional Programming Project Laboratory" + | Some s => "6.947 – " ^ s + in + + {[titleString]} + + end + +fun generic (pageName : option string) (content : xbody) : xhtml [] [] = + + + {pageTitleTag pageName} + + + + {content} +
      +

      + 6.947 is free software: you can redistribute it and/or modify it under the terms of the gnu Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +

      + +

      + 6.947 is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. + See the gnu Affero General Public License for more details. +

      + +

      + You can get the 6.947 source code via AFS. +

      +
      + +
      diff --git a/template.urs b/template.urs new file mode 100644 index 0000000..f94bd47 --- /dev/null +++ b/template.urs @@ -0,0 +1,21 @@ +(* Template -- site templates +Copyright (C) 2013 Benjamin Barenblat + +This file is a part of 6.947. + +6.947 is is free software: you can redistribute it and/or modify it under the +terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +6.947 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more +details. + +You should have received a copy of the GNU Affero General Public License along +with 6.947. If not, see . *) + +val generic : option string (* an optional page title *) + -> xbody (* the page content *) + -> page -- cgit v1.2.3