on master help sign in
CHANGELOG.md+13
since splitsnapshots
unifiedsplit
@@ -4,6 +4,19 @@ title: Releases
4
4
5# Releases
5# Releases
6
6
7+## Hakyll 4.13.0.0 (2019-08-30)
8+
9+- Improved documentation in many places (contribution by Bergi)
10+- Significantly improve error messages when reading and applying templates
11+ (contribution by Bergi)
12+ * `empty` and `fail` for `Compiler` now fail without or with a message,
13+ allowing for much better debug output
14+ * `renderFeed`, `renderRssWithTemplates` and `renderAtomWithTemplates` now
15+ take `Template` rather than `String` arguments
16+- Add option to specify date in directory structure,e.g.
17+ `posts/2019/05/10/tomorrow.md` (contribution by Taeer Bar-Ya)
18+- Bump QuickCheck to 2.13
19+
7## Hakyll 4.12.5.2 (2019-05-09)
20## Hakyll 4.12.5.2 (2019-05-09)
8
21
9- Bump pandoc to 2.7
22- Bump pandoc to 2.7
hakyll.cabal+1−1
@@ -1,5 +1,5 @@
1Name: hakyll
1Name: hakyll
2−Version: 4.12.5.2
2+Version: 4.13.0.0
3
3
4Synopsis: A static website compiler library
4Synopsis: A static website compiler library
5Description:
5Description:
lib/Hakyll/Web/Template/Context.hs+14−1
@@ -21,6 +21,7 @@
21--------------------------------------------------------------------------------
21--------------------------------------------------------------------------------
22{-# LANGUAGE CPP #-}
22{-# LANGUAGE CPP #-}
23{-# LANGUAGE ExistentialQuantification #-}
23{-# LANGUAGE ExistentialQuantification #-}
24+{-# LANGUAGE RankNTypes #-}
24module Hakyll.Web.Template.Context
25module Hakyll.Web.Template.Context
25 ( ContextField (..)
26 ( ContextField (..)
26 , Context (..)
27 , Context (..)
@@ -48,6 +49,7 @@ module Hakyll.Web.Template.Context
48 , teaserField
49 , teaserField
49 , teaserFieldWithSeparator
50 , teaserFieldWithSeparator
50 , missingField
51 , missingField
52+ , bindItem
51 ) where
53 ) where
52
54
53
55
@@ -176,7 +178,11 @@ listField key c xs = listFieldWith key c (const xs)
176
178
177
179
178--------------------------------------------------------------------------------
180--------------------------------------------------------------------------------
181+-- | Produces a new 'Context' which has list field 'key'. All fields from
182+-- 'c' are also accessible from the produced context.
183+-- Be careful when doing @listFieldWith k ca f <> cb@ as any fields in @ca@
184+-- will override fields in @cb@ with the same name.
179−-- | Creates a list field like 'listField', but supplies the current page
185+-- Creates a list field like 'listField', but supplies the current page
180-- to the compiler.
186-- to the compiler.
181listFieldWith
187listFieldWith
182 :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
188 :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
@@ -466,3 +472,10 @@ parseTimeM = TF.parseTimeM
466#else
472#else
467parseTimeM _ = TF.parseTime
473parseTimeM _ = TF.parseTime
468#endif
474#endif
475+
476+--------------------------------------------------------------------------------
477+
478+-- | Binds an 'Item' to a given 'Context', allowing it to be combined with any
479+-- other 'Context' of any type.
480+bindItem :: Context a -> Item a -> forall b. Context b
481+bindItem (Context ctx) ia = Context $ \k args _ -> ctx k args ia
lib/Hakyll/Web/Template/Internal.hs+3−2
@@ -21,7 +21,8 @@ module Hakyll.Web.Template.Internal
21
21
22
22
23--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
24−import Control.Monad.Except (catchError)
24+import Control.Monad (forM)
25+import Control.Monad.Except (MonadError (..), catchError)
25import Data.Binary (Binary)
26import Data.Binary (Binary)
26import Data.List (intercalate)
27import Data.List (intercalate)
27import qualified Data.List.NonEmpty as NonEmpty
28import qualified Data.List.NonEmpty as NonEmpty
@@ -171,7 +172,7 @@ applyTemplate' tes context x = go tes
171 StringField _ -> expected "list" "string" typeMsg
172 StringField _ -> expected "list" "string" typeMsg
172 ListField c xs -> withErrorMessage bodyMsg $ do
173 ListField c xs -> withErrorMessage bodyMsg $ do
173 sep <- maybe (return "") go s
174 sep <- maybe (return "") go s
174− bs <- mapM (applyTemplate' b c) xs
175+ bs <- forM xs $ applyTemplate' b $ c <> bindItem context x
175 return $ intercalate sep bs
176 return $ intercalate sep bs
176 where
177 where
177 headMsg = "In expr '$for(" ++ show e ++ ")$'"
178 headMsg = "In expr '$for(" ++ show e ++ ")$'"
tests/Hakyll/Web/Tags/Tests.hsdeleted−42
@@ -1,42 +0,0 @@
1−--------------------------------------------------------------------------------
2−{-# LANGUAGE OverloadedStrings #-}
3−module Hakyll.Web.Tags.Tests
4− ( tests
5− ) where
6−
7−--------------------------------------------------------------------------------
8−import Test.Tasty (TestTree, testGroup)
9−import Test.Tasty.HUnit (Assertion, testCase, (@?=))
10−
11−--------------------------------------------------------------------------------
12−import Hakyll.Core.Identifier
13−import Hakyll.Core.Provider
14−import Hakyll.Core.Store (Store)
15−import Hakyll.Web.Tags
16−import TestSuite.Util
17−
18−tests :: TestTree
19−tests = testGroup "Hakyll.Web.Tags"
20− [ testCase "testGetCategory" testGetCategory
21− ]
22−
23−testGetCategory :: Assertion
24−testGetCategory = do
25− store <- newTestStore
26− provider <- newTestProvider store
27−
28− noCategory <- testCategoryDone store provider "example.md"
29− noCategory @?= [""]
30−
31− oneCategory1 <- testCategoryDone store provider "posts/2010-08-26-birthday.md"
32− oneCategory1 @?= ["posts"]
33−
34− oneCategory2 <- testCategoryDone store provider "posts/2019/05/10/tomorrow.md"
35− oneCategory2 @?= ["10"]
36−
37− cleanTestEnv
38−
39−--------------------------------------------------------------------------------
40−testCategoryDone :: Store -> Provider -> Identifier -> IO [String]
41−testCategoryDone store provider identifier =
42− testCompilerDone store provider identifier $ getCategory identifier
tests/Hakyll/Web/Template/Context/Tests.hs+28
@@ -13,9 +13,11 @@ import Test.Tasty.HUnit (Assertion, testCase, (@=?))
13--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
14import Hakyll.Core.Compiler
14import Hakyll.Core.Compiler
15import Hakyll.Core.Identifier
15import Hakyll.Core.Identifier
16+import Hakyll.Core.Item
16import Hakyll.Core.Provider
17import Hakyll.Core.Provider
17import Hakyll.Core.Store (Store)
18import Hakyll.Core.Store (Store)
18import Hakyll.Web.Template.Context
19import Hakyll.Web.Template.Context
20+import Hakyll.Web.Template.Internal
19import TestSuite.Util
21import TestSuite.Util
20
22
21
23
@@ -23,6 +25,7 @@ import TestSuite.Util
23tests :: TestTree
25tests :: TestTree
24tests = testGroup "Hakyll.Web.Template.Context.Tests"
26tests = testGroup "Hakyll.Web.Template.Context.Tests"
25 [ testCase "testDateField" testDateField
27 [ testCase "testDateField" testDateField
28+ , testCase "testOuerLoopContextAccess" testOuerLoopContextAccess
26 ]
29 ]
27
30
28
31
@@ -65,3 +68,28 @@ testContextDone store provider identifier key context =
65 _ -> error $
68 _ -> error $
66 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
69 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
67 "expected StringField"
70 "expected StringField"
71+
72+--------------------------------------------------------------------------------
73+
74+testOuerLoopContextAccess :: Assertion
75+testOuerLoopContextAccess = do
76+ store <- newTestStore
77+ provider <- newTestProvider store
78+ test store provider ctx "baz"
79+ test store provider (ctx' <> ctx) "not baz"
80+ test store provider (ctx <> ctx') "baz"
81+
82+ cleanTestEnv
83+ where
84+ tpl = readTemplate "$for(foo)$$for(bar)$$qux$$endfor$$endfor$"
85+ ctx = mconcat [
86+ field "qux" $ const $ return "baz"
87+ , listField "foo" (listField "bar" mempty $ return [mockItem])
88+ $ return [mockItem]
89+ ]
90+ ctx' = field "qux" $ const $ return "not baz"
91+ mockItem = Item "" ()
92+ test store provider context str = do
93+ str' <- testCompilerDone store provider ""
94+ $ applyTemplate tpl context mockItem
95+ str @=? itemBody str'