
On Wed, Nov 19, 2014 at 03:45:37PM +0100, Wojtek NarczyĆski wrote:
On 19.11.2014 13:17, Tobias Dammers wrote:
That's pretty much what my tamper library (http://hackage.haskell.org/package/tamper) is supposed to be. It's pretty rough around the edges still, and nowhere near as complete as Blaze itself, but it works well enough for basic HTML templating, and unlike Blaze, it is implemented as a monad transformer, which means you can integrate it with whatever monad stack you like. I couldn't find an existing solution to this myself, which is why I rolled my own. Tobias,
I'm puzzled how your library can ensure that, for example <head> has only one <title>, how / where are such rules enforced? Do you have a sample or testcase?
Ah, sorry for getting your hopes up. No, it doesn't ensure valid parent/child combinations or anything, it just does what basic Blaze-HTML does, but generalized to a monad transformer. I considered writing something that could do this, but figured that 1) it would be pretty tricky to get right, and 2) it would be quite restricting, for little gain. The kind of incorrectness this would prevent isn't that common, and when it does happen, it rarely causes severe breakage, meanwhile locking things down would make it harder to adapt your code to the moving target that is HTML. So I dropped the idea. One thing I might want at some point though is checking for valid attributes, somehow. Not sure how to go about that yet though, not without going completely crazy with types, anyway.
On the practical side, wouldn't you prefer to write, for example?
{-#LANGUAGE Rank2Types #-}
type ElementType = (Monad m, Ord t, IsString t) => TamperT t m () -> TamperT t m ()
a, abbr, address, area, article, aside, audio :: ElementType a = tag "a" abbr = tag "abbr" address = tag "address" area = tagS "area" article = tag "article" aside = tag "aside" audio = tag "audio"
Good point; patches welcome in case I forget doing it myself ;)