on master help sign in
Partial trimming
commit430a0a8849191edfa7b53dcf76a0fb72f12ebde7 authorsamgd <sam@samgd.com> dateSat 23 Jul 2016, 12:52 (10 years ago) parent6e14d33
2 files changed+18−5
src/Hakyll/Web/Template/Internal.hs+11−5 tests/Hakyll/Web/Template/Tests.hs+7
src/Hakyll/Web/Template/Internal.hs+11−5
@@ -142,7 +142,7 @@ template = mconcat <$> P.many (P.choice [ lift chunk
142142 , lift escaped
143143 , conditional
144144 , for
145− , lift partial
145+ , partial
146146 , lift expr
147147 ])
148148 where lift = fmap (Template . (:[]))
@@ -246,12 +246,18 @@ for = P.try $ do
246246
247247
248248--------------------------------------------------------------------------------
249−partial :: P.Parser TemplateElement
249+partial :: P.Parser Template
250250partial = P.try $ do
251− void $ P.string "$partial("
251+ trimLPartial <- trimOpen
252+ void $ P.string "partial("
252253 e <- expr'
253− void $ P.string ")$"
254− return $ Partial e
254+ void $ P.char ')'
255+ trimRPartial <- trimClose
256+
257+ pure $ Template $ mconcat [ [TrimL | trimLPartial]
258+ , [Partial e]
259+ , [TrimR | trimRPartial]
260+ ]
255261
256262
257263--------------------------------------------------------------------------------
tests/Hakyll/Web/Template/Tests.hs+7
@@ -68,6 +68,13 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
6868 , TrimR
6969 ]
7070 @=? 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\")-$"
7178 ]
7279 ]
7380