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

Safe HaskellNone
LanguageHaskell98

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

A monad providing convenient syntax for defining splices.

Constructors

SplicesM 

Fields

unSplices :: State (Map Text s) a
 

Instances

Monad (SplicesM s) 
Functor (SplicesM s) 
Applicative (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 ()

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

(##) :: Text -> s -> Splices s infixr 0

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

(#!) :: Text -> s -> Splices s infixr 0

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 s infixr 0

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

noSplices :: Splices s

A Splices with nothing in it.

runSplices :: SplicesM s a -> Map Text s

Runs the SplicesM monad, generating a map of splices.

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

Constructs an alist representation.

add :: Map Text s -> Splices s

Internal helper function for adding a map.

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

Maps a function over all the splices.

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

Applies an argument to a splice function.

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

Inserts a splice into the Splices.

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

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

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

Union of Splices with a combining function.

($$) :: Splices (a -> b) -> a -> Splices b infixr 0

Infix operator for flip applyS

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

Maps a function over all the splice names.

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

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 a

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