Better module definitions.

This commit is contained in:
Jasper Van der Jeugt 2009-12-02 14:34:50 +01:00
parent 36e4bf881b
commit f716440837
4 changed files with 30 additions and 7 deletions

View file

@ -12,8 +12,10 @@ Cabal-Version: >= 1.2
build-type: Simple
library
ghc-options: -Wall
hs-source-dirs: src/
build-depends: base > 4, template, filepath, directory, containers, bytestring,
build-depends: base >= 4 && < 5, template, filepath, directory, containers, bytestring,
pandoc >= 1
exposed-modules: Text.Hakyll.Render
Text.Hakyll.Page
Text.Hakyll.Util

View file

@ -1,4 +1,12 @@
module Text.Hakyll.Page where
module Text.Hakyll.Page
( Page,
addContext,
getURL,
getBody,
readPage,
pageFromList,
concatPages
) where
import qualified Data.Map as M
import qualified Data.List as L
@ -18,7 +26,7 @@ getBody :: Page -> String
getBody context = fromMaybe "" $ M.lookup "body" context
readConfig :: [String] -> Page
readConfig lines = M.fromList $ map (trim . break (== ':')) lines
readConfig = M.fromList . map (trim . break (== ':'))
where trim (key, value) = (key, dropWhile (`elem` ": ") value)
extractContext :: String -> Page
@ -45,3 +53,8 @@ readPage path = do
url = addExtension (dropExtension path) ".html"
return $ addContext "url" url $ addContext "body" body $ context
pageFromList :: [(String, String)] -> Page
pageFromList = M.fromList
concatPages :: [Page] -> String
concatPages = concat . map getBody

View file

@ -1,4 +1,9 @@
module Text.Hakyll.Render where
module Text.Hakyll.Render
( renderPage,
renderAndWrite,
static,
staticDirectory
) where
import Text.Template
import qualified Data.ByteString.Lazy.Char8 as B
@ -20,8 +25,8 @@ createContext = M.fromList . map packPair . M.toList
renderPage :: FilePath -> Page -> IO Page
renderPage templatePath page = do
template <- B.readFile templatePath
let body = substitute template (createContext page)
templateString <- B.readFile templatePath
let body = substitute templateString (createContext page)
return $ addContext "body" (B.unpack body) page
renderAndWrite :: FilePath -> Page -> IO ()

View file

@ -1,4 +1,7 @@
module Text.Hakyll.Util where
module Text.Hakyll.Util
( touchDirectories,
getRecursiveContents
) where
import System.Directory
import System.FilePath