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 1ad9656b474e20b2d37d8408db31b47249234bb0 (commit)
from e8284463bf93170bec02fb139bc222f853a944c0 (commit)
Summary of changes:
src/Text/Templating/Heist/Internal.hs | 25 ++++++++------
test/suite/Text/Templating/Heist/Tests.hs | 52 +++++++++++++++++++++++++----
test/templates/attrs.tpl | 6 +++
test/templates/ioc.tpl | 5 ++-
test/templates/noroot.tpl | 2 +
5 files changed, 71 insertions(+), 19 deletions(-)
create mode 100644 test/templates/attrs.tpl
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 1ad9656b474e20b2d37d8408db31b47249234bb0
Author: Mighty Byte <[email protected]>
Date: Mon May 31 05:23:34 2010 -0400
Allow nested template attribute substitution.
Increased test coverage.
diff --git a/src/Text/Templating/Heist/Internal.hs
b/src/Text/Templating/Heist/Internal.hs
index a32cc54..7e809d2 100644
--- a/src/Text/Templating/Heist/Internal.hs
+++ b/src/Text/Templating/Heist/Internal.hs
@@ -388,21 +388,24 @@ parseAtt bs
| otherwise = let (pre,rest) = B.span (/='{') bs in do
suffix <- if B.null rest
then return B.empty
- else parseVar "" (B.tail rest)
+ else do (a,b) <- parseVar "" (B.tail rest)
+ c <- parseAtt b
+ return $ B.append a c
return $ B.append pre suffix
-
+
+------------------------------------------------------------------------------
+parseVar :: Monad m => ByteString -> ByteString
+ -> TemplateMonad m (ByteString, ByteString)
parseVar pre bs
- | B.null bs = return B.empty
+ | B.null bs = return (B.empty, B.empty)
| otherwise = let (name,rest) = B.span (\c -> c/='{' && c/='}') bs in do
- suffix <- if B.null rest
- then return B.empty
+ if B.null rest
+ then return (B.empty, 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
+ '{' -> do (a,b) <- parseVar "" (B.tail rest)
+ parseVar (B.concat [pre, name, a]) b
+ _ -> do s <- getAttributeSplice $ B.append pre name
+ return (s, B.tail rest)
getAttributeSplice :: Monad m => ByteString -> TemplateMonad m ByteString
getAttributeSplice name = do
diff --git a/test/suite/Text/Templating/Heist/Tests.hs
b/test/suite/Text/Templating/Heist/Tests.hs
index 9554af1..758a957 100644
--- a/test/suite/Text/Templating/Heist/Tests.hs
+++ b/test/suite/Text/Templating/Heist/Tests.hs
@@ -24,6 +24,7 @@ import System.IO.Unsafe
import Text.Templating.Heist
import Text.Templating.Heist.Internal
+import Text.Templating.Heist.Splices.Apply
import Text.XML.Expat.Cursor
import Text.XML.Expat.Format
import qualified Text.XML.Expat.Tree as X
@@ -38,8 +39,17 @@ tests = [ testProperty "simpleBindTest" $ monadicIO $
forAllM arbitrary prop_sim
, testCase "fsLoadTest" fsLoadTest
, testCase "renderNoNameTest" renderNoNameTest
, testCase "doctypeTest" doctypeTest
+ , testCase "attributeSubstitution" attrSubst
+ , testCase "applyTest" applyTest
]
+applyTest :: H.Assertion
+applyTest = do
+ let es = emptyTemplateState :: TemplateState IO
+ res <- runTemplateMonad es
+ (X.Element "apply" [("template", "nonexistant")] []) applyImpl
+ H.assertEqual "apply nothing" res []
+
monoidTest :: IO ()
monoidTest = do
H.assertBool "left monoid identity" $ mempty `mappend` es == es
@@ -65,7 +75,7 @@ loadTest = do
ets <- loadT "templates"
either (error "Error loading templates")
(\ts -> do let tm = _templateMap ts
- H.assertBool "loadTest size" $ Map.size tm == 14
+ H.assertBool "loadTest size" $ Map.size tm == 15
) ets
renderNoNameTest :: H.Assertion
@@ -96,12 +106,40 @@ fsLoadTest = do
doctypeTest :: H.Assertion
doctypeTest = do
- ets <- loadT "templates"
- let ts = either (error "Error loading templates") id ets
- index <- renderTemplate ts "index"
- H.assertBool "doctype test index" $ hasDoctype $ fromJust index
- ioc <- renderTemplate ts "ioc"
- H.assertBool "doctype test ioc" $ hasDoctype $ fromJust ioc
+ ets <- loadT "templates"
+ let ts = either (error "Error loading templates") id ets
+ index <- renderTemplate ts "index"
+ H.assertBool "doctype test index" $ hasDoctype $ fromJust index
+ ioc <- renderTemplate ts "ioc"
+ H.assertBool "doctype test ioc" $ hasDoctype $ fromJust ioc
+
+attrSubst :: H.Assertion
+attrSubst = do
+ ets <- loadT "templates"
+ let ts = either (error "Error loading templates") id ets
+ check ts ("a", "42") "pre_meaning_of_everything_post"
+ check ts ("a", "64") "pre_power_of_two_post"
+ check ts ("b", "42") "pre_MEANING_OF_EVERYTHING_post"
+ check ts ("b", "64") "pre_POWER_OF_TWO_post"
+ emptyPV ts
+ single ts
+ partial ts
+ where
+ setTs (char, ind) = bindSplice "char" (return [X.Text char]) .
+ bindSplice "ind" (return [X.Text ind])
+ check ts arg str = do
+ res <- renderTemplate (setTs arg ts) "attrs"
+ H.assertBool ("attr subst "++(show arg)) $
+ not $ B.null $ snd $ B.breakSubstring str $ fromJust res
+ emptyPV ts = do
+ res <- runTemplateMonad ts (X.Text "") $ parseVar "" ""
+ H.assertEqual "emptyParseVar" res ("", "")
+ single ts = do
+ res <- runTemplateMonad ts (X.Text "") $ parseVar "" "{abc}"
+ H.assertEqual "singleParseVar" res ("", "")
+ partial ts = do
+ res <- runTemplateMonad ts (X.Text "") $ parseVar "" "{abc"
+ H.assertEqual "partialParseVar" res ("", "")
-- dotdotTest :: H.Assertion
-- dotdotTest = do
diff --git a/test/templates/attrs.tpl b/test/templates/attrs.tpl
new file mode 100644
index 0000000..3166ccb
--- /dev/null
+++ b/test/templates/attrs.tpl
@@ -0,0 +1,6 @@
+<bind tag="att_a_42">meaning_of_everything</bind>
+<bind tag="att_a_64">power_of_two</bind>
+<bind tag="att_b_42">MEANING_OF_EVERYTHING</bind>
+<bind tag="att_b_64">POWER_OF_TWO</bind>
+<mytag flag="">Empty attribute</mytag>
+<div id="pre_{att_{char}_{ind}}_post"/>
diff --git a/test/templates/ioc.tpl b/test/templates/ioc.tpl
index 40a4ac8..ff06889 100644
--- a/test/templates/ioc.tpl
+++ b/test/templates/ioc.tpl
@@ -1,3 +1,6 @@
-<apply template="page">
+<apply>
+Apply with no parameter.
+</apply>
+<apply template="/page">
Inversion of control content
</apply>
diff --git a/test/templates/noroot.tpl b/test/templates/noroot.tpl
index f8a4386..8f237c7 100644
--- a/test/templates/noroot.tpl
+++ b/test/templates/noroot.tpl
@@ -1 +1,3 @@
+<apply>
noroot
+</apply>
-----------------------------------------------------------------------
hooks/post-receive
--
heist
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap