on master help sign in
Better module definitions.
commitf716440837521c192eeccdb95f210ff8b917db13 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 2 Dec 2009, 14:34 (17 years ago) parent36e4bf8
4 files changed+30−7
hakyll.cabal+3−1 src/Text/Hakyll/Page.hs+15−2 src/Text/Hakyll/Render.hs+8−3 src/Text/Hakyll/Util.hs+4−1
hakyll.cabal+3−1
@@ -12,8 +12,10 @@ Cabal-Version: >= 1.2
1212build-type: Simple
1313
1414library
15+ ghc-options: -Wall
1516 hs-source-dirs: src/
16− build-depends: base > 4, template, filepath, directory, containers, bytestring,
17+ build-depends: base >= 4 && < 5, template, filepath, directory, containers, bytestring,
1718 pandoc >= 1
1819 exposed-modules: Text.Hakyll.Render
1920 Text.Hakyll.Page
21+ Text.Hakyll.Util
src/Text/Hakyll/Page.hs+15−2
@@ -1,4 +1,12 @@
1−module Text.Hakyll.Page where
1+module Text.Hakyll.Page
2+ ( Page,
3+ addContext,
4+ getURL,
5+ getBody,
6+ readPage,
7+ pageFromList,
8+ concatPages
9+ ) where
210
311import qualified Data.Map as M
412import qualified Data.List as L
@@ -18,7 +26,7 @@ getBody :: Page -> String
1826getBody context = fromMaybe "" $ M.lookup "body" context
1927
2028readConfig :: [String] -> Page
21−readConfig lines = M.fromList $ map (trim . break (== ':')) lines
29+readConfig = M.fromList . map (trim . break (== ':'))
2230 where trim (key, value) = (key, dropWhile (`elem` ": ") value)
2331
2432extractContext :: String -> Page
@@ -45,3 +53,8 @@ readPage path = do
4553 url = addExtension (dropExtension path) ".html"
4654 return $ addContext "url" url $ addContext "body" body $ context
4755
56+pageFromList :: [(String, String)] -> Page
57+pageFromList = M.fromList
58+
59+concatPages :: [Page] -> String
60+concatPages = concat . map getBody
src/Text/Hakyll/Render.hs+8−3
@@ -1,4 +1,9 @@
1−module Text.Hakyll.Render where
1+module Text.Hakyll.Render
2+ ( renderPage,
3+ renderAndWrite,
4+ static,
5+ staticDirectory
6+ ) where
27
38import Text.Template
49import qualified Data.ByteString.Lazy.Char8 as B
@@ -20,8 +25,8 @@ createContext = M.fromList . map packPair . M.toList
2025
2126renderPage :: FilePath -> Page -> IO Page
2227renderPage templatePath page = do
23− template <- B.readFile templatePath
24− let body = substitute template (createContext page)
28+ templateString <- B.readFile templatePath
29+ let body = substitute templateString (createContext page)
2530 return $ addContext "body" (B.unpack body) page
2631
2732renderAndWrite :: FilePath -> Page -> IO ()
src/Text/Hakyll/Util.hs+4−1
@@ -1,4 +1,7 @@
1−module Text.Hakyll.Util where
1+module Text.Hakyll.Util
2+ ( touchDirectories,
3+ getRecursiveContents
4+ ) where
25
36import System.Directory
47import System.FilePath