Browse files

fixed: showing section according non empty variables

  • Loading branch information...
1 parent 40376cf commit ffe90a79e51e09d16e2e9450f4611ad4fb338aab @lymar lymar committed Feb 3, 2012
Showing with 18 additions and 3 deletions.
  1. +3 −0 Text/Hastache.hs
  2. +15 −3 tests/test.hs
View
3 Text/Hastache.hs
@@ -371,6 +371,9 @@ renderBlock contexts symb inTag afterClose otag ctag conf
mapM_ (\c -> processBlock sectionContent
(c:contexts) otag ctag conf) b
next afterSection
+ Just (MuVariable a) -> if isEmpty a
+ then next afterSection
+ else processAndNext
Just (MuBool True) -> processAndNext
Just (MuLambda func) -> do
func sectionContent ~> toLByteString ~> addResLZ
View
18 tests/test.hs
@@ -68,8 +68,8 @@ variablesTest = do
\ HtmlStringUnEsc2: [ <p>text (\\)</p> ] \n\
\"
--- Inverted sections
-invertedSections = do
+-- Show/hide sections
+showHideSectionsTest = do
res <- hastacheStr defaultConfig (encodeStr template)
(mkStrContext context)
assertEqualStr resCorrectness (decodeStrLBS res) testRes
@@ -91,13 +91,22 @@ invertedSections = do
\{{^emptyInt}}yes {{emptyInt}}{{/emptyInt}}\n\
\{{#emptyDouble}}no {{emptyDouble}}{{/emptyDouble}}\
\{{^emptyDouble}}yes {{emptyDouble}}{{/emptyDouble}}\n\
+ \{{#nonEmptyString}}yes {{nonEmptyString}}{{/nonEmptyString}}\
+ \{{^nonEmptyString}}no{{/nonEmptyString}}\n\
+ \{{#nonEmptyInt}}yes {{nonEmptyInt}}{{/nonEmptyInt}}\
+ \{{^nonEmptyInt}}no{{/nonEmptyInt}}\n\
+ \{{#nonEmptyDouble}}yes {{nonEmptyDouble}}{{/nonEmptyDouble}}\
+ \{{^nonEmptyDouble}}no{{/nonEmptyDouble}}\n\
\"
context "noCtx" = MuNothing
context "emptyList" = MuList []
context "someval" = MuVariable (5 :: Int)
context "emptyString" = MuVariable ""
context "emptyInt" = MuVariable (0 :: Int)
context "emptyDouble" = MuVariable (0 :: Double)
+ context "nonEmptyString" = MuVariable "some"
+ context "nonEmptyInt" = MuVariable (1 :: Int)
+ context "nonEmptyDouble" = MuVariable (1 :: Double)
testRes = "\
\no context : Should render\n\
@@ -108,6 +117,9 @@ invertedSections = do
\yes 5\n\
\yes 0\n\
\yes 0.0\n\
+ \yes some\n\
+ \yes 1\n\
+ \yes 1.0\n\
\"
-- Render list
@@ -402,7 +414,7 @@ nestedGenericContextTest = do
tests = TestList [
TestLabel "Comments test" (TestCase commentsTest)
,TestLabel "Variables test" (TestCase variablesTest)
- ,TestLabel "Inverted sections" (TestCase invertedSections)
+ ,TestLabel "Show/hide sections test" (TestCase showHideSectionsTest)
,TestLabel "List test" (TestCase listSectionTest)
,TestLabel "Bool test" (TestCase boolSectionTest)
,TestLabel "Lambda test" (TestCase lambdaSectionTest)

0 comments on commit ffe90a7

Please sign in to comment.