On Tue, Feb 22, 2011 at 3:52 PM, MightyByte <[email protected]> wrote:
> The short answer is no. Templates are just text parsed into and
> XML/HTML document. In this domain there are no types. Haskell types
> only exist in source code processed by GHC. Templates are data files
> read at runtime.
>
> It is possible to create looping abstractions in Heist, but that
> requires the question to be formulated differently. This is a much
> longer answer that would probably be better as a blog post or
> documentation page. I'll see if I can work on that.
Hi Doug,
We need some combinators on the Haskell side to make writing code like
this easier. Possible examples:
mapValues :: Monad m => (a -> [(Text, [Node])]) -> [a] -> Splice m
and a specialization
mapContent :: Monad m => [[Node]] -> Splice m
mapContent = mapValues (\x -> [("content", x)])
What mapValues would do is: for each element in the list, it would
produce a set of (tag name, dom forest) bindings which would be
applied to the local TemplateState, and then the splice tag's child
nodes would get run in the context of the local environment. Example:
linkList :: [(Text,Text)] -> Splice m
linkList = mapValues (\(desc, href) -> [("linkDescription",
[TextNode desc]), ("linkHref", [TextNode href])])
Binding "<fooList>" to one of these would let you write:
<fooList><li><a href="$(linkHref)"><linkDescription/></a></li></fooList>
G
--
Gregory Collins <[email protected]>
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap