summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamgd <sam@samgd.com>2016-07-23 12:52:55 +0200
committersamgd <sam@samgd.com>2016-07-23 12:52:55 +0200
commit430a0a8849191edfa7b53dcf76a0fb72f12ebde7 (patch)
treebea6202e12b0d2e02fbbe009aa3563c6bd9e083d
parent6e14d33a101e4ea9559d13d7a562da7ebc72acf2 (diff)
downloadhakyll-430a0a8849191edfa7b53dcf76a0fb72f12ebde7.tar.gz
Partial trimming
-rw-r--r--src/Hakyll/Web/Template/Internal.hs16
-rw-r--r--tests/Hakyll/Web/Template/Tests.hs7
2 files changed, 18 insertions, 5 deletions
diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs
index 983bd16..6ccad74 100644
--- a/src/Hakyll/Web/Template/Internal.hs
+++ b/src/Hakyll/Web/Template/Internal.hs
@@ -142,7 +142,7 @@ template = mconcat <$> P.many (P.choice [ lift chunk
, lift escaped
, conditional
, for
- , lift partial
+ , partial
, lift expr
])
where lift = fmap (Template . (:[]))
@@ -246,12 +246,18 @@ for = P.try $ do
--------------------------------------------------------------------------------
-partial :: P.Parser TemplateElement
+partial :: P.Parser Template
partial = P.try $ do
- void $ P.string "$partial("
+ trimLPartial <- trimOpen
+ void $ P.string "partial("
e <- expr'
- void $ P.string ")$"
- return $ Partial e
+ void $ P.char ')'
+ trimRPartial <- trimClose
+
+ pure $ Template $ mconcat [ [TrimL | trimLPartial]
+ , [Partial e]
+ , [TrimR | trimRPartial]
+ ]
--------------------------------------------------------------------------------
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs
index b6a3a1d..1ace2d4 100644
--- a/tests/Hakyll/Web/Template/Tests.hs
+++ b/tests/Hakyll/Web/Template/Tests.hs
@@ -68,6 +68,13 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
, TrimR
]
@=? readTemplate "$-for(authors)-$\n body \n$-endfor-$"
+ -- 'Partial' trim check.
+ , Template
+ [ TrimL
+ , Partial (StringLiteral "path")
+ , TrimR
+ ]
+ @=? readTemplate "$-partial(\"path\")-$"
]
]