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, 0.2-dev has been updated
via e8284463bf93170bec02fb139bc222f853a944c0 (commit)
from aae6986117305fa685d0d04dd08b21ef5e53cf25 (commit)
Summary of changes:
src/Text/Templating/Heist/Internal.hs | 42 +++++++++++++++++++++++++++++---
test/templates/index.tpl | 3 ++
2 files changed, 41 insertions(+), 4 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 e8284463bf93170bec02fb139bc222f853a944c0
Author: Mighty Byte <[email protected]>
Date: Sun May 30 21:40:39 2010 -0400
Attribute substitution tentatively working. Needs cleanup and testing.
diff --git a/src/Text/Templating/Heist/Internal.hs
b/src/Text/Templating/Heist/Internal.hs
index 2080440..a32cc54 100644
--- a/src/Text/Templating/Heist/Internal.hs
+++ b/src/Text/Templating/Heist/Internal.hs
@@ -369,15 +369,49 @@ getContext = gets _curContext
-- | Performs splice processing on a single node.
runNode :: Monad m => Node -> Splice m
runNode n@(X.Text _) = return [n]
-runNode n@(X.Element nm _ ch) = do
+runNode n@(X.Element nm at ch) = do
s <- liftM (lookupSplice nm) get
maybe runChildren (recurseSplice n) s
-
+
where
runChildren = do
newKids <- runNodeList ch
- return [X.modifyChildren (const newKids) n]
-
+ newAtts <- mapM attSubst at
+ return [X.Element nm newAtts newKids]
+ attSubst (n,v) = do
+ v' <- parseAtt v
+ return (n,v')
+
+
+parseAtt bs
+ | B.null bs = return B.empty
+ | otherwise = let (pre,rest) = B.span (/='{') bs in do
+ suffix <- if B.null rest
+ then return B.empty
+ else parseVar "" (B.tail rest)
+ return $ B.append pre suffix
+
+parseVar pre bs
+ | B.null bs = return B.empty
+ | otherwise = let (name,rest) = B.span (\c -> c/='{' && c/='}') bs in do
+ suffix <- if B.null rest
+ then return B.empty
+ else case B.head rest of
+ '{' -> parseVar (B.append pre name) (B.tail rest)
+ '}' -> do s <- getAttributeSplice $ B.append pre name
+ end <- parseAtt $ B.tail rest
+ return $ B.append s end
+ _ -> return B.empty
+ return $ B.append pre suffix
+
+getAttributeSplice :: Monad m => ByteString -> TemplateMonad m ByteString
+getAttributeSplice name = do
+ s <- liftM (lookupSplice name) get
+ nodes <- maybe (return []) id s
+ return $ check nodes
+ where
+ check ((X.Text t):_) = t
+ check _ = ""
------------------------------------------------------------------------------
-- | Performs splice processing on a list of nodes.
diff --git a/test/templates/index.tpl b/test/templates/index.tpl
index 4319f1c..5a3c909 100644
--- a/test/templates/index.tpl
+++ b/test/templates/index.tpl
@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<bind tag="att">ultralongname</bind>
<html>
+<div id="pre_{att}_post">
/index
+</div>
</html>
-----------------------------------------------------------------------
hooks/post-receive
--
heist
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap