on master help sign in
Work on migration to arrows. Compulation fails.

- Update readPage to produce a Hakyll Context. - Update createPagePath to produce a Context Arrow. - Move Page to internal modules.

commit192c4a16ea01c9398a55f61025425d8e0e87e0f8 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 4 Mar 2010, 09:50 (17 years ago) parent76ebcf9
5 files changed+20−31
hakyll.cabal+1−1 src/Text/Hakyll/Page.hs → src/Text/Hakyll/Internal/Page.hs+8−12 src/Text/Hakyll/Internal/Render.hs+1−1 src/Text/Hakyll/Render.hs+2−2 src/Text/Hakyll/Renderables.hs+8−15
hakyll.cabal+1−1
@@ -47,11 +47,11 @@ library
4747 Text.Hakyll.RenderAction
4848 Text.Hakyll.Renderable
4949 Text.Hakyll.Renderables
50− Text.Hakyll.Page
5150 Text.Hakyll.Paginate
5251 Text.Hakyll.Util
5352 Text.Hakyll.Tags
5453 Text.Hakyll.Internal.Cache
5554 Text.Hakyll.Internal.CompressCss
55+ Text.Hakyll.Internal.Page
5656 Text.Hakyll.Internal.Render
5757 Text.Hakyll.Internal.Template
src/Text/Hakyll/Page.hs → src/Text/Hakyll/Internal/Page.hsrenamed+8−12
@@ -1,5 +1,5 @@
11-- | A module for dealing with @Page@s. This module is mostly internally used.
2−module Text.Hakyll.Page
2+module Text.Hakyll.Internal.Page
33 ( Page
44 , fromContext
55 , getValue
@@ -25,6 +25,7 @@ import Text.Hakyll.File
2525import Text.Hakyll.Util (trim)
2626import Text.Hakyll.Context (Context)
2727import Text.Hakyll.Renderable
28+import Text.Hakyll.RenderAction
2829import Text.Hakyll.Regex (substituteRegex, matchesRegex)
2930
3031-- | A Page is basically key-value mapping. Certain keys have special
@@ -125,7 +126,7 @@ readSection renderFunction isFirst ls
125126
126127-- | Read a page from a file. Metadata is supported, and if the filename
127128-- has a @.markdown@ extension, it will be rendered using pandoc.
128−readPageFromFile :: FilePath -> Hakyll Page
129+readPageFromFile :: FilePath -> Hakyll Context
129130readPageFromFile path = do
130131 let renderFunction = getRenderFunction $ takeExtension path
131132 sectionFunctions = map (readSection renderFunction)
@@ -133,23 +134,18 @@ readPageFromFile path = do
133134
134135 -- Read file.
135136 contents <- liftIO $ readFile path
136− url <- toUrl path
137137 let sections = splitAtDelimiters $ lines contents
138− context = concat $ zipWith ($) sectionFunctions sections
139− page = fromContext $ M.fromList $
140− category ++
141− [ ("url", url)
142− , ("path", path)
143− ] ++ context
144−
145− return page
138+ sectionsData = concat $ zipWith ($) sectionFunctions sections
139+ context = M.fromList $ category ++ sectionsData
140+
141+ return context
146142 where
147143 category = let dirs = splitDirectories $ takeDirectory path
148144 in [("category", last dirs) | not (null dirs)]
149145
150146-- | Read a page. Might fetch it from the cache if available. Otherwise, it will
151147-- read it from the file given and store it in the cache.
152−readPage :: FilePath -> Hakyll Page
148+readPage :: FilePath -> Hakyll Context
153149readPage path = do
154150 isCacheMoreRecent' <- isCacheMoreRecent fileName [path]
155151 if isCacheMoreRecent' then getFromCache fileName
src/Text/Hakyll/Internal/Render.hs+1−1
@@ -16,9 +16,9 @@ import Data.Maybe (fromMaybe)
1616
1717import Text.Hakyll.Context (Context, ContextManipulation)
1818import Text.Hakyll.Renderable
19−import Text.Hakyll.Page
2019import Text.Hakyll.File
2120import Text.Hakyll.Hakyll
21+import Text.Hakyll.Internal.Page
2222import Text.Hakyll.Internal.Template
2323
2424-- | A pure render function.
src/Text/Hakyll/Render.hs+2−2
@@ -18,12 +18,12 @@ import System.Directory (copyFile)
1818
1919import Text.Hakyll.Hakyll (Hakyll)
2020import Text.Hakyll.Context (ContextManipulation)
21−import Text.Hakyll.Page
2221import Text.Hakyll.Renderable
2322import Text.Hakyll.File
24−import Text.Hakyll.Internal.Template (readTemplate)
2523import Text.Hakyll.Internal.CompressCss
24+import Text.Hakyll.Internal.Page
2625import Text.Hakyll.Internal.Render
26+import Text.Hakyll.Internal.Template (readTemplate)
2727
2828-- | Execute an IO action only when the cache is invalid.
2929depends :: FilePath -- ^ File to be rendered or created.
src/Text/Hakyll/Renderables.hs+8−15
@@ -11,18 +11,18 @@ module Text.Hakyll.Renderables
1111
1212import qualified Data.Map as M
1313import Control.Arrow (second)
14−import Control.Monad (liftM, liftM2, mplus)
14+import Control.Monad (liftM2, mplus)
1515import Control.Applicative ((<$>))
1616
1717import Data.Binary
1818
1919import Text.Hakyll.Hakyll (Hakyll)
20−import Text.Hakyll.Page
2120import Text.Hakyll.Renderable
2221import Text.Hakyll.File
2322import Text.Hakyll.Context
2423import Text.Hakyll.Render
2524import Text.Hakyll.RenderAction
25+import Text.Hakyll.Internal.Page
2626
2727-- | Create a custom page.
2828--
@@ -90,19 +90,12 @@ newtype PagePath = PagePath FilePath
9090 deriving (Ord, Eq, Read, Show)
9191
9292-- | Create a PagePath from a FilePath.
93−createPagePath :: FilePath -> PagePath
94−createPagePath = PagePath
95−
96−-- We can render filepaths
97−instance Renderable PagePath where
98− getDependencies (PagePath path) = return path
99− getUrl (PagePath path) = toUrl path
100− toContext (PagePath path) = readPage path >>= toContext
101−
102−-- We can serialize filepaths
103−instance Binary PagePath where
104− put (PagePath path) = put path
105− get = liftM PagePath get
93+createPagePath :: FilePath -> RenderAction () Context
94+createPagePath path = RenderAction
95+ { actionDependencies = [path]
96+ , actionDestination = Just $ toUrl path
97+ , actionFunction = const (readPage path)
98+ }
10699
107100-- | A combination of two other renderables.
108101data CombinedRenderable a b = CombinedRenderable a b