diff navbar.urs @ 6:f17b869fbb71

Shifting some generic theme navigation menu code to the library.
author Karn Kallio <kkallio@eka>
date Tue, 26 Apr 2011 20:27:04 -0430
parents
children d314d2ec3300
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/navbar.urs	Tue Apr 26 20:27:04 2011 -0430
@@ -0,0 +1,52 @@
+(* NAVBAR provides services to construct and pretty print to xml typical
+ * menu items (of a visible text and a url link) and menu bars assembled
+ * from them.  It is intended to be used as a low-level component in
+ * constructing navigation related widgets and theme parts. *)
+
+type navItem
+(* Items in the navigation menu. *)
+
+con navBar :: Type -> Type
+(* A menu bar of navigation links. Up to one link may be active. *)
+
+type build
+type print
+(* These track the current navbar mode. *)
+
+class mode
+(* To make sure we always print the navbar correctly. *)
+
+val navToXml_build : mode build
+val navToXml_print : mode print
+(* How to print both modes. *)
+
+val printingNavBar : navBar build -> navBar print
+(* This switches the navbar from building mode to printing mode.  Normally not
+ * necessary to call this, but is in the signature in case the programmer will
+ * pass the same navbar to several components wanting to print it.  Then by
+ * using this first multiple (redundant) calls to List.rev can be avoided.
+ * Mode tracking makes this optimization safe. *)
+
+val emptyNavBar : navBar build
+(* An empty menu bar. *)
+
+val mkNavItem : string -> url -> navItem
+(* Make a menu item with visible text given by the string and linking to url. *)
+
+val navAdd : navItem -> navBar build -> navBar build
+(* Add an unactive item to the right end of the navbar. *)
+
+val navAddActive : navItem -> navBar build -> navBar build
+(* Add an active item to the right end of the navbar.  If there already
+ * was an active item it will be deactivated. *)
+
+val navItemToXml : option css_class -> navItem -> xbody
+(* Pretty print a navItem with an optional style to a piece of <a>...</a> xml. *)
+
+val navBarToXml : t ::: Type -> mode t -> navBar t -> xbody
+(* Pretty print the navigation menu as a piece of xml made of
+ * a chain <li><a>...</a></li> repeated. *)
+
+style active
+style last
+(* CSS classes to mark the active and last menu item. *)