Fix partials and add a test

Fixes #460
This commit is contained in:
Jasper Van der Jeugt 2016-08-04 14:13:24 +02:00
parent 82ba9542e7
commit fdb298d6a2
5 changed files with 28 additions and 2 deletions

View file

@ -138,8 +138,8 @@ applyTemplate' tes context x = go tes
return $ intercalate sep bs return $ intercalate sep bs
applyElem (Partial e) = do applyElem (Partial e) = do
p <- applyExpr e >>= getString e p <- applyExpr e >>= getString e
tpl' <- loadBody (fromFilePath p) Template tpl' <- loadBody (fromFilePath p)
applyTemplate' tpl' context x applyTemplate' tpl' context x
--------------------------------------------------------------------------- ---------------------------------------------------------------------------

View file

@ -41,6 +41,15 @@ case01 = do
>>= saveSnapshot "raw" >>= saveSnapshot "raw"
>>= renderPandoc >>= renderPandoc
match (fromList ["partial.html", "partial-helper.html"]) $
compile templateCompiler
create ["partial.html.out"] $ do
route idRoute
compile $ do
example <- loadSnapshotBody "example.md" "raw"
makeItem example
>>= loadAndApplyTemplate "partial.html" defaultContext
create ["bodies.txt"] $ do create ["bodies.txt"] $ do
route idRoute route idRoute
compile $ do compile $ do
@ -60,6 +69,10 @@ case01 = do
bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt" bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
head (lines bodies) @?= "This is an example." head (lines bodies) @?= "This is an example."
partial <- readFile $ providerDirectory testConfiguration </> "partial.html.out"
partial' <- readFile $ destinationDirectory testConfiguration </> "partial.html.out"
partial @?= partial'
cleanTestEnv cleanTestEnv

View file

@ -0,0 +1,3 @@
<p>This is an included partial.</p>
$body$

3
tests/data/partial.html Normal file
View file

@ -0,0 +1,3 @@
<p>This is a file that includes a partial.</p>
$partial("partial-helper.html")$

View file

@ -0,0 +1,7 @@
<p>This is a file that includes a partial.</p>
<p>This is an included partial.</p>
This is an example.