on master help sign in
Wrote documentation for Text.Hakyll.Page and Text.Hakyll.Renderable.
commite6099205d9d2ead9201226c807525102f39883c6 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 12 Dec 2009, 15:17 (17 years ago) parent333c19d
2 files changed+15−5
src/Text/Hakyll/Page.hs+7−1 src/Text/Hakyll/Renderable.hs+8−4
src/Text/Hakyll/Page.hs+7−1
@@ -24,6 +24,7 @@ import Text.Pandoc
2424-- meanings, like for example url, body and title.
2525data Page = Page (M.Map B.ByteString B.ByteString)
2626
27+-- | Create a Page from a key-value mapping.
2728fromContext :: (M.Map B.ByteString B.ByteString) -> Page
2829fromContext = Page
2930
@@ -31,6 +32,7 @@ fromContext = Page
3132addContext :: String -> String -> Page -> Page
3233addContext key value (Page page) = Page $ M.insert (B.pack key) (B.pack value) page
3334
35+-- | Auxiliary function to pack a pair.
3436packPair :: (String, String) -> (B.ByteString, B.ByteString)
3537packPair (a, b) = (B.pack a, B.pack b)
3638
@@ -47,9 +49,11 @@ getPageURL (Page page) =
4749getBody :: Page -> B.ByteString
4850getBody (Page page) = fromMaybe B.empty $ M.lookup (B.pack "body") page
4951
52+-- | The default writer options for pandoc rendering.
5053writerOptions :: WriterOptions
5154writerOptions = defaultWriterOptions
5255
56+-- | Get a render function for a given extension.
5357renderFunction :: String -> (String -> String)
5458renderFunction ".html" = id
5559renderFunction ext = writeHtmlString writerOptions .
@@ -59,6 +63,7 @@ renderFunction ext = writeHtmlString writerOptions .
5963 readFunction ".tex" = readLaTeX
6064 readFunction _ = readMarkdown
6165
66+-- | Read metadata header from a file handle.
6267readMetaData :: Handle -> IO [(String, String)]
6368readMetaData handle = do
6469 line <- hGetLine handle
@@ -67,6 +72,7 @@ readMetaData handle = do
6772 return $ (trimPair . break (== ':')) line : others
6873 where trimPair (key, value) = (trim key, trim $ tail value)
6974
75+-- | Check if the given string is a metadata delimiter.
7076isDelimiter :: String -> Bool
7177isDelimiter = L.isPrefixOf "---"
7278
@@ -119,7 +125,7 @@ readPage pagePath = do
119125pageFromList :: [(String, String)] -> Page
120126pageFromList = Page . M.fromList . map packPair
121127
122−-- Make pages renderable
128+-- Make pages renderable.
123129instance Renderable Page where
124130 getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL
125131 getURL = getPageURL
src/Text/Hakyll/Renderable.hs+8−4
@@ -1,14 +1,18 @@
11module Text.Hakyll.Renderable
2− ( Renderable,
3− toContext,
4− getDependencies,
5− getURL
2+ ( Renderable(toContext, getDependencies, getURL)
63 ) where
74
85import System.FilePath
96import Text.Template
107
8+-- | A class for datatypes that can be rendered to pages.
119class Renderable a where
10+ -- | Get a context to do substitutions with.
1211 toContext :: a -> IO Context
12+
13+ -- | Get the dependencies for the renderable. This is used for cache
14+ -- invalidation.
1315 getDependencies :: a -> [FilePath]
16+
17+ -- | Get the destination for the renderable.
1418 getURL :: a -> FilePath