on master help sign in
Fix partials and add a test
fdb298dJasper Van der Jeugt
src/Hakyll/Web/Template/Internal.hs+2−2
@@ -138,8 +138,8 @@ applyTemplate' tes context x = go tes
138 return $ intercalate sep bs
138 return $ intercalate sep bs
139
139
140 applyElem (Partial e) = do
140 applyElem (Partial e) = do
141− p <- applyExpr e >>= getString e
141+ p <- applyExpr e >>= getString e
142− tpl' <- loadBody (fromFilePath p)
142+ Template tpl' <- loadBody (fromFilePath p)
143 applyTemplate' tpl' context x
143 applyTemplate' tpl' context x
144
144
145 ---------------------------------------------------------------------------
145 ---------------------------------------------------------------------------
tests/Hakyll/Core/Runtime/Tests.hs+13
@@ -41,6 +41,15 @@ case01 = do
41 >>= saveSnapshot "raw"
41 >>= saveSnapshot "raw"
42 >>= renderPandoc
42 >>= renderPandoc
43
43
44+ match (fromList ["partial.html", "partial-helper.html"]) $
45+ compile templateCompiler
46+ create ["partial.html.out"] $ do
47+ route idRoute
48+ compile $ do
49+ example <- loadSnapshotBody "example.md" "raw"
50+ makeItem example
51+ >>= loadAndApplyTemplate "partial.html" defaultContext
52+
44 create ["bodies.txt"] $ do
53 create ["bodies.txt"] $ do
45 route idRoute
54 route idRoute
46 compile $ do
55 compile $ do
@@ -60,6 +69,10 @@ case01 = do
60 bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
69 bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
61 head (lines bodies) @?= "This is an example."
70 head (lines bodies) @?= "This is an example."
62
71
72+ partial <- readFile $ providerDirectory testConfiguration </> "partial.html.out"
73+ partial' <- readFile $ destinationDirectory testConfiguration </> "partial.html.out"
74+ partial @?= partial'
75+
63 cleanTestEnv
76 cleanTestEnv
64
77
65
78
tests/data/partial-helper.htmlnew file+3
@@ -0,0 +1,3 @@
1+<p>This is an included partial.</p>
2+
3+$body$
tests/data/partial.htmlnew file+3
@@ -0,0 +1,3 @@
1+<p>This is a file that includes a partial.</p>
2+
3+$partial("partial-helper.html")$
tests/data/partial.html.outnew file+7
@@ -0,0 +1,7 @@
1+<p>This is a file that includes a partial.</p>
2+
3+<p>This is an included partial.</p>
4+
5+This is an example.
6+
7+