heist-0.13.0.2: An Haskell template system supporting both HTML5 and XML.

Safe HaskellNone

Heist.SpliceAPI

Description

An API implementing a convenient syntax for defining and manipulating splices. This module was born from the observation that a list of tuples is semantically ambiguous about how duplicate keys should be handled. Additionally, the syntax is inherently rather cumbersome and difficult to work with. This API takes advantage of do notation to provide a very light syntax for defining splices while at the same time eliminating the semantic ambiguity of alists.

Here's how you can define splices:

 mySplices :: Splices Text
 mySplices = do
   "firstName" ## "John"
   "lastName"  ## "Smith"

Synopsis

Documentation

newtype SplicesM s a Source

A monad providing convenient syntax for defining splices.

Constructors

SplicesM 

Fields

unSplices :: State (Map Text s) a
 

Instances

Monad (SplicesM s) 
Monoid (Splices s)

Monoid instance does a union of the two maps with the second map overwriting any duplicates.

MonadState (Map Text s) (SplicesM s) 

type Splices s = SplicesM s ()Source

Convenient type alias that will probably be used most of the time.

(##) :: Text -> s -> Splices sSource

Forces a splice to be added. If the key already exists, its value is overwritten.

(#!) :: Text -> s -> Splices sSource

Tries to add a splice, but if the key already exists, then it throws an error message. This may be useful if name collisions are bad and you want to crash when they occur.

(#?) :: Text -> s -> Splices sSource

Inserts into the map only if the key does not already exist.

noSplices :: Splices sSource

A Splices with nothing in it.

runSplices :: SplicesM s a -> Map Text sSource

Runs the SplicesM monad, generating a map of splices.

splicesToList :: SplicesM s a -> [(Text, s)]Source

Constructs an alist representation.

add :: Map Text s -> Splices sSource

Internal helper function for adding a map.

mapS :: (a -> b) -> Splices a -> Splices bSource

Maps a function over all the splices.

applyS :: a -> Splices (a -> b) -> Splices bSource

Applies an argument to a splice function.

insertS :: Text -> s -> Splices s -> Splices sSource

Inserts a splice into the Splices.

insertWithS :: (s -> s -> s) -> Text -> s -> SplicesM s a2 -> SplicesM s ()Source

Inserts a splice with a function combining new value and old value.

unionWithS :: (s -> s -> s) -> SplicesM s a1 -> SplicesM s a2 -> SplicesM s ()Source

Union of Splices with a combining function.

($$) :: Splices (a -> b) -> a -> Splices bSource

Infix operator for flip applyS

mapNames :: (Text -> Text) -> Splices a -> Splices aSource

Maps a function over all the splice names.

prefixSplices :: Text -> Text -> Splices a -> Splices aSource

Adds a prefix to the tag names for a list of splices. If the existing tag name is empty, then the new tag name is just the prefix. Otherwise the new tag name is the prefix followed by the separator followed by the existing name.

namespaceSplices :: Text -> Splices a -> Splices aSource

prefixSplices specialized to use a colon as separator in the style of XML namespaces.