<div dir="ltr">Thanks for the input everyone. I&#39;ve just pushed the new Hamlet runtime code to github[1]. Instead of using data-object, I&#39;ve created a new datatype: HamletData[2]. Runtime templates support *almost* the entirety of valid Hamlet documents; the only exception is complicated references, such as:<div>
<br></div><div>$(foo.bar).baz$</div><div><br></div><div>I don&#39;t think this should be a problem in real life; that syntax was only added to support functions with multiple arguments, and since runtime templates don&#39;t deal with functions, it should work just fine.</div>
<div><br></div><div>I&#39;d appreciate feedback on this before releasing. I&#39;m planning on making this version 0.4.2. When I *do* make a release, I&#39;ll most likely accompany it with a blog post explaining how to use it, and discuss when you should use runtime versus quasi-quoted templates.</div>
<div><br></div><div>Michael<br><div><br></div><div>[1] <a href="http://github.com/snoyberg/hamlet">http://github.com/snoyberg/hamlet</a></div><div><a href="http://github.com/snoyberg/hamlet"></a>[2] <a href="http://github.com/snoyberg/hamlet/blob/master/Text/Hamlet/RT.hs#L21">http://github.com/snoyberg/hamlet/blob/master/Text/Hamlet/RT.hs#L21</a><br>
<br><div class="gmail_quote">On Sat, Jul 31, 2010 at 10:34 PM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr">Hey all,<div><br></div><div>An often-mentioned &quot;cool feature&quot; for Hamlet would be to support runtime parsing/rendering of templates. Currently, the only supported method is quasi-quoting a template and thereby have it parsed into Haskell code at compile time. In my opinion, this is definitely the preferred way of using Hamlet, as it gives you very solid compile-time guarantees of correct syntax and type safety. Nonetheless, there are some use cases (static site generation via Hakyll, a hamlet-to-html tool, etc) that would really benefit from runtime parsing.</div>

<div><br></div><div>It turns out this is pretty simple to add, except for one thing: I can&#39;t figure out a good API for passing in variables for a template. Hamlet templates have essentially four different datatypes they recognize:</div>

<div><br></div><div>* Html</div><div>* Some URL data type</div><div>* That same URL datatype along with a [(String, String)] to represent query-string parameters</div><div>* A Hamlet template</div><div><br></div><div>In addition, $forall and $maybe need lists and Maybe values, respectively. Variable lookup is handled by a tree, which allows you to express arbitrary function application. $if requires Bools.</div>

<div><br></div><div>So the question is, what should an API look like? The parse function is fairly straight-forward:</div><div><br></div><div>parseHamletRT :: HamletSettings -&gt; String -&gt; Either HamletException HamletRT</div>

<div><br></div><div>However, the render function is more complicated. I&#39;ve toyed with a few possible ideas:</div><div><br></div><div>* Use the data-object package with some complicated HamletData datatype.</div><div>
* Just do the complicated HamletData datatype.</div>
<div>* Type lookup functions as parameters.</div><div>* Disallow most of the more complicated features in Hamlet, like URL and subtemplates, and just allow dollar-sign interpolation with $forall and $if. That tree datatype for variable names could be collapsed into a [String].</div>

<div><br></div><div>Thoughts on the matter are welcome, as well as sample use cases you have for such a function.</div><div><br></div><font color="#888888"><div>Michael</div></font></div>
</blockquote></div><br></div></div></div>