I agree that this would probably be a good addition. Looks like mapValues should actually be:
mapBind :: (Monad m) => (a -> [(Text, Template)]) -> [a] -> TemplateMonad m () ...keeping these definitions in mind: type Template = [Node] type Splice m = TemplateMonad m Template The substantive difference between this and yours is returning () because this function really just modifies the template state. However, I was wondering if the first parameter should be (a -> [(Text, Splice m)]). (Returning TemplateMonad computations instead of pure templates.) This fits more naturally with the the existing bindSplices. bindSplices :: Monad m => [(Text, Splice m)] -> TemplateState m -> TemplateState m And maybe we should call it mapBind instead of mapValues. Thoughts? If this seems reasonable I'll go ahead and commit it. On Wed, Feb 23, 2011 at 7:31 AM, Gregory Collins <[email protected]> wrote: > 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
