summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-04 09:50:25 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-04 09:50:25 +0100
commit192c4a16ea01c9398a55f61025425d8e0e87e0f8 (patch)
treef9980899244c11c34d400ee5d8ad3d9c4ca3a803 /src/Text
parent76ebcf97b4e2c993297aa914ce576fc0abd68d06 (diff)
downloadhakyll-192c4a16ea01c9398a55f61025425d8e0e87e0f8.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Hakyll/Internal/Page.hs (renamed from src/Text/Hakyll/Page.hs)20
-rw-r--r--src/Text/Hakyll/Internal/Render.hs2
-rw-r--r--src/Text/Hakyll/Render.hs4
-rw-r--r--src/Text/Hakyll/Renderables.hs23
4 files changed, 19 insertions, 30 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Internal/Page.hs
index 54f9c84..92e7249 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Internal/Page.hs
@@ -1,5 +1,5 @@
-- | A module for dealing with @Page@s. This module is mostly internally used.
-module Text.Hakyll.Page
+module Text.Hakyll.Internal.Page
( Page
, fromContext
, getValue
@@ -25,6 +25,7 @@ import Text.Hakyll.File
import Text.Hakyll.Util (trim)
import Text.Hakyll.Context (Context)
import Text.Hakyll.Renderable
+import Text.Hakyll.RenderAction
import Text.Hakyll.Regex (substituteRegex, matchesRegex)
-- | A Page is basically key-value mapping. Certain keys have special
@@ -125,7 +126,7 @@ readSection renderFunction isFirst ls
-- | Read a page from a file. Metadata is supported, and if the filename
-- has a @.markdown@ extension, it will be rendered using pandoc.
-readPageFromFile :: FilePath -> Hakyll Page
+readPageFromFile :: FilePath -> Hakyll Context
readPageFromFile path = do
let renderFunction = getRenderFunction $ takeExtension path
sectionFunctions = map (readSection renderFunction)
@@ -133,23 +134,18 @@ readPageFromFile path = do
-- Read file.
contents <- liftIO $ readFile path
- url <- toUrl path
let sections = splitAtDelimiters $ lines contents
- context = concat $ zipWith ($) sectionFunctions sections
- page = fromContext $ M.fromList $
- category ++
- [ ("url", url)
- , ("path", path)
- ] ++ context
-
- return page
+ sectionsData = concat $ zipWith ($) sectionFunctions sections
+ context = M.fromList $ category ++ sectionsData
+
+ return context
where
category = let dirs = splitDirectories $ takeDirectory path
in [("category", last dirs) | not (null dirs)]
-- | Read a page. Might fetch it from the cache if available. Otherwise, it will
-- read it from the file given and store it in the cache.
-readPage :: FilePath -> Hakyll Page
+readPage :: FilePath -> Hakyll Context
readPage path = do
isCacheMoreRecent' <- isCacheMoreRecent fileName [path]
if isCacheMoreRecent' then getFromCache fileName
diff --git a/src/Text/Hakyll/Internal/Render.hs b/src/Text/Hakyll/Internal/Render.hs
index 49e6be2..00b74a7 100644
--- a/src/Text/Hakyll/Internal/Render.hs
+++ b/src/Text/Hakyll/Internal/Render.hs
@@ -16,9 +16,9 @@ import Data.Maybe (fromMaybe)
import Text.Hakyll.Context (Context, ContextManipulation)
import Text.Hakyll.Renderable
-import Text.Hakyll.Page
import Text.Hakyll.File
import Text.Hakyll.Hakyll
+import Text.Hakyll.Internal.Page
import Text.Hakyll.Internal.Template
-- | A pure render function.
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index 64fc0ab..98d1a3c 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -18,12 +18,12 @@ import System.Directory (copyFile)
import Text.Hakyll.Hakyll (Hakyll)
import Text.Hakyll.Context (ContextManipulation)
-import Text.Hakyll.Page
import Text.Hakyll.Renderable
import Text.Hakyll.File
-import Text.Hakyll.Internal.Template (readTemplate)
import Text.Hakyll.Internal.CompressCss
+import Text.Hakyll.Internal.Page
import Text.Hakyll.Internal.Render
+import Text.Hakyll.Internal.Template (readTemplate)
-- | Execute an IO action only when the cache is invalid.
depends :: FilePath -- ^ File to be rendered or created.
diff --git a/src/Text/Hakyll/Renderables.hs b/src/Text/Hakyll/Renderables.hs
index 136bd85..42c05cc 100644
--- a/src/Text/Hakyll/Renderables.hs
+++ b/src/Text/Hakyll/Renderables.hs
@@ -11,18 +11,18 @@ module Text.Hakyll.Renderables
import qualified Data.Map as M
import Control.Arrow (second)
-import Control.Monad (liftM, liftM2, mplus)
+import Control.Monad (liftM2, mplus)
import Control.Applicative ((<$>))
import Data.Binary
import Text.Hakyll.Hakyll (Hakyll)
-import Text.Hakyll.Page
import Text.Hakyll.Renderable
import Text.Hakyll.File
import Text.Hakyll.Context
import Text.Hakyll.Render
import Text.Hakyll.RenderAction
+import Text.Hakyll.Internal.Page
-- | Create a custom page.
--
@@ -90,19 +90,12 @@ newtype PagePath = PagePath FilePath
deriving (Ord, Eq, Read, Show)
-- | Create a PagePath from a FilePath.
-createPagePath :: FilePath -> PagePath
-createPagePath = PagePath
-
--- We can render filepaths
-instance Renderable PagePath where
- getDependencies (PagePath path) = return path
- getUrl (PagePath path) = toUrl path
- toContext (PagePath path) = readPage path >>= toContext
-
--- We can serialize filepaths
-instance Binary PagePath where
- put (PagePath path) = put path
- get = liftM PagePath get
+createPagePath :: FilePath -> RenderAction () Context
+createPagePath path = RenderAction
+ { actionDependencies = [path]
+ , actionDestination = Just $ toUrl path
+ , actionFunction = const (readPage path)
+ }
-- | A combination of two other renderables.
data CombinedRenderable a b = CombinedRenderable a b