on master help sign in
Partial trimming
430a0a8samgd
src/Hakyll/Web/Template/Internal.hs+11−5
@@ -142,7 +142,7 @@ template = mconcat <$> P.many (P.choice [ lift chunk
142 , lift escaped
142 , lift escaped
143 , conditional
143 , conditional
144 , for
144 , for
145− , lift partial
145+ , partial
146 , lift expr
146 , lift expr
147 ])
147 ])
148 where lift = fmap (Template . (:[]))
148 where lift = fmap (Template . (:[]))
@@ -246,12 +246,18 @@ for = P.try $ do
246
246
247
247
248--------------------------------------------------------------------------------
248--------------------------------------------------------------------------------
249−partial :: P.Parser TemplateElement
249+partial :: P.Parser Template
250partial = P.try $ do
250partial = P.try $ do
251+ trimLPartial <- trimOpen
251− void $ P.string "$partial("
252+ void $ P.string "partial("
252 e <- expr'
253 e <- expr'
253− void $ P.string ")$"
254+ void $ P.char ')'
255+ trimRPartial <- trimClose
256+
257+ pure $ Template $ mconcat [ [TrimL | trimLPartial]
254− return $ Partial e
258+ , [Partial e]
259+ , [TrimR | trimRPartial]
260+ ]
255
261
256
262
257--------------------------------------------------------------------------------
263--------------------------------------------------------------------------------
tests/Hakyll/Web/Template/Tests.hs+7
@@ -68,6 +68,13 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
68 , TrimR
68 , TrimR
69 ]
69 ]
70 @=? readTemplate "$-for(authors)-$\n body \n$-endfor-$"
70 @=? readTemplate "$-for(authors)-$\n body \n$-endfor-$"
71+ -- 'Partial' trim check.
72+ , Template
73+ [ TrimL
74+ , Partial (StringLiteral "path")
75+ , TrimR
76+ ]
77+ @=? readTemplate "$-partial(\"path\")-$"
71 ]
78 ]
72 ]
79 ]
73
80