summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/RenderAction.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-05 12:22:09 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-05 12:22:09 +0100
commit664111c00178039c5a68f62da7612fb04b25927c (patch)
treec74fbca0bdec6ad5c324884b826e82b044f4b3d0 /src/Text/Hakyll/RenderAction.hs
parentcd51ba5789243d47b1bb0701c563eef8be6e1d8e (diff)
downloadhakyll-664111c00178039c5a68f62da7612fb04b25927c.tar.gz
Simplified css and static code.
Diffstat (limited to 'src/Text/Hakyll/RenderAction.hs')
-rw-r--r--src/Text/Hakyll/RenderAction.hs28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/Text/Hakyll/RenderAction.hs b/src/Text/Hakyll/RenderAction.hs
index 9fb9477..b84a3c5 100644
--- a/src/Text/Hakyll/RenderAction.hs
+++ b/src/Text/Hakyll/RenderAction.hs
@@ -2,17 +2,22 @@ module Text.Hakyll.RenderAction
( RenderAction (..)
, createRenderAction
, createSimpleRenderAction
+ , createFileRenderAction
, createManipulationAction
, chain
, runRenderAction
+ , runRenderActionIfNeeded
) where
-import Prelude hiding ((.), id)
import Control.Category
-import Control.Monad ((<=<), mplus)
+import Control.Monad ((<=<), mplus, unless)
+import Control.Monad.Reader (liftIO)
+import Prelude hiding ((.), id)
+import System.IO (hPutStrLn, stderr)
-import Text.Hakyll.Hakyll
import Text.Hakyll.Context
+import Text.Hakyll.File (toDestination, isFileMoreRecent)
+import Text.Hakyll.Hakyll
data RenderAction a b = RenderAction
{ actionDependencies :: [FilePath]
@@ -26,6 +31,13 @@ createRenderAction f = id { actionFunction = f }
createSimpleRenderAction :: Hakyll b -> RenderAction () b
createSimpleRenderAction = createRenderAction . const
+createFileRenderAction :: FilePath -> Hakyll b -> RenderAction () b
+createFileRenderAction path action = RenderAction
+ { actionDependencies = [path]
+ , actionUrl = Just $ return path
+ , actionFunction = const action
+ }
+
instance Category RenderAction where
id = RenderAction
{ actionDependencies = []
@@ -47,3 +59,13 @@ chain = foldl1 (>>>)
runRenderAction :: RenderAction () a -> Hakyll a
runRenderAction action = actionFunction action ()
+
+runRenderActionIfNeeded :: RenderAction () () -> Hakyll ()
+runRenderActionIfNeeded action = do
+ url <- case actionUrl action of
+ (Just u) -> u
+ Nothing -> error "No url when checking dependencies."
+ destination <- toDestination url
+ valid <- isFileMoreRecent destination $ actionDependencies action
+ unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination
+ runRenderAction action