hsx-jmacro-7.0.0: hsx+jmacro support

Safe HaskellSafe-Infered

HSX.JMacro

Description

This module provides support for embedding javascript generated by jmacro into HSX.

It provides the following instances:

 instance (XMLGenerator m, IntegerSupply m) => EmbedAsChild m JStat
 instance (IntegerSupply m, IsName n, EmbedAsAttr m (Attr Name String)) => EmbedAsAttr m (Attr n JStat)

In order to ensure that each embedded JStat block has unique variable names, the monad must supply a source of unique names. This is done by adding an instance of IntegerSupply for the monad being used with XMLGenerator.

For example, an IntegerSupply for ServerPartT:

 instance IntegerSupply (ServerPartT (StateT Integer IO)) where
     nextInteger = nextInteger'

This variation avoids the use of an extra monad transformer:

 instance IntegerSupply (ServerPartT IO) where
     nextInteger = fmap (fromIntegral . (`mod` 1024) . hashUnique) (liftIO newUnique)

Synopsis

Documentation

nextInteger' :: MonadState Integer m => m IntegerSource

This help function allows you to easily create an IntegerSupply instance for monads that have a MonadState Integer instance.

For example:

 instance IntegerSupply (ServerPartT (StateT Integer IO)) where
     nextInteger = nextInteger'