3 ms·
Reminds me of the “Shakespearean Templates“ [1] from the Yesod web framework [2]. [1]: https://www.oreilly.com/library/view/developing-web-applications/9781449
by one-punch 6y ago
Reminds me of the “Shakespearean Templates“ [1] from the Yesod web framework [2].
[1]: https://www.oreilly.com/library/view/developing-web-applications/9781449336868/ch04.html https://www.oreilly.com/library/view/developing-web-applicat...
[2]: https://www.yesodweb.com/ https://www.yesodweb.com/
Copied below to save you a click:
Hamlet (HTML)
$doctype 5
<html>
<head>
<title>#{pageTitle} - My Site
<link rel=stylesheet href=@{Stylesheet}>
<body>
<h1 .page-title>#{pageTitle}
<p>Here is a list of your friends:
$if null friends
<p>Sorry, I lied, you don't have any friends.
$else
<ul>
$forall Friend name age <- friends
<li>#{name} (#{age} years old)
<footer>^{copyright}
Cassius (CSS)
#myid
color: #{red}
font-size: #{bodyFontSize}
foo bar baz
background-image: url(@{MyBackgroundR})
Lucius (CSS)
section.blog {
padding: 1em;
border: 1px solid #000;
h1 {
color: #{headingColor};
}
}
Julius (JavaScript)
$(function(){
$("section.#{sectionClass}").hide();
$("#mybutton").click(function(){document.location = "@{SomeRouteR}";});
^{addBling}
});
For those curious, the above is implemented in the metaprogramming framework of Template Haskell.
- eyelidlessness 6y agoDoes Hamlet produce structured data, or a string?
- one-punch 6y agoIt produces structured data (the `MarkupM` datatype from `blaze` to be precise [1]). To check this, note that Hamlet produces `Html` [2], which (when following the link) is defined to be `Markup` [3], which is in turn `MarkupM` [4]. [1]: https://hackage.haskell.org/package/blaze-markup-0.8.2.3/docs/Text-Blaze-Internal.html#t:MarkupM https://hackage.haskell.org/package/blaze-markup-0.8.2.3/doc... [2]: https://hackage.haskell.org/package/shakespeare-2.0.24/docs/Text-Hamlet.html#g:2 https://hackage.haskell.org/package/shakespeare-2.0.24/docs/... [3]: https://hackage.haskell.org/package/shakespeare-2.0.24/docs/Text-Hamlet.html#t:Html https://hackage.haskell.org/package/shakespeare-2.0.24/docs/... [4]: https://hackage.haskell.org/package/blaze-markup-0.8.2.3/docs/Text-Blaze-Internal.html#t:Markup https://hackage.haskell.org/package/blaze-markup-0.8.2.3/doc...