Safe Haskell | None |
---|---|
Language | Haskell98 |
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"
- newtype SplicesM s a = SplicesM {}
- type Splices s = SplicesM s ()
- (##) :: Text -> s -> Splices s
- (#!) :: Text -> s -> Splices s
- (#?) :: Text -> s -> Splices s
- noSplices :: Splices s
- runSplices :: SplicesM s a -> Map Text s
- splicesToList :: SplicesM s a -> [(Text, s)]
- add :: Map Text s -> Splices s
- mapS :: (a -> b) -> Splices a -> Splices b
- applyS :: a -> Splices (a -> b) -> Splices b
- insertS :: Text -> s -> Splices s -> Splices s
- insertWithS :: (s -> s -> s) -> Text -> s -> SplicesM s a2 -> SplicesM s ()
- unionWithS :: (s -> s -> s) -> SplicesM s a1 -> SplicesM s a2 -> SplicesM s ()
- ($$) :: Splices (a -> b) -> a -> Splices b
- mapNames :: (Text -> Text) -> Splices a -> Splices a
- prefixSplices :: Text -> Text -> Splices a -> Splices a
- namespaceSplices :: Text -> Splices a -> Splices a
Documentation
newtype SplicesM s a
A monad providing convenient syntax for defining splices.
(##) :: 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.
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.
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.
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.