From 8de6e1df62557daa55fd3eb2a073a7871ddf9768 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 2 Mar 2013 20:32:04 -0500 Subject: Decouple template from heading/menu generation --- main.ur | 70 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/main.ur b/main.ur index 76082f9..03bb2fe 100644 --- a/main.ur +++ b/main.ur @@ -28,38 +28,9 @@ style content style footer -(*********************************** 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 - - (********************************* Template **********************************) -and generic (pageName : option string) (menuAndContent : xbody) : xhtml [] [] = +fun generic (pageName : option string) (content : xbody) : xhtml [] [] = let val titleString : string = case pageName of | None => "6.947 – Functional Programming Project Laboratory" @@ -71,8 +42,7 @@ and generic (pageName : option string) (menuAndContent : xbody) : xhtml [] [] = -

    6.947 – Functional Programming Project Laboratory

    - {menuAndContent} + {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. @@ -92,11 +62,42 @@ and generic (pageName : option string) (menuAndContent : xbody) : xhtml [] [] = end +(******************************* Page headings *******************************) + +(* Generating nice headings and 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 title and menu generation code. *) +fun header (current : pageName) : xbody = + let fun item (target : pageName) (page : unit -> transaction page) = + if Variant.eq current target + then

  • {getName target}
  • + else
  • {getName target}
  • + in + +

    6.947 – Functional Programming Project Laboratory

    +
      + {item (make [#Main] ()) main} + {item (make [#Forum] ()) forum} +
    +
    + end + + (*********************************** Pages ***********************************) and main () = return (generic None - {menu (make [#Main] ())} + {header (make [#Main] ())}

    Like 6.115, 6.947 is a chance to remember why you came to mit: to learn and to build. @@ -108,10 +109,11 @@ and main () = and forum () = return (generic (Some "Forum") - {menu (make [#Forum] ())} + {header (make [#Forum] ())}

    Coming soon!

    ) + -- cgit v1.2.3