[Haskell-cafe] Re: HStringTemplate to generate html tables
Sterling Clover
s.clover at gmail.com
Thu Sep 18 18:30:12 EDT 2008
Hmm... an untested suggestion...
<table>
$cells:{ row | <tr>$row:{ cell | <td>$cell$</td>}$</tr>}$
</table>
(i.e. nested iteration)
or to encompass the table call inside,
$cells:{ row | <tr>$row:{ cell |
<td>$cell$</td>}$</tr>}:{<table>$it$</table>}$
Regards,
Sterl.
On Thu, Sep 18, 2008 at 8:16 AM, Thomas Hartman <
thomashartman1 at googlemail.com> wrote:
> I am trying to use HStringTemplate for generating html tables, for use
> in http://happstutorial.com:5001
>
> The best I could do is below. Seems awfully kludgy.
>
> Can someone suggest a better way, which keeps me inside the
> StringTemplate way of doing things? (Eg, no suggestions to use HTML.*
> libraries, which are nice for some things but are a higher barrier to
> entry than just jumping in and writing html.)
>
> Some kind of map structure... for each... ?
>
> Thanks for any help!
>
> thomas.
>
> {-# LANGUAGE NoMonomorphismRestriction #-}
> import Text.StringTemplate
> import Control.Applicative
> import qualified Text.PrettyPrint as PP
>
> main = putStrLn . PP.render . toPPDoc $ tableFromCells cells
> cells = [["mee","mah","moh"],["fee","fah","foh"]]
>
> -- This does generate an html table, but seems horribly obfuscated.
> -- is there machinery for doing things like html table generation
> -- in some better way than this hack where </end><start>
> -- tags are used as a separator?
> -- I would imagine something like
> -- newSTMP "$cells:{<td>$it$</td>}:{<tr>$it</tr>}:{<table>$it</table>}"
> -- which works a bit like a list comprehension
> tableFromCells cells = setAttribute "cells" cells . optInsertTmpl
> [("separator","</td><td>")]
> $ newSTMP "$cells:\
> \{<tr><td>$it$</td></tr>}:\
> \{<table>$it$</table>}$"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080918/171a729a/attachment.htm
More information about the Haskell-Cafe
mailing list