[Haskell-cafe] ANNOUNCE: Bravo-0.1.0
matthias.reisner at googlemail.com
Thu Mar 11 23:37:38 EST 2010
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.
> On Wed, Mar 10, 2010 at 8:46 PM, Matthias Reisner <
> matthias.reisner at googlemail.com> wrote:
>> 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.
>> Matthias Reisner
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe