Partial trimming

This commit is contained in:
samgd 2016-07-23 12:52:55 +02:00
parent 6e14d33a10
commit 430a0a8849
No known key found for this signature in database
GPG key ID: E69F2FF86041ADB3
2 changed files with 18 additions and 5 deletions

View file

@ -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]
]
--------------------------------------------------------------------------------

View file

@ -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\")-$"
]
]