
Hello, I'm pleased to announce the first release of Bravo, a static text template generation library, on Hackage: http://hackage.haskell.org/package/Bravo. Bravo is a text template library that provides parsing and generation of templates at compile time. Templates can be read from strings or files and for each a new record data type is created, allowing convenient access to all template variables in a type-safe manner. Since all templates are processed at compile time, no extra file access or error handling at runtime is necessary. Bravo is inspired by the PHP template engine Smarty and the Haskell template library chunks. Compared to chunks, Bravo provides additional features like conditional template evaluation, embedding of Haskell expressions and customized data type generation. I'm going to add further information to the HaskellWiki page (http://www.haskell.org/haskellwiki/Bravo) later. Bravo is still highly experimental and not well-tested, so bug reports and additional feedback are very welcome. I'd also like to hear if you feel the package dependencies are to restrictive. Regards, Matthias Reisner

Hi Marc, I'm sorry, the current Bravo version does not support caching of evaluated templates. Maybe this will be a feature of later releases. Matthias Am 11.03.2010 10:02 schrieb Marc Weber:
Hi Matthias,
Bravo is inspired by the PHP template engine Smarty and the Haskell
Smarty is also about caching. Can you say whether your library support kind of caching as well?
Marc Weber

Am 11.03.2010 23:38 schrieb Simon Michael:
Thank you, how does it compare to HStringTemplate ?
Hi Simon, I never worked with HStringTemplate, so as far as I can tell after having a glance at the HStringTemplate API and the wiki page, the main difference is that Bravo parses the templates at compile time, while HStringTemplate does at runtime. Besides that, HStringTemplate provides several methods for rendering different data types in different styles. This can also be accomplished in Bravo by writing the appropriate rendering function in your Haskell code and using it in the template. Regards, Matthias

Matthis, Thank you for releasing this library, it looks very intriguing. I've been building web apps using HStringTemplate up until now, and one thing that always irks me is that- while the rest of my program is checked at compile-time- my template results need to be checked manually at runtime. One of my todo-list items was to write a library that fixed this: it looks like yours does just that. I'll need to look into the library a bit more to get a better idea, but it seems like Bravo could work for my needs. One thing that concerns me is your comment that it allows embedding of Haskell expressions. In general, I try to keep a strict separation between login and presentation: can you explain exactly what type of expressions can be embedded? Also, while looking through the example, it looks like the library is making some automatic translations, like firstName -> userFirstName and user -> users. I've found these kinds of mappings to be brittle in the past; can you explain how this is done (or if I'm simply missing something obvious)? Finally, I can't seem to get it to compile on 6.12. Any chance of getting a version out that supports it? Thanks, Michael On Wed, Mar 10, 2010 at 8:46 PM, Matthias Reisner < matthias.reisner@googlemail.com> wrote:
Hello,
I'm pleased to announce the first release of Bravo, a static text template generation library, on Hackage: http://hackage.haskell.org/package/Bravo.
Bravo is a text template library that provides parsing and generation of templates at compile time. Templates can be read from strings or files and for each a new record data type is created, allowing convenient access to all template variables in a type-safe manner. Since all templates are processed at compile time, no extra file access or error handling at runtime is necessary.
Bravo is inspired by the PHP template engine Smarty and the Haskell template library chunks. Compared to chunks, Bravo provides additional features like conditional template evaluation, embedding of Haskell expressions and customized data type generation. I'm going to add further information to the HaskellWiki page ( http://www.haskell.org/haskellwiki/Bravo) later.
Bravo is still highly experimental and not well-tested, so bug reports and additional feedback are very welcome. I'd also like to hear if you feel the package dependencies are to restrictive.
Regards,
Matthias Reisner _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Michael Am 12.03.2010 01:33 schrieb Michael Snoyman:
I'll need to look into the library a bit more to get a better idea, but it seems like Bravo could work for my needs. One thing that concerns me is your comment that it allows embedding of Haskell expressions. In general, I try to keep a strict separation between login and presentation: can you explain exactly what type of expressions can be embedded?
This is really one disadvantage of the current Bravo version I'm worrying about too. At the moment you can insert arbitrary Haskell expressions, so no one prevents the template writer from inserting expressions like `unsafePerformIO launchAtomicMissile >> return ""'. Some kind of security mechanism will definitely be included in future releases, but I'm not sure in what way at the moment. I thought about passing a list of permitted function names to the template creation function and then failing with an error if any other functions are used.
Also, while looking through the example, it looks like the library is making some automatic translations, like firstName -> userFirstName and user -> users. I've found these kinds of mappings to be brittle in the past; can you explain how this is done (or if I'm simply missing something obvious)?
Bravo creates a data type per template, where the default naming scheme for the data type/constructor name is "name" -> "TplName". For each template variable a record field is created; for a template "temp" and a variable "var" the name will be "tempVar". Have a look at the `mkTemplatesWithOptions' and `mkTemplatesFromFileWithOptions' functions, that allow you to customize this naming scheme.
Finally, I can't seem to get it to compile on 6.12. Any chance of getting a version out that supports it?
The problem seems to be haskell-src-meta, that doesn't like template-haskell-2.4, and on the other side I can't get build template-haskell < 2.4 with GHC-6.12. So I will contact Matt Morrow, the maintainer of haskell-src-meta, and see if he can fix it. Regards, Matthias
Thanks, Michael
On Wed, Mar 10, 2010 at 8:46 PM, Matthias Reisner < matthias.reisner@googlemail.com> wrote:
Hello,
I'm pleased to announce the first release of Bravo, a static text template generation library, on Hackage: http://hackage.haskell.org/package/Bravo.
Bravo is a text template library that provides parsing and generation of templates at compile time. Templates can be read from strings or files and for each a new record data type is created, allowing convenient access to all template variables in a type-safe manner. Since all templates are processed at compile time, no extra file access or error handling at runtime is necessary.
Bravo is inspired by the PHP template engine Smarty and the Haskell template library chunks. Compared to chunks, Bravo provides additional features like conditional template evaluation, embedding of Haskell expressions and customized data type generation. I'm going to add further information to the HaskellWiki page ( http://www.haskell.org/haskellwiki/Bravo) later.
Bravo is still highly experimental and not well-tested, so bug reports and additional feedback are very welcome. I'd also like to hear if you feel the package dependencies are to restrictive.
Regards,
Matthias Reisner _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Am 12.03.2010 05:37 schrieb Matthias Reisner:
Hi Michael
Am 12.03.2010 01:33 schrieb Michael Snoyman:
I'll need to look into the library a bit more to get a better idea, but it seems like Bravo could work for my needs. One thing that concerns me is your comment that it allows embedding of Haskell expressions. In general, I try to keep a strict separation between login and presentation: can you explain exactly what type of expressions can be embedded?
This is really one disadvantage of the current Bravo version I'm worrying about too. At the moment you can insert arbitrary Haskell expressions, so no one prevents the template writer from inserting expressions like `unsafePerformIO launchAtomicMissile >> return ""'. Some kind of security mechanism will definitely be included in future releases, but I'm not sure in what way at the moment. I thought about passing a list of permitted function names to the template creation function and then failing with an error if any other functions are used.
Today I thought about a security mechanism for Bravo and came to the simple solution: There actually is no need for it! If you don't trust your template writers, just do the following: Create a new module and import all functions you permit to be used in your templates (or hide functions from the Prelude). Call the template creation functions within this module and export all created data structures. Perhaps different templates may access different sets of permitted functions, so just create a module for each of these sets. Meanwhile I created the wiki page for Bravo and added an example that illustrates the problem (see http://www.haskell.org/haskellwiki/Bravo#Security_concerns).
Finally, I can't seem to get it to compile on 6.12. Any chance of getting a version out that supports it?
The problem seems to be haskell-src-meta, that doesn't like template-haskell-2.4, and on the other side I can't get build template-haskell < 2.4 with GHC-6.12. So I will contact Matt Morrow, the maintainer of haskell-src-meta, and see if he can fix it.
Matt didn't reply yet, but there already is a patched haskell-src-meta version available at http://moonpatio.com/repos/haskell-src-meta_NEW_TH. I updated Bravo to be compatible with this version. Regards, Matthias
participants (4)
-
Marc Weber
-
Matthias Reisner
-
Michael Snoyman
-
Simon Michael