on master help sign in
For trimming
6e14d33samgd
src/Hakyll/Web/Template/Internal.hs+18−6
@@ -141,7 +141,7 @@ template :: P.Parser Template
141template = mconcat <$> P.many (P.choice [ lift chunk
141template = mconcat <$> P.many (P.choice [ lift chunk
142 , lift escaped
142 , lift escaped
143 , conditional
143 , conditional
144− , lift for
144+ , for
145 , lift partial
145 , lift partial
146 , lift expr
146 , lift expr
147 ])
147 ])
@@ -222,15 +222,27 @@ conditional = P.try $ do
222
222
223
223
224--------------------------------------------------------------------------------
224--------------------------------------------------------------------------------
225−for :: P.Parser TemplateElement
225+for :: P.Parser Template
226for = P.try $ do
226for = P.try $ do
227+ trimLFor <- trimOpen
227− void $ P.string "$for("
228+ void $ P.string "for("
228 e <- expr'
229 e <- expr'
229− void $ P.string ")$"
230+ void $ P.char ')'
231+ trimRFor <- trimClose
232+
230 body <- template
233 body <- template
231 sep <- P.optionMaybe $ P.try (P.string "$sep$") >> template
234 sep <- P.optionMaybe $ P.try (P.string "$sep$") >> template
235+
236+ trimLEnd <- trimOpen
232− void $ P.string "$endfor$"
237+ void $ P.string "endfor"
238+ trimREnd <- trimClose
239+
240+ pure $ Template $ mconcat [ [TrimL | trimLFor]
241+ , [TrimR | trimRFor]
233− return $ For e body sep
242+ , [For e body sep]
243+ , [TrimL | trimLEnd]
244+ , [TrimR | trimREnd]
245+ ]
234
246
235
247
236--------------------------------------------------------------------------------
248--------------------------------------------------------------------------------
tests/Hakyll/Web/Template/Tests.hs+13−3
@@ -6,7 +6,6 @@ module Hakyll.Web.Template.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Data.Monoid (mconcat)
10import Test.Framework (Test, testGroup)
9import Test.Framework (Test, testGroup)
11import Test.Framework.Providers.HUnit (testCase)
10import Test.Framework.Providers.HUnit (testCase)
12import Test.HUnit (Assertion, (@=?), (@?=))
11import Test.HUnit (Assertion, (@=?), (@?=))
@@ -33,12 +32,12 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
33
32
34 , fromAssertions "readTemplate"
33 , fromAssertions "readTemplate"
35 [ Template [Chunk "Hello ", Expr (Call "guest" [])]
34 [ Template [Chunk "Hello ", Expr (Call "guest" [])]
36− @=? readTemplate "Hello $guest()$"
35+ @=? readTemplate "Hello $guest()$"
37 , Template
36 , Template
38 [If (Call "a" [StringLiteral "bar"])
37 [If (Call "a" [StringLiteral "bar"])
39 (Template [Chunk "foo"])
38 (Template [Chunk "foo"])
40 Nothing]
39 Nothing]
41− @=? readTemplate "$if(a(\"bar\"))$foo$endif$"
40+ @=? readTemplate "$if(a(\"bar\"))$foo$endif$"
42 -- 'If' trim check.
41 -- 'If' trim check.
43 , Template
42 , Template
44 [ TrimL
43 [ TrimL
@@ -58,6 +57,17 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
58 , TrimR
57 , TrimR
59 ]
58 ]
60 @=? readTemplate "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
59 @=? readTemplate "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
60+ -- 'For' trim check.
61+ , Template
62+ [ TrimL
63+ , TrimR
64+ , For (Ident (TemplateKey "authors"))
65+ (Template [Chunk "\n body \n"])
66+ Nothing
67+ , TrimL
68+ , TrimR
69+ ]
70+ @=? readTemplate "$-for(authors)-$\n body \n$-endfor-$"
61 ]
71 ]
62 ]
72 ]
63
73