I've been working on some quickly-growing Haskell based web applications, and am finding myself shot in the foot with this issue. Suppose I have some template that I've defined early in my code:
{-# LANGUAGE OverloadedStrings #-}
import Text.Blaze.Html5
import Text.Blaze.Html5.Attributes
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
foo = H.div ! class_ "foo"
and later, I decide to use foo
, but with a slight non-destructive amendment:
bar = foo ! class_ "bar" -- this should add bar to the classes available, imo
but alas, when I render the html, here is the result I get:
import Text.Blaze.Html.Renderer.String
λ: renderHtml $ bar "baz"
↪ "<div class=\"foo\" class=\"bar\"></div>"
This is a monad, after all! Is there any way we could integrate this kind of logic into blaze-html? Or is that beyond the scope of the templating framework? Are there any methods of selection (like jQuery), such that I could do something along the lines of...
bar' = do
classes <- classesOf foo
H.div ! class_ (classes ++ " bar")
Has anyone found a way around this? Are there any type-assisted Html tools for Haskell out there? This really has me scratching my head, and coming up with horrible ideas...