lymar/hastache — pull request #20 by basvandijk (2013-01-24 14:41:42+00:00)
Title: Effectful mucontext

In my program I would like throw exceptions when my template references undefined variables. This patch makes MuContext and effectful function which allows a user to throw an exception for example:

```haskell
import Text.Hastache
import Text.Hastache.Context
import qualified Data.ByteString.Lazy.Char8 as LZ
import System.IO
import Control.Monad.Error

main = do
r <- runErrorT $ hastacheStr defaultConfig (encodeStr template)
(mkStrContext context)
case r of
Left err -> hPutStrLn stderr err
Right res -> LZ.putStrLn res
where
template = "Hello, {{name}}!\n\nYou have {{unread}} unread messages."
-- context "name" = return $ MuVariable "Haskell"
context "unread" = return $ MuVariable (100 :: Int)
context var = throwError $ "Var: " ++ var ++ " not found!"
```

prints:

```
Var: name not found!
```