[Ur] Hamlet like XML, structured by indentation with tag autoclosing
Gabriel Riba
gabriel at xarxaire.com
Thu Jun 18 09:46:28 EDT 2015
This indented xml has been designed as a template system for the yesod
web framework (http://www.yesodweb.com/).
Lets make a comparison with equivalent code:
(* --- hamlet style template *)
fun mymodule items = <ixml>
<h3> title
<div>
$if {null items}
<p> Sorry, no items left
$else
<ul>
$forall {item} <- {items}
<li> <b>{[item]}</b>
</ixml>
(* ---------- without hamlet ---- *)
val emptyListSnippet = <xml>
<p> Sorry, no items left
</xml>
fun listItemSnippet item = <xml>
<li> <b>{[item]}</b> </li>
</xml>
fun listSnippet items =
List.foldr join <xml/> <|
List.map (fn item => listItemSnippet item) items
fun mymodule items =
<xml>
<h3>title</h3>
<div> { if null
then emptyListSnippet
else <xml>
<ul>
{listSnippet items}
</ul>
</xml>
}
</div>
</xml>
More information about the Ur
mailing list