on master help sign in
Add Trim_ data constructors. Add If test for Trim
commit02dd1cf2360cb2a650cb61c5e6ae2ca573eb5125 authorsamgd <sam@samgd.com> dateFri 22 Jul 2016, 16:39 (10 years ago) parent94cbdc1
2 files changed+25−6
src/Hakyll/Web/Template/Internal.hs+10−6 tests/Hakyll/Web/Template/Tests.hs+15
src/Hakyll/Web/Template/Internal.hs+10−6
@@ -64,6 +64,8 @@ data TemplateElement
6464 | If TemplateExpr Template (Maybe Template) -- expr, then, else
6565 | For TemplateExpr Template (Maybe Template) -- expr, body, separator
6666 | Partial TemplateExpr -- filename
67+ | TrimL
68+ | TrimR
6769 deriving (Show, Eq, Typeable)
6870
6971
@@ -71,10 +73,12 @@ data TemplateElement
7173instance Binary TemplateElement where
7274 put (Chunk string) = putWord8 0 >> put string
7375 put (Expr e) = putWord8 1 >> put e
74− put (Escaped) = putWord8 2
75− put (If e t f ) = putWord8 3 >> put e >> put t >> put f
76+ put Escaped = putWord8 2
77+ put (If e t f) = putWord8 3 >> put e >> put t >> put f
7678 put (For e b s) = putWord8 4 >> put e >> put b >> put s
7779 put (Partial e) = putWord8 5 >> put e
80+ put TrimL = putWord8 6
81+ put TrimR = putWord8 7
7882
7983 get = getWord8 >>= \tag -> case tag of
8084 0 -> Chunk <$> get
@@ -83,8 +87,9 @@ instance Binary TemplateElement where
8387 3 -> If <$> get <*> get <*> get
8488 4 -> For <$> get <*> get <*> get
8589 5 -> Partial <$> get
86− _ -> error $
87− "Hakyll.Web.Template.Internal: Error reading cached template"
90+ 6 -> pure TrimL
91+ 7 -> pure TrimR
92+ _ -> error "Hakyll.Web.Template.Internal: Error reading cached template"
8893
8994
9095--------------------------------------------------------------------------------
@@ -114,8 +119,7 @@ instance Binary TemplateExpr where
114119 0 -> Ident <$> get
115120 1 -> Call <$> get <*> get
116121 2 -> StringLiteral <$> get
117− _ -> error $
118− "Hakyll.Web.Tamplte.Internal: Error reading cached template"
122+ _ -> error "Hakyll.Web.Template.Internal: Error reading cached template"
119123
120124
121125--------------------------------------------------------------------------------
tests/Hakyll/Web/Template/Tests.hs+15
@@ -39,6 +39,21 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
3939 (Template [Chunk "foo"])
4040 Nothing]
4141 @=? readTemplate "$if(a(\"bar\"))$foo$endif$"
42+ -- 'If' 'Trim_' test.
43+ , Template
44+ [ TrimL
45+ , If (Ident (TemplateKey "body"))
46+ (Template [ TrimR
47+ , Expr (Ident (TemplateKey "body"))
48+ ])
49+ (Just (Template [ TrimL
50+ , TrimR
51+ , Expr (Ident (TemplateKey "body"))
52+ ]))
53+ , TrimL
54+ , TrimR
55+ ]
56+ @=? readTemplate "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
4257 ]
4358 ]
4459