From e6099205d9d2ead9201226c807525102f39883c6 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 12 Dec 2009 15:17:01 +0100 Subject: Wrote documentation for Text.Hakyll.Page and Text.Hakyll.Renderable. --- src/Text/Hakyll/Page.hs | 8 +++++++- src/Text/Hakyll/Renderable.hs | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index 857a016..f106303 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -24,6 +24,7 @@ import Text.Pandoc -- meanings, like for example url, body and title. data Page = Page (M.Map B.ByteString B.ByteString) +-- | Create a Page from a key-value mapping. fromContext :: (M.Map B.ByteString B.ByteString) -> Page fromContext = Page @@ -31,6 +32,7 @@ fromContext = Page addContext :: String -> String -> Page -> Page addContext key value (Page page) = Page $ M.insert (B.pack key) (B.pack value) page +-- | Auxiliary function to pack a pair. packPair :: (String, String) -> (B.ByteString, B.ByteString) packPair (a, b) = (B.pack a, B.pack b) @@ -47,9 +49,11 @@ getPageURL (Page page) = getBody :: Page -> B.ByteString getBody (Page page) = fromMaybe B.empty $ M.lookup (B.pack "body") page +-- | The default writer options for pandoc rendering. writerOptions :: WriterOptions writerOptions = defaultWriterOptions +-- | Get a render function for a given extension. renderFunction :: String -> (String -> String) renderFunction ".html" = id renderFunction ext = writeHtmlString writerOptions . @@ -59,6 +63,7 @@ renderFunction ext = writeHtmlString writerOptions . readFunction ".tex" = readLaTeX readFunction _ = readMarkdown +-- | Read metadata header from a file handle. readMetaData :: Handle -> IO [(String, String)] readMetaData handle = do line <- hGetLine handle @@ -67,6 +72,7 @@ readMetaData handle = do return $ (trimPair . break (== ':')) line : others where trimPair (key, value) = (trim key, trim $ tail value) +-- | Check if the given string is a metadata delimiter. isDelimiter :: String -> Bool isDelimiter = L.isPrefixOf "---" @@ -119,7 +125,7 @@ readPage pagePath = do pageFromList :: [(String, String)] -> Page pageFromList = Page . M.fromList . map packPair --- Make pages renderable +-- Make pages renderable. instance Renderable Page where getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL getURL = getPageURL diff --git a/src/Text/Hakyll/Renderable.hs b/src/Text/Hakyll/Renderable.hs index 12aff5b..549899c 100644 --- a/src/Text/Hakyll/Renderable.hs +++ b/src/Text/Hakyll/Renderable.hs @@ -1,14 +1,18 @@ module Text.Hakyll.Renderable - ( Renderable, - toContext, - getDependencies, - getURL + ( Renderable(toContext, getDependencies, getURL) ) where import System.FilePath import Text.Template +-- | A class for datatypes that can be rendered to pages. class Renderable a where + -- | Get a context to do substitutions with. toContext :: a -> IO Context + + -- | Get the dependencies for the renderable. This is used for cache + -- invalidation. getDependencies :: a -> [FilePath] + + -- | Get the destination for the renderable. getURL :: a -> FilePath -- cgit v1.2.3