summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2013-03-16 16:25:45 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2013-03-16 16:25:45 -0400
commit5b8b76078ca1eb04ad787b1884b1c1e79b2273c8 (patch)
tree88f1e5a960781b16d93ecc63f351c721bf55503f
parent963ab32b176228017635e4ef1bb60555c4022142 (diff)
Decouple a bunch of stuff into Config and Template
-rw-r--r--config.ur24
-rw-r--r--config.urs27
-rw-r--r--main.ur43
-rw-r--r--menu.ur19
-rw-r--r--menu.urs8
-rw-r--r--site.urp2
-rw-r--r--template.ur55
-rw-r--r--template.urs21
8 files changed, 142 insertions, 57 deletions
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
+val baseUrlS = "/urweb/6.947"
+
+val siteTitle = <xml>6.947 &ndash; Functional Programming Project Laboratory</xml>
+
+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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
+(* 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 <http://www.gnu.org/licenses/>. *)
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
- <xml>
- <head>
- <title>{[titleString]}</title>
- <link rel="stylesheet" type="text/css" href="//bbaren.scripts.mit.edu/urweb/6.947-static/site.css"/>
- </head>
- <body>
- {content}
- <div class={footer}>
- <p>
- 6.947 is free software: you can redistribute it and/or modify it under the terms of the <a href="//gnu.org/licenses/agpl"><span class={smallCaps}>gnu</span> Affero General Public License</a> as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- </p>
-
- <p>
- 6.947 is distributed in the hope that it will be useful, but <span class={smallCaps}>without any warranty</span>; without even the implied warranty of <span class={smallCaps}>merchantability</span> or <span class={smallCaps}>fitness for a particular purpose</span>.
- See the <span class={smallCaps}>gnu</span> Affero General Public License for more details.
- </p>
-
- <p>
- You can get the 6.947 source code <a href="file:///afs/athena.mit.edu/user/b/b/bbaren/web_scripts/urweb/6.947/">via AFS</a>.
- </p>
- </div>
- </body>
- </xml>
- end
-
-
-(*********************************** Pages ***********************************)
-
-and main () =
- return (generic None <xml>
+fun main () =
+ return (Template.generic None <xml>
{Menu.header (make [#Main] ())}
<div class={content}>
<p>
@@ -69,7 +32,7 @@ and main () =
and forum () = forumWorker Forum.main
and forumWorker (f : unit -> xbody) =
- return (generic (Some "Forum") <xml>
+ return (Template.generic (Some "Forum") <xml>
{Menu.header (make [#Forum] ())}
{f ()}
</xml>)
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 () => <xml>Main</xml>,
Forum = fn () => <xml>Forum</xml> }
(* 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 <xml><li class={active}>{getName target}</li></xml>
else <xml><li><a href={getUrl target}>{getName target}</a></li></xml>
in
<xml>
- <h1 class={siteTitle}><a href={getUrl (make [#Main] ())}>6.947 &ndash; Functional Programming Project Laboratory</a></h1>
+ <h1 class={siteTitle}><a href={getUrl (make [#Main] ())}>{Config.siteTitle}</a></h1>
<ul class={navBar}>
{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 <http://www.gnu.org/licenses/>. *)
-(* 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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
+open Styles
+
+fun pageTitleTag nameOpt =
+ let val titleString =
+ case nameOpt of
+ | None => "6.947 – Functional Programming Project Laboratory"
+ | Some s => "6.947 – " ^ s
+ in
+ <xml>
+ <title>{[titleString]}</title>
+ </xml>
+ end
+
+fun generic (pageName : option string) (content : xbody) : xhtml [] [] =
+ <xml>
+ <head>
+ {pageTitleTag pageName}
+ <link rel="stylesheet" type="text/css" href="//bbaren.scripts.mit.edu/urweb/6.947-static/site.css"/>
+ </head>
+ <body>
+ {content}
+ <div class={footer}>
+ <p>
+ 6.947 is free software: you can redistribute it and/or modify it under the terms of the <a href="//gnu.org/licenses/agpl"><span class={smallCaps}>gnu</span> Affero General Public License</a> as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ </p>
+
+ <p>
+ 6.947 is distributed in the hope that it will be useful, but <span class={smallCaps}>without any warranty</span>; without even the implied warranty of <span class={smallCaps}>merchantability</span> or <span class={smallCaps}>fitness for a particular purpose</span>.
+ See the <span class={smallCaps}>gnu</span> Affero General Public License for more details.
+ </p>
+
+ <p>
+ You can get the 6.947 source code <a href="file:///afs/athena.mit.edu/user/b/b/bbaren/web_scripts/urweb/6.947/">via AFS</a>.
+ </p>
+ </div>
+ </body>
+ </xml>
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
+val generic : option string (* an optional page title *)
+ -> xbody (* the page content *)
+ -> page