on 036c583 help sign in
6 files changed+46−59
since splitsnapshots
unifiedsplit
CHANGELOG.md−13 hakyll.cabal+1−1 lib/Hakyll/Web/Template/Context.hs+1−14 lib/Hakyll/Web/Template/Internal.hs+2−3 tests/Hakyll/Web/Tags/Tests.hs+42 tests/Hakyll/Web/Template/Context/Tests.hs−28
CHANGELOG.md−13
@@ -4,19 +4,6 @@ title: Releases
44
55# Releases
66
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−
207## Hakyll 4.12.5.2 (2019-05-09)
218
229- Bump pandoc to 2.7
hakyll.cabal+1−1
@@ -1,5 +1,5 @@
11Name: hakyll
2−Version: 4.13.0.0
2+Version: 4.12.5.2
33
44Synopsis: A static website compiler library
55Description:
lib/Hakyll/Web/Template/Context.hs+1−14
@@ -21,7 +21,6 @@
2121--------------------------------------------------------------------------------
2222{-# LANGUAGE CPP #-}
2323{-# LANGUAGE ExistentialQuantification #-}
24−{-# LANGUAGE RankNTypes #-}
2524module Hakyll.Web.Template.Context
2625 ( ContextField (..)
2726 , Context (..)
@@ -49,7 +48,6 @@ module Hakyll.Web.Template.Context
4948 , teaserField
5049 , teaserFieldWithSeparator
5150 , missingField
52− , bindItem
5351 ) where
5452
5553
@@ -178,11 +176,7 @@ listField key c xs = listFieldWith key c (const xs)
178176
179177
180178--------------------------------------------------------------------------------
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.
185−-- Creates a list field like 'listField', but supplies the current page
179+-- | Creates a list field like 'listField', but supplies the current page
186180-- to the compiler.
187181listFieldWith
188182 :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
@@ -472,10 +466,3 @@ parseTimeM = TF.parseTimeM
472466#else
473467parseTimeM _ = TF.parseTime
474468#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+2−3
@@ -21,8 +21,7 @@ module Hakyll.Web.Template.Internal
2121
2222
2323--------------------------------------------------------------------------------
24−import Control.Monad (forM)
25−import Control.Monad.Except (MonadError (..), catchError)
24+import Control.Monad.Except (catchError)
2625import Data.Binary (Binary)
2726import Data.List (intercalate)
2827import qualified Data.List.NonEmpty as NonEmpty
@@ -172,7 +171,7 @@ applyTemplate' tes context x = go tes
172171 StringField _ -> expected "list" "string" typeMsg
173172 ListField c xs -> withErrorMessage bodyMsg $ do
174173 sep <- maybe (return "") go s
175− bs <- forM xs $ applyTemplate' b $ c <> bindItem context x
174+ bs <- mapM (applyTemplate' b c) xs
176175 return $ intercalate sep bs
177176 where
178177 headMsg = "In expr '$for(" ++ show e ++ ")$'"
tests/Hakyll/Web/Tags/Tests.hsnew file+42
@@ -0,0 +1,42 @@
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,11 +13,9 @@ import Test.Tasty.HUnit (Assertion, testCase, (@=?))
1313--------------------------------------------------------------------------------
1414import Hakyll.Core.Compiler
1515import Hakyll.Core.Identifier
16−import Hakyll.Core.Item
1716import Hakyll.Core.Provider
1817import Hakyll.Core.Store (Store)
1918import Hakyll.Web.Template.Context
20−import Hakyll.Web.Template.Internal
2119import TestSuite.Util
2220
2321
@@ -25,7 +23,6 @@ import TestSuite.Util
2523tests :: TestTree
2624tests = testGroup "Hakyll.Web.Template.Context.Tests"
2725 [ testCase "testDateField" testDateField
28− , testCase "testOuerLoopContextAccess" testOuerLoopContextAccess
2926 ]
3027
3128
@@ -68,28 +65,3 @@ testContextDone store provider identifier key context =
6865 _ -> error $
6966 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
7067 "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'