on master help sign in
Rename require to load, thanks @ddfreyne
cfac1bbJasper Van der Jeugt
data/example/site.hs+17−9
@@ -18,9 +18,17 @@ main = hakyll $ do
18
18
19 match (fromList ["about.rst", "contact.markdown"]) $ do
19 match (fromList ["about.rst", "contact.markdown"]) $ do
20 route $ setExtension "html"
20 route $ setExtension "html"
21+ compile $ do
22+
23+ defaultTpl <- loadBody "templates/default.html"
24+ pageCompiler
25+ >>= applyTemplate defaultTpl defaultContext
26+ >>= relativizeUrls
27+ {-
21 compile $ pageCompiler
28 compile $ pageCompiler
22− >>= requireApplyTemplate "templates/default.html" defaultContext
29+ >>= loadAndApplyTemplate "templates/default.html" defaultContext
23 >>= relativizeUrls
30 >>= relativizeUrls
31+ -}
24
32
25 match "posts/*" $ do
33 match "posts/*" $ do
26 route $ setExtension "html"
34 route $ setExtension "html"
@@ -28,8 +36,8 @@ main = hakyll $ do
28 post <- pageCompiler
36 post <- pageCompiler
29 saveSnapshot "content" post
37 saveSnapshot "content" post
30 return post
38 return post
31− >>= requireApplyTemplate "templates/post.html" postCtx
39+ >>= loadAndApplyTemplate "templates/post.html" postCtx
32− >>= requireApplyTemplate "templates/default.html" postCtx
40+ >>= loadAndApplyTemplate "templates/default.html" postCtx
33 >>= relativizeUrls
41 >>= relativizeUrls
34
42
35 match "archive.html" $ do
43 match "archive.html" $ do
@@ -41,8 +49,8 @@ main = hakyll $ do
41 defaultContext
49 defaultContext
42
50
43 makeItem ""
51 makeItem ""
44− >>= requireApplyTemplate "templates/archive.html" archiveCtx
52+ >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
45− >>= requireApplyTemplate "templates/default.html" archiveCtx
53+ >>= loadAndApplyTemplate "templates/default.html" archiveCtx
46 >>= relativizeUrls
54 >>= relativizeUrls
47
55
48
56
@@ -52,8 +60,8 @@ main = hakyll $ do
52 let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
60 let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
53
61
54 getResourceBody
62 getResourceBody
55− >>= applySelf indexCtx
63+ >>= applyAsTemplate indexCtx
56− >>= requireApplyTemplate "templates/default.html" postCtx
64+ >>= loadAndApplyTemplate "templates/default.html" postCtx
57 >>= relativizeUrls
65 >>= relativizeUrls
58
66
59 match "templates/*" $ compile templateCompiler
67 match "templates/*" $ compile templateCompiler
@@ -69,7 +77,7 @@ postCtx =
69--------------------------------------------------------------------------------
77--------------------------------------------------------------------------------
70postList :: ([Item String] -> [Item String]) -> Compiler String
78postList :: ([Item String] -> [Item String]) -> Compiler String
71postList preprocess = do
79postList preprocess = do
72− posts <- preprocess <$> requireAll "posts/*"
80+ posts <- preprocess <$> loadAll "posts/*"
73− itemTpl <- requireBody "templates/post-item.html"
81+ itemTpl <- loadBody "templates/post-item.html"
74 list <- applyTemplateList itemTpl postCtx posts
82 list <- applyTemplateList itemTpl postCtx posts
75 return list
83 return list
src/Hakyll/Core/Compiler.hs+6−6
@@ -13,12 +13,12 @@ module Hakyll.Core.Compiler
13
13
14 , Internal.Snapshot
14 , Internal.Snapshot
15 , saveSnapshot
15 , saveSnapshot
16− , Internal.require
16+ , Internal.load
17− , Internal.requireSnapshot
17+ , Internal.loadSnapshot
18− , Internal.requireBody
18+ , Internal.loadBody
19− , Internal.requireSnapshotBody
19+ , Internal.loadSnapshotBody
20− , Internal.requireAll
20+ , Internal.loadAll
21− , Internal.requireAllSnapshots
21+ , Internal.loadAllSnapshots
22
22
23 , cached
23 , cached
24 , unsafeCompiler
24 , unsafeCompiler
src/Hakyll/Core/Compiler/Require.hs+27−27
@@ -3,12 +3,12 @@ module Hakyll.Core.Compiler.Require
3 ( Snapshot
3 ( Snapshot
4 , save
4 , save
5 , saveSnapshot
5 , saveSnapshot
6− , require
6+ , load
7− , requireSnapshot
7+ , loadSnapshot
8− , requireBody
8+ , loadBody
9− , requireSnapshotBody
9+ , loadSnapshotBody
10− , requireAll
10+ , loadAll
11− , requireAllSnapshots
11+ , loadAllSnapshots
12 ) where
12 ) where
13
13
14
14
@@ -44,7 +44,7 @@ save store item = saveSnapshot store final item
44
44
45--------------------------------------------------------------------------------
45--------------------------------------------------------------------------------
46-- | Save a specific snapshot of an item, so you can load it later using
46-- | Save a specific snapshot of an item, so you can load it later using
47−-- 'requireSnapshot'.
47+-- 'loadSnapshot'.
48saveSnapshot :: (Binary a, Typeable a)
48saveSnapshot :: (Binary a, Typeable a)
49 => Store -> Snapshot -> Item a -> IO ()
49 => Store -> Snapshot -> Item a -> IO ()
50saveSnapshot store snapshot item =
50saveSnapshot store snapshot item =
@@ -54,15 +54,15 @@ saveSnapshot store snapshot item =
54--------------------------------------------------------------------------------
54--------------------------------------------------------------------------------
55-- | Load an item compiled elsewhere. If the required item is not yet compiled,
55-- | Load an item compiled elsewhere. If the required item is not yet compiled,
56-- the build system will take care of that automatically.
56-- the build system will take care of that automatically.
57−require :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
57+load :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
58−require id' = requireSnapshot id' final
58+load id' = loadSnapshot id' final
59
59
60
60
61--------------------------------------------------------------------------------
61--------------------------------------------------------------------------------
62-- | Require a specific snapshot of an item.
62-- | Require a specific snapshot of an item.
63−requireSnapshot :: (Binary a, Typeable a)
63+loadSnapshot :: (Binary a, Typeable a)
64− => Identifier -> Snapshot -> Compiler (Item a)
64+ => Identifier -> Snapshot -> Compiler (Item a)
65−requireSnapshot id' snapshot = do
65+loadSnapshot id' snapshot = do
66 store <- compilerStore <$> compilerAsk
66 store <- compilerStore <$> compilerAsk
67 universe <- compilerUniverse <$> compilerAsk
67 universe <- compilerUniverse <$> compilerAsk
68
68
@@ -78,12 +78,12 @@ requireSnapshot id' snapshot = do
78 Store.Found x -> return $ Item id' x
78 Store.Found x -> return $ Item id' x
79 where
79 where
80 notFound =
80 notFound =
81− "Hakyll.Core.Compiler.Require.require: " ++ show id' ++
81+ "Hakyll.Core.Compiler.Require.load: " ++ show id' ++
82 " (snapshot " ++ snapshot ++ ") was not found in the cache, " ++
82 " (snapshot " ++ snapshot ++ ") was not found in the cache, " ++
83 "the cache might be corrupted or " ++
83 "the cache might be corrupted or " ++
84 "the item you are referring to might not exist"
84 "the item you are referring to might not exist"
85 wrongType e r =
85 wrongType e r =
86− "Hakyll.Core.Compiler.Require.require: " ++ show id' ++
86+ "Hakyll.Core.Compiler.Require.load: " ++ show id' ++
87 " (snapshot " ++ snapshot ++ ") was found in the cache, " ++
87 " (snapshot " ++ snapshot ++ ") was found in the cache, " ++
88 "but does not have the right type: expected " ++ show e ++
88 "but does not have the right type: expected " ++ show e ++
89 " but got " ++ show r
89 " but got " ++ show r
@@ -92,29 +92,29 @@ requireSnapshot id' snapshot = do
92--------------------------------------------------------------------------------
92--------------------------------------------------------------------------------
93-- | A shortcut for only requiring the body of an item.
93-- | A shortcut for only requiring the body of an item.
94--
94--
95−-- > requireBody = fmap itemBody . require
95+-- > loadBody = fmap itemBody . load
96−requireBody :: (Binary a, Typeable a) => Identifier -> Compiler a
96+loadBody :: (Binary a, Typeable a) => Identifier -> Compiler a
97−requireBody id' = requireSnapshotBody id' final
97+loadBody id' = loadSnapshotBody id' final
98
98
99
99
100--------------------------------------------------------------------------------
100--------------------------------------------------------------------------------
101−requireSnapshotBody :: (Binary a, Typeable a)
101+loadSnapshotBody :: (Binary a, Typeable a)
102− => Identifier -> Snapshot -> Compiler a
102+ => Identifier -> Snapshot -> Compiler a
103−requireSnapshotBody id' snapshot = fmap itemBody $ requireSnapshot id' snapshot
103+loadSnapshotBody id' snapshot = fmap itemBody $ loadSnapshot id' snapshot
104
104
105
105
106--------------------------------------------------------------------------------
106--------------------------------------------------------------------------------
107−-- | This function allows you to 'require' a dynamic list of items
107+-- | This function allows you to 'load' a dynamic list of items
108−requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
108+loadAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
109−requireAll pattern = requireAllSnapshots pattern final
109+loadAll pattern = loadAllSnapshots pattern final
110
110
111
111
112--------------------------------------------------------------------------------
112--------------------------------------------------------------------------------
113−requireAllSnapshots :: (Binary a, Typeable a)
113+loadAllSnapshots :: (Binary a, Typeable a)
114− => Pattern -> Snapshot -> Compiler [Item a]
114+ => Pattern -> Snapshot -> Compiler [Item a]
115−requireAllSnapshots pattern snapshot = do
115+loadAllSnapshots pattern snapshot = do
116 matching <- getMatches pattern
116 matching <- getMatches pattern
117− mapM (\i -> requireSnapshot i snapshot) matching
117+ mapM (\i -> loadSnapshot i snapshot) matching
118
118
119
119
120--------------------------------------------------------------------------------
120--------------------------------------------------------------------------------
src/Hakyll/Core/Runtime.hs+1−1
@@ -212,7 +212,7 @@ chase trail id'
212 liftIO $ write path item
212 liftIO $ write path item
213 Logger.debug logger $ "Routed to " ++ path
213 Logger.debug logger $ "Routed to " ++ path
214
214
215− -- Save! (For require)
215+ -- Save! (For load)
216 liftIO $ save store item
216 liftIO $ save store item
217
217
218 -- Update state
218 -- Update state
src/Hakyll/Web/Template.hs+6−6
@@ -40,7 +40,7 @@ module Hakyll.Web.Template
40 ( Template
40 ( Template
41 , templateCompiler
41 , templateCompiler
42 , applyTemplate
42 , applyTemplate
43− , requireApplyTemplate
43+ , loadAndApplyTemplate
44 , applyAsTemplate
44 , applyAsTemplate
45 , applyTemplateWith
45 , applyTemplateWith
46 ) where
46 ) where
@@ -82,20 +82,20 @@ applyTemplate tpl context item = do
82--------------------------------------------------------------------------------
82--------------------------------------------------------------------------------
83-- | The following pattern is so common:
83-- | The following pattern is so common:
84--
84--
85−-- > tpl <- requireBody "templates/foo.html"
85+-- > tpl <- loadBody "templates/foo.html"
86-- > someCompiler
86-- > someCompiler
87-- > >>= applyTemplate tpl context
87-- > >>= applyTemplate tpl context
88--
88--
89-- That we have a single function which does this:
89-- That we have a single function which does this:
90--
90--
91-- > someCompiler
91-- > someCompiler
92−-- > >>= requireApplyTemplate "templates/foo.html" context
92+-- > >>= loadAndApplyTemplate "templates/foo.html" context
93−requireApplyTemplate :: Identifier -- ^ Template identifier
93+loadAndApplyTemplate :: Identifier -- ^ Template identifier
94 -> Context a -- ^ Context
94 -> Context a -- ^ Context
95 -> Item a -- ^ Page
95 -> Item a -- ^ Page
96 -> Compiler (Item String) -- ^ Resulting item
96 -> Compiler (Item String) -- ^ Resulting item
97−requireApplyTemplate identifier context item = do
97+loadAndApplyTemplate identifier context item = do
98− tpl <- requireBody identifier
98+ tpl <- loadBody identifier
99 applyTemplate tpl context item
99 applyTemplate tpl context item
100
100
101
101
tests/Hakyll/Core/Runtime/Tests.hs+1−1
@@ -36,7 +36,7 @@ case01 = withTestConfiguration $ \config -> do
36 match "bodies.txt" $ do
36 match "bodies.txt" $ do
37 route idRoute
37 route idRoute
38 compile $ do
38 compile $ do
39− items <- requireAllSnapshots "*.md" "raw"
39+ items <- loadAllSnapshots "*.md" "raw"
40 makeItem $ concat $ map itemBody (items :: [Item String])
40 makeItem $ concat $ map itemBody (items :: [Item String])
41
41
42 example <- readFile $ destinationDirectory config </> "example.html"
42 example <- readFile $ destinationDirectory config </> "example.html"