on master help sign in
Merged Text.Hakyll.Internal.Render into Text.Hakyll.Render.
commit35e824648499d868b2c37b41ecc8f847f452917b authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 10 Mar 2010, 19:47 (17 years ago) parent23f9d1e
5 files changed+38−54
hakyll.cabal−1 src/Network/Hakyll/SimpleServer.hs+10−10 src/Text/Hakyll/Feed.hs+1−1 src/Text/Hakyll/Internal/Render.hs−39 src/Text/Hakyll/Render.hs+27−3
hakyll.cabal−1
@@ -58,6 +58,5 @@ library
5858 Text.Hakyll.Internal.CompressCss
5959 Text.Hakyll.Internal.FileType
6060 Text.Hakyll.Internal.Page
61− Text.Hakyll.Internal.Render
6261 Text.Hakyll.Internal.Template
6362 other-modules: Paths_hakyll
src/Network/Hakyll/SimpleServer.hs+10−10
@@ -143,16 +143,16 @@ getMIMEHeader fileName =
143143 Nothing -> []
144144 where
145145 result = lookup (takeExtension fileName) [ (".css", "text/css")
146− , (".gif", "image/gif")
147− , (".htm", "text/html")
148− , (".html", "text/html")
149− , (".jpeg", "image/jpeg")
150− , (".jpg", "image/jpeg")
151− , (".js", "text/javascript")
152− , (".png", "image/png")
153− , (".txt", "text/plain")
154− , (".xml", "text/xml")
155− ]
146+ , (".gif", "image/gif")
147+ , (".htm", "text/html")
148+ , (".html", "text/html")
149+ , (".jpeg", "image/jpeg")
150+ , (".jpg", "image/jpeg")
151+ , (".js", "text/javascript")
152+ , (".png", "image/png")
153+ , (".txt", "text/plain")
154+ , (".xml", "text/xml")
155+ ]
156156
157157-- | Respond to an incoming request.
158158respond :: Handle -> Server ()
src/Text/Hakyll/Feed.hs+1−1
@@ -28,7 +28,7 @@ import Control.Monad.Reader (liftIO)
2828import Data.Maybe (fromMaybe)
2929import qualified Data.Map as M
3030
31−import Text.Hakyll.Context (ContextManipulation, renderDate)
31+import Text.Hakyll.Context (renderDate)
3232import Text.Hakyll.Hakyll (Hakyll, Context)
3333import Text.Hakyll.Render (render, renderChain)
3434import Text.Hakyll.Renderables (createListing)
src/Text/Hakyll/Internal/Render.hsdeleted−39
@@ -1,39 +0,0 @@
1−-- | Internal module do some low-level rendering.
2−module Text.Hakyll.Internal.Render
3− ( pureRender
4− , writePage
5− ) where
6−
7−import qualified Data.Map as M
8−import Control.Monad.Reader (liftIO)
9−import Data.Maybe (fromMaybe)
10−
11−import Text.Hakyll.File
12−import Text.Hakyll.Hakyll
13−import Text.Hakyll.HakyllAction
14−import Text.Hakyll.Internal.Template
15−
16−-- | A pure render function.
17−pureRender :: Template -- ^ Template to use for rendering.
18− -> Context -- ^ Renderable object to render with given template.
19− -> Context -- ^ The body of the result will contain the render.
20−pureRender template context =
21− -- Ignore $root when substituting here. We will only replace that in the
22− -- final render (just before writing).
23− let contextIgnoringRoot = M.insert "root" "$root" context
24− body = regularSubstitute template contextIgnoringRoot
25− in M.insert "body" body context
26−
27−-- | Write a page to the site destination. Final action after render
28−-- chains and such.
29−writePage :: HakyllAction Context ()
30−writePage = createHakyllAction $ \initialContext -> do
31− additionalContext' <- askHakyll getAdditionalContext
32− let url = fromMaybe (error "No url defined at write time.")
33− (M.lookup "url" initialContext)
34− body = fromMaybe "" (M.lookup "body" initialContext)
35− let context = additionalContext' `M.union` M.singleton "root" (toRoot url)
36− destination <- toDestination url
37− makeDirectories destination
38− -- Substitute $root here, just before writing.
39− liftIO $ writeFile destination $ finalSubstitute (fromString body) context
src/Text/Hakyll/Render.hs+27−3
@@ -14,12 +14,22 @@ import System.Directory (copyFile)
1414import Data.Maybe (fromMaybe)
1515import qualified Data.Map as M
1616
17−import Text.Hakyll.Hakyll (Hakyll, Context)
17+import Text.Hakyll.Hakyll (Hakyll, Context, askHakyll, getAdditionalContext)
1818import Text.Hakyll.File
1919import Text.Hakyll.HakyllAction
2020import Text.Hakyll.Internal.CompressCss
21−import Text.Hakyll.Internal.Render
22−import Text.Hakyll.Internal.Template (readTemplate)
21+import Text.Hakyll.Internal.Template
22+
23+-- | A pure render function.
24+pureRender :: Template -- ^ Template to use for rendering.
25+ -> Context -- ^ Renderable object to render with given template.
26+ -> Context -- ^ The body of the result will contain the render.
27+pureRender template context =
28+ -- Ignore $root when substituting here. We will only replace that in the
29+ -- final render (just before writing).
30+ let contextIgnoringRoot = M.insert "root" "$root" context
31+ body = regularSubstitute template contextIgnoringRoot
32+ in M.insert "body" body context
2333
2434-- | Render to a Page.
2535render :: FilePath -- ^ Template to use for rendering.
@@ -101,3 +111,17 @@ css source = runHakyllActionIfNeeded css'
101111 destination <- toDestination source
102112 makeDirectories destination
103113 liftIO $ writeFile destination (compressCss contents)
114+
115+-- | Write a page to the site destination. Final action after render
116+-- chains and such.
117+writePage :: HakyllAction Context ()
118+writePage = createHakyllAction $ \initialContext -> do
119+ additionalContext' <- askHakyll getAdditionalContext
120+ let url = fromMaybe (error "No url defined at write time.")
121+ (M.lookup "url" initialContext)
122+ body = fromMaybe "" (M.lookup "body" initialContext)
123+ let context = additionalContext' `M.union` M.singleton "root" (toRoot url)
124+ destination <- toDestination url
125+ makeDirectories destination
126+ -- Substitute $root here, just before writing.
127+ liftIO $ writeFile destination $ finalSubstitute (fromString body) context