on master help sign in
Rename require to load, thanks @ddfreyne
commitcfac1bbca6e5950d8abdc8329e84de4794e08677 authorJasper Van der Jeugt <m@jaspervdj.be> dateThu 13 Dec 2012, 22:25 (14 years ago) parent0896706
6 files changed+58−50
data/example/site.hs+17−9 src/Hakyll/Core/Compiler.hs+6−6 src/Hakyll/Core/Compiler/Require.hs+27−27 src/Hakyll/Core/Runtime.hs+1−1 src/Hakyll/Web/Template.hs+6−6 tests/Hakyll/Core/Runtime/Tests.hs+1−1
data/example/site.hs+17−9
@@ -18,9 +18,17 @@ main = hakyll $ do
1818
1919 match (fromList ["about.rst", "contact.markdown"]) $ do
2020 route $ setExtension "html"
21+ compile $ do
22+
23+ defaultTpl <- loadBody "templates/default.html"
24+ pageCompiler
25+ >>= applyTemplate defaultTpl defaultContext
26+ >>= relativizeUrls
27+ {-
2128 compile $ pageCompiler
22− >>= requireApplyTemplate "templates/default.html" defaultContext
29+ >>= loadAndApplyTemplate "templates/default.html" defaultContext
2330 >>= relativizeUrls
31+ -}
2432
2533 match "posts/*" $ do
2634 route $ setExtension "html"
@@ -28,8 +36,8 @@ main = hakyll $ do
2836 post <- pageCompiler
2937 saveSnapshot "content" post
3038 return post
31− >>= requireApplyTemplate "templates/post.html" postCtx
32− >>= requireApplyTemplate "templates/default.html" postCtx
39+ >>= loadAndApplyTemplate "templates/post.html" postCtx
40+ >>= loadAndApplyTemplate "templates/default.html" postCtx
3341 >>= relativizeUrls
3442
3543 match "archive.html" $ do
@@ -41,8 +49,8 @@ main = hakyll $ do
4149 defaultContext
4250
4351 makeItem ""
44− >>= requireApplyTemplate "templates/archive.html" archiveCtx
45− >>= requireApplyTemplate "templates/default.html" archiveCtx
52+ >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
53+ >>= loadAndApplyTemplate "templates/default.html" archiveCtx
4654 >>= relativizeUrls
4755
4856
@@ -52,8 +60,8 @@ main = hakyll $ do
5260 let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
5361
5462 getResourceBody
55− >>= applySelf indexCtx
56− >>= requireApplyTemplate "templates/default.html" postCtx
63+ >>= applyAsTemplate indexCtx
64+ >>= loadAndApplyTemplate "templates/default.html" postCtx
5765 >>= relativizeUrls
5866
5967 match "templates/*" $ compile templateCompiler
@@ -69,7 +77,7 @@ postCtx =
6977--------------------------------------------------------------------------------
7078postList :: ([Item String] -> [Item String]) -> Compiler String
7179postList preprocess = do
72− posts <- preprocess <$> requireAll "posts/*"
73− itemTpl <- requireBody "templates/post-item.html"
80+ posts <- preprocess <$> loadAll "posts/*"
81+ itemTpl <- loadBody "templates/post-item.html"
7482 list <- applyTemplateList itemTpl postCtx posts
7583 return list
src/Hakyll/Core/Compiler.hs+6−6
@@ -13,12 +13,12 @@ module Hakyll.Core.Compiler
1313
1414 , Internal.Snapshot
1515 , saveSnapshot
16− , Internal.require
17− , Internal.requireSnapshot
18− , Internal.requireBody
19− , Internal.requireSnapshotBody
20− , Internal.requireAll
21− , Internal.requireAllSnapshots
16+ , Internal.load
17+ , Internal.loadSnapshot
18+ , Internal.loadBody
19+ , Internal.loadSnapshotBody
20+ , Internal.loadAll
21+ , Internal.loadAllSnapshots
2222
2323 , cached
2424 , unsafeCompiler
src/Hakyll/Core/Compiler/Require.hs+27−27
@@ -3,12 +3,12 @@ module Hakyll.Core.Compiler.Require
33 ( Snapshot
44 , save
55 , saveSnapshot
6− , require
7− , requireSnapshot
8− , requireBody
9− , requireSnapshotBody
10− , requireAll
11− , requireAllSnapshots
6+ , load
7+ , loadSnapshot
8+ , loadBody
9+ , loadSnapshotBody
10+ , loadAll
11+ , loadAllSnapshots
1212 ) where
1313
1414
@@ -44,7 +44,7 @@ save store item = saveSnapshot store final item
4444
4545--------------------------------------------------------------------------------
4646-- | Save a specific snapshot of an item, so you can load it later using
47−-- 'requireSnapshot'.
47+-- 'loadSnapshot'.
4848saveSnapshot :: (Binary a, Typeable a)
4949 => Store -> Snapshot -> Item a -> IO ()
5050saveSnapshot store snapshot item =
@@ -54,15 +54,15 @@ saveSnapshot store snapshot item =
5454--------------------------------------------------------------------------------
5555-- | Load an item compiled elsewhere. If the required item is not yet compiled,
5656-- the build system will take care of that automatically.
57−require :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
58−require id' = requireSnapshot id' final
57+load :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
58+load id' = loadSnapshot id' final
5959
6060
6161--------------------------------------------------------------------------------
6262-- | Require a specific snapshot of an item.
63−requireSnapshot :: (Binary a, Typeable a)
64− => Identifier -> Snapshot -> Compiler (Item a)
65−requireSnapshot id' snapshot = do
63+loadSnapshot :: (Binary a, Typeable a)
64+ => Identifier -> Snapshot -> Compiler (Item a)
65+loadSnapshot id' snapshot = do
6666 store <- compilerStore <$> compilerAsk
6767 universe <- compilerUniverse <$> compilerAsk
6868
@@ -78,12 +78,12 @@ requireSnapshot id' snapshot = do
7878 Store.Found x -> return $ Item id' x
7979 where
8080 notFound =
81− "Hakyll.Core.Compiler.Require.require: " ++ show id' ++
81+ "Hakyll.Core.Compiler.Require.load: " ++ show id' ++
8282 " (snapshot " ++ snapshot ++ ") was not found in the cache, " ++
8383 "the cache might be corrupted or " ++
8484 "the item you are referring to might not exist"
8585 wrongType e r =
86− "Hakyll.Core.Compiler.Require.require: " ++ show id' ++
86+ "Hakyll.Core.Compiler.Require.load: " ++ show id' ++
8787 " (snapshot " ++ snapshot ++ ") was found in the cache, " ++
8888 "but does not have the right type: expected " ++ show e ++
8989 " but got " ++ show r
@@ -92,29 +92,29 @@ requireSnapshot id' snapshot = do
9292--------------------------------------------------------------------------------
9393-- | A shortcut for only requiring the body of an item.
9494--
95−-- > requireBody = fmap itemBody . require
96−requireBody :: (Binary a, Typeable a) => Identifier -> Compiler a
97−requireBody id' = requireSnapshotBody id' final
95+-- > loadBody = fmap itemBody . load
96+loadBody :: (Binary a, Typeable a) => Identifier -> Compiler a
97+loadBody id' = loadSnapshotBody id' final
9898
9999
100100--------------------------------------------------------------------------------
101−requireSnapshotBody :: (Binary a, Typeable a)
102− => Identifier -> Snapshot -> Compiler a
103−requireSnapshotBody id' snapshot = fmap itemBody $ requireSnapshot id' snapshot
101+loadSnapshotBody :: (Binary a, Typeable a)
102+ => Identifier -> Snapshot -> Compiler a
103+loadSnapshotBody id' snapshot = fmap itemBody $ loadSnapshot id' snapshot
104104
105105
106106--------------------------------------------------------------------------------
107−-- | This function allows you to 'require' a dynamic list of items
108−requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
109−requireAll pattern = requireAllSnapshots pattern final
107+-- | This function allows you to 'load' a dynamic list of items
108+loadAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
109+loadAll pattern = loadAllSnapshots pattern final
110110
111111
112112--------------------------------------------------------------------------------
113−requireAllSnapshots :: (Binary a, Typeable a)
114− => Pattern -> Snapshot -> Compiler [Item a]
115−requireAllSnapshots pattern snapshot = do
113+loadAllSnapshots :: (Binary a, Typeable a)
114+ => Pattern -> Snapshot -> Compiler [Item a]
115+loadAllSnapshots pattern snapshot = do
116116 matching <- getMatches pattern
117− mapM (\i -> requireSnapshot i snapshot) matching
117+ mapM (\i -> loadSnapshot i snapshot) matching
118118
119119
120120--------------------------------------------------------------------------------
src/Hakyll/Core/Runtime.hs+1−1
@@ -212,7 +212,7 @@ chase trail id'
212212 liftIO $ write path item
213213 Logger.debug logger $ "Routed to " ++ path
214214
215− -- Save! (For require)
215+ -- Save! (For load)
216216 liftIO $ save store item
217217
218218 -- Update state
src/Hakyll/Web/Template.hs+6−6
@@ -40,7 +40,7 @@ module Hakyll.Web.Template
4040 ( Template
4141 , templateCompiler
4242 , applyTemplate
43− , requireApplyTemplate
43+ , loadAndApplyTemplate
4444 , applyAsTemplate
4545 , applyTemplateWith
4646 ) where
@@ -82,20 +82,20 @@ applyTemplate tpl context item = do
8282--------------------------------------------------------------------------------
8383-- | The following pattern is so common:
8484--
85−-- > tpl <- requireBody "templates/foo.html"
85+-- > tpl <- loadBody "templates/foo.html"
8686-- > someCompiler
8787-- > >>= applyTemplate tpl context
8888--
8989-- That we have a single function which does this:
9090--
9191-- > someCompiler
92−-- > >>= requireApplyTemplate "templates/foo.html" context
93−requireApplyTemplate :: Identifier -- ^ Template identifier
92+-- > >>= loadAndApplyTemplate "templates/foo.html" context
93+loadAndApplyTemplate :: Identifier -- ^ Template identifier
9494 -> Context a -- ^ Context
9595 -> Item a -- ^ Page
9696 -> Compiler (Item String) -- ^ Resulting item
97−requireApplyTemplate identifier context item = do
98− tpl <- requireBody identifier
97+loadAndApplyTemplate identifier context item = do
98+ tpl <- loadBody identifier
9999 applyTemplate tpl context item
100100
101101
tests/Hakyll/Core/Runtime/Tests.hs+1−1
@@ -36,7 +36,7 @@ case01 = withTestConfiguration $ \config -> do
3636 match "bodies.txt" $ do
3737 route idRoute
3838 compile $ do
39− items <- requireAllSnapshots "*.md" "raw"
39+ items <- loadAllSnapshots "*.md" "raw"
4040 makeItem $ concat $ map itemBody (items :: [Item String])
4141
4242 example <- readFile $ destinationDirectory config </> "example.html"