[Haskell-cafe] ANNOUNCE: plat

Miguel Mitrofanov miguelimo38 at yandex.ru
Wed Oct 31 07:40:35 CET 2012

My current project at work has a web interface. Therefore I needed an HTML templating library. I've tried several and found them all unsatisfactory. Most of them generate Haskell code from templates (with Template Haskell or a separate utility), and I don't like metaprogramming; and recompiling the program every time you make a small change in the template kinda defeats the purpose. Other libraries make it PITA to implement basic things, like iterating over an array. So, I'm proud to announce the first release of another template library: plat- (http://hackage.haskell.org/package/plat).

An example of what it does. If your data looks like

do "name" =: "Mac's tools"
   "staff" =: [
    do "index" =: "1"
       "name" =: "Alice"
    do "name" =: "Bob"
       "index" =: "2"
       "bad" =: True
    do "index" =: "3"
       "name" =: "Nicolás"

and your template is

List of employees at @name:
@person.index at .. @person.name@{@!person.bad (going to be fired)@|@}@
@]@# There won't be an empty line in the result

Then the result you get would be this:

List of employees at Mac's tools:
1. Alice
2. Bob (going to be fired)
3. Nicolás

Keep in mind, that it's actually a string template library, and the resulting string doesn't have to be valid HTML, or any HTML at all.

I haven't benchmarked this library - since I intended to use it for web interface in an program which won't be released outside, speed was not in my priorities; but I'll work on that in future versions.

Also, templates are supposed to be in UTF-8, as I've successfully forgot all about other encodings. So, if you want binary templates, I'm afraid, this library is not for you.

More information about the Haskell-Cafe mailing list