This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "heist".
The branch, master has been updated
via adeb763231793c424ba2d6e5493ed2e74e879e20 (commit)
from 07363490c4cfa752103f5e2f56d4cc8e139b9b4f (commit)
Summary of changes:
heist.cabal | 2 +-
src/Text/Templating/Heist.hs | 3 +++
src/Text/Templating/Heist/Internal.hs | 20 +++++++++++++++++++-
src/Text/Templating/Heist/Types.hs | 33 ++++++++++++++++++++++-----------
4 files changed, 45 insertions(+), 13 deletions(-)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit adeb763231793c424ba2d6e5493ed2e74e879e20
Author: Mighty Byte <[email protected]>
Date: Mon Mar 7 14:15:50 2011 -0500
Added restoreTS and initial versions of mapBind and mapValues.
diff --git a/heist.cabal b/heist.cabal
index 9c52e7a..7bffeee 100644
--- a/heist.cabal
+++ b/heist.cabal
@@ -1,5 +1,5 @@
name: heist
-version: 0.5.0.2
+version: 0.5.1.0
synopsis: An xhtml templating system
description: An xhtml templating system
license: BSD3
diff --git a/src/Text/Templating/Heist.hs b/src/Text/Templating/Heist.hs
index 677f580..4ab6088 100644
--- a/src/Text/Templating/Heist.hs
+++ b/src/Text/Templating/Heist.hs
@@ -104,6 +104,7 @@ module Text.Templating.Heist
, putTS
, modifyTS
, restoreTS
+ , localTS
-- * Functions for running splices and templates
, evalTemplate
@@ -112,6 +113,8 @@ module Text.Templating.Heist
, renderWithArgs
, bindStrings
, bindString
+ , mapBind
+ , mapValues
-- * Misc functions
, getDoc
diff --git a/src/Text/Templating/Heist/Internal.hs
b/src/Text/Templating/Heist/Internal.hs
index b563fce..af95443 100644
--- a/src/Text/Templating/Heist/Internal.hs
+++ b/src/Text/Templating/Heist/Internal.hs
@@ -7,6 +7,7 @@ module Text.Templating.Heist.Internal where
------------------------------------------------------------------------------
import Blaze.ByteString.Builder
import Control.Applicative
+import Control.Arrow
import Control.Exception (SomeException)
import Control.Monad
import Control.Monad.CatchIO
@@ -93,6 +94,23 @@ bindSplices ss ts = foldl' (flip id) ts acts
------------------------------------------------------------------------------
+-- | Convenient abstraction for applying multiple splice generating functions
+-- before running the contents of the splice's child node. This allows a
+-- splice to be passed in the view that it should use to render the dynamic
+-- data it is responsible for.
+mapBind :: (Monad m) => (a -> [(Text, Splice m)]) -> [a] -> Splice m
+mapBind f vs = localTS (bindSplices (concat $ map f vs))
+ (runNodeList =<< liftM X.childNodes getParamNode)
+
+
+------------------------------------------------------------------------------
+-- | Specialization of mapBind that takes a template generating function
+-- instead of a splice generating function.
+mapValues :: (Monad m) => (a -> [(Text, Template)]) -> [a] -> Splice m
+mapValues f = mapBind (map (second return) . f)
+
+
+------------------------------------------------------------------------------
-- | Convenience function for looking up a splice.
lookupSplice :: Monad m =>
Text
@@ -303,7 +321,7 @@ attParser = AP.many1 (identParser <|> litParser)
------------------------------------------------------------------------------
--- | Get's the attribute value. If the splice's result list contains non-text
+-- | Gets the attribute value. If the splice's result list contains non-text
-- nodes, this will translate them into text nodes with nodeText and
-- concatenate them together.
--
diff --git a/src/Text/Templating/Heist/Types.hs
b/src/Text/Templating/Heist/Types.hs
index dfb5e4c..856019e 100644
--- a/src/Text/Templating/Heist/Types.hs
+++ b/src/Text/Templating/Heist/Types.hs
@@ -341,15 +341,26 @@ modifyTS f = TemplateMonad $ \_ s -> return ((), f s)
------------------------------------------------------------------------------
--- | Restores the components of TemplateState that can get modified in
--- template calls. You should use this function instead of @putTS@ to restore
--- an old state. Thas was needed because doctypes needs to be in a "global
--- scope" as opposed to the template call "local scope" of state items such
--- as recursionDepth, curContext, and spliceMap.
+-- | Restores the TemplateState. This function is almost like putTS except it
+-- preserves the current doctypes. You should use this function instead of
+-- @putTS@ to restore an old state. This was needed because doctypes needs to
+-- be in a "global scope" as opposed to the template call "local scope" of
+-- state items such as recursionDepth, curContext, and spliceMap.
restoreTS :: Monad m => TemplateState m -> TemplateMonad m ()
-restoreTS ts1 =
- modifyTS (\ts2 -> ts2
- { _recursionDepth = _recursionDepth ts1
- , _curContext = _curContext ts1
- , _spliceMap = _spliceMap ts1
- })
+restoreTS old = modifyTS (\cur -> old { _doctypes = _doctypes cur })
+
+
+------------------------------------------------------------------------------
+-- | Abstracts the common pattern of running a TemplateMonad computation with
+-- a modified template state.
+localTS :: Monad m
+ => (TemplateState m -> TemplateState m)
+ -> TemplateMonad m a
+ -> TemplateMonad m a
+localTS f k = do
+ ts <- getTS
+ putTS $ f ts
+ res <- k
+ restoreTS ts
+ return res
+
-----------------------------------------------------------------------
hooks/post-receive
--
heist
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap