From 9d9935696b9c7dc8e70f6cab680f0363a7946601 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 2 Mar 2013 20:11:29 -0500 Subject: Add nice menu --- main.ur | 50 +++++++++++++++++++++++++++++++++++--------------- site.urp | 1 + 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 () => Main, + Forum = fn () => Forum } + +(* 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
  • {getName target}
  • + else
  • {getName target}
  • + in + + + + 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 {headTag None}

    6.947 – Functional Programming Project Laboratory

    - {menu ()} + {menu (make [#Main] ())}

    Like 6.115, 6.947 is a chance to remember why you came to mit: to learn and to build. @@ -47,15 +78,12 @@ fun main () = - -(*********************************** Forum ***********************************) - and forum () = return {headTag (Some "Forum")}

    6.947 – Functional Programming Project Laboratory

    - {menu ()} + {menu (make [#Forum] ())}

    Coming soon! @@ -82,14 +110,6 @@ and headTag (pageName : option string) : xhtml [] [] = end -and menu () : xbody = - -

    - - and licenseInfo () : xbody =
    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 -- cgit v1.2.3