summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2013-03-02 20:11:29 -0500
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2013-03-02 20:11:29 -0500
commit9d9935696b9c7dc8e70f6cab680f0363a7946601 (patch)
treeab2685cb3b6f9786fdac1a7d11ff2af378b9983b
parent1bfbe1736ceda8659a483cb3303a3ea67496458a (diff)
Add nice menu
-rw-r--r--main.ur50
-rw-r--r--site.urp1
2 files changed, 36 insertions, 15 deletions
diff --git a/main.ur b/main.ur
index efa1266..491d9b6 100644
--- a/main.ur
+++ b/main.ur
@@ -28,14 +28,45 @@ style content
style footer
-(*********************************** Main ************************************)
+(*********************************** Menus ***********************************)
+
+(* Generating nice menus is quite difficult in Ur/Web--there are a lot of links
+that the compiler needs to be convinced aren't broken. The link 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])
+
+(* 'getName' generates the link text given a 'pageName'. *)
+fun getName (n : pageName) : xbody =
+ match n { Main = fn () => <xml>Main</xml>,
+ Forum = fn () => <xml>Forum</xml> }
+
+(* Now we can do the actual menu generation code. *)
+fun menu (current : pageName) : xbody =
+ let fun item (target : pageName) (page : unit -> transaction page) =
+ if Variant.eq current target
+ then <xml><li class={active}>{getName target}</li></xml>
+ else <xml><li><a link={page ()}>{getName target}</a></li></xml>
+ in
+ <xml>
+ <ul class={navBar}>
+ {item (make [#Main] ()) main}
+ {item (make [#Forum] ()) forum}
+ </ul>
+ </xml>
+ end
+
+
+(*********************************** Pages ***********************************)
+(* These need to be mutually recursive with the menu code--otherwise, the menus
+can't link to all the pages. *)
-fun main () =
+and main () =
return <xml>
{headTag None}
<body>
<h1 class={siteTitle}><a link={main ()}>6.947 &ndash; Functional Programming Project Laboratory</a></h1>
- {menu ()}
+ {menu (make [#Main] ())}
<div class={content}>
<p>
Like <a href="//web.mit.edu/6.115/www/">6.115</a>, 6.947 is a chance to remember why you came to <span class={smallCaps}>mit</span>: to learn and to build.
@@ -47,15 +78,12 @@ fun main () =
</body>
</xml>
-
-(*********************************** Forum ***********************************)
-
and forum () =
return <xml>
{headTag (Some "Forum")}
<body>
<h1 class={siteTitle}><a link={main ()}>6.947 &ndash; Functional Programming Project Laboratory</a></h1>
- {menu ()}
+ {menu (make [#Forum] ())}
<div class={content}>
<p>
Coming soon!
@@ -82,14 +110,6 @@ and headTag (pageName : option string) : xhtml [] [] =
</xml>
end
-and menu () : xbody =
- <xml>
- <ul class={navBar}>
- <li><a link={main ()}>Main</a></li>
- <li><a link={forum ()}>Forum</a></li>
- </ul>
- </xml>
-
and licenseInfo () : xbody =
<xml>
<div class={footer}>
diff --git a/site.urp b/site.urp
index c2883f5..9f68007 100644
--- a/site.urp
+++ b/site.urp
@@ -10,5 +10,6 @@ rewrite style Main/navBar navBar
rewrite style Main/active active
rewrite style Main/content content
rewrite style Main/footer footer
+library meta
main