diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2013-03-02 20:11:29 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2013-03-02 20:11:29 -0500 |
commit | 9d9935696b9c7dc8e70f6cab680f0363a7946601 (patch) | |
tree | ab2685cb3b6f9786fdac1a7d11ff2af378b9983b | |
parent | 1bfbe1736ceda8659a483cb3303a3ea67496458a (diff) |
Add nice menu
-rw-r--r-- | main.ur | 50 | ||||
-rw-r--r-- | site.urp | 1 |
2 files changed, 36 insertions, 15 deletions
@@ -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 – 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 – 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}> @@ -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 |