summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-02 20:37:34 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-02 20:37:34 +0100
commit21789abd101a738639c957d5701a514860b63ee2 (patch)
treea1ba8f5bbf685add787cb6d863ad222679d65c4b
parent38effae07a6df36a41b55f2b5427fcdd8ef31b14 (diff)
downloadhakyll-21789abd101a738639c957d5701a514860b63ee2.tar.gz
Add WritableTuple
-rw-r--r--src/Hakyll.hs6
-rw-r--r--src/Hakyll/Core/CompiledItem.hs5
-rw-r--r--src/Hakyll/Core/Writable/CopyFile.hs (renamed from src/Hakyll/Core/CopyFile.hs)2
-rw-r--r--src/Hakyll/Core/Writable/WritableTuple.hs37
4 files changed, 45 insertions, 5 deletions
diff --git a/src/Hakyll.hs b/src/Hakyll.hs
index 0261044..dbc67f3 100644
--- a/src/Hakyll.hs
+++ b/src/Hakyll.hs
@@ -2,7 +2,6 @@
--
module Hakyll
( module Hakyll.Core.Compiler
- , module Hakyll.Core.CopyFile
, module Hakyll.Core.Configuration
, module Hakyll.Core.Identifier
, module Hakyll.Core.Identifier.Pattern
@@ -14,6 +13,8 @@ module Hakyll
, module Hakyll.Core.Util.File
, module Hakyll.Core.Util.String
, module Hakyll.Core.Writable
+ , module Hakyll.Core.Writable.CopyFile
+ , module Hakyll.Core.Writable.WritableTuple
, module Hakyll.Main
, module Hakyll.Web.CompressCss
, module Hakyll.Web.Feed
@@ -29,7 +30,6 @@ module Hakyll
) where
import Hakyll.Core.Compiler
-import Hakyll.Core.CopyFile
import Hakyll.Core.Configuration
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
@@ -41,6 +41,8 @@ import Hakyll.Core.Util.Arrow
import Hakyll.Core.Util.File
import Hakyll.Core.Util.String
import Hakyll.Core.Writable
+import Hakyll.Core.Writable.CopyFile
+import Hakyll.Core.Writable.WritableTuple
import Hakyll.Main
import Hakyll.Web.CompressCss
import Hakyll.Web.Feed
diff --git a/src/Hakyll/Core/CompiledItem.hs b/src/Hakyll/Core/CompiledItem.hs
index 5dd0efc..2e492a2 100644
--- a/src/Hakyll/Core/CompiledItem.hs
+++ b/src/Hakyll/Core/CompiledItem.hs
@@ -15,7 +15,7 @@ module Hakyll.Core.CompiledItem
) where
import Data.Binary (Binary)
-import Data.Typeable (Typeable, cast)
+import Data.Typeable (Typeable, cast, typeOf)
import Data.Maybe (fromMaybe)
import Hakyll.Core.Writable
@@ -42,4 +42,5 @@ unCompiledItem :: (Binary a, Typeable a, Writable a)
-> a
unCompiledItem (CompiledItem x) = fromMaybe error' $ cast x
where
- error' = error "Hakyll.Core.CompiledItem.unCompiledItem: Unsupported type"
+ error' = error $ "Hakyll.Core.CompiledItem.unCompiledItem: "
+ ++ "unsupported type (got " ++ show (typeOf x) ++ ")"
diff --git a/src/Hakyll/Core/CopyFile.hs b/src/Hakyll/Core/Writable/CopyFile.hs
index dbbaaa1..1cd5fd2 100644
--- a/src/Hakyll/Core/CopyFile.hs
+++ b/src/Hakyll/Core/Writable/CopyFile.hs
@@ -1,7 +1,7 @@
-- | Exports simple compilers to just copy files
--
{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
-module Hakyll.Core.CopyFile
+module Hakyll.Core.Writable.CopyFile
( CopyFile (..)
, copyFileCompiler
) where
diff --git a/src/Hakyll/Core/Writable/WritableTuple.hs b/src/Hakyll/Core/Writable/WritableTuple.hs
new file mode 100644
index 0000000..741d2c7
--- /dev/null
+++ b/src/Hakyll/Core/Writable/WritableTuple.hs
@@ -0,0 +1,37 @@
+-- | This module exposes a writable type 'WritableTuple' which is a simple
+-- newtype wrapper around a tuple.
+--
+-- The idea is that, given a tuple @(a, b)@, @a@ is the value you actually want
+-- to save to the disk, and @b@ is some additional info that you /don't/ want to
+-- save, but that you need later, for example in a 'require' clause.
+--
+{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
+module Hakyll.Core.Writable.WritableTuple
+ ( WritableTuple (..)
+ , writableTupleFst
+ , writableTupleSnd
+ , writableTupleCompiler
+ ) where
+
+import Control.Arrow (arr)
+
+import Data.Typeable (Typeable)
+import Data.Binary (Binary)
+
+import Hakyll.Core.Writable
+import Hakyll.Core.Compiler
+
+newtype WritableTuple a b = WritableTuple {unWritableTuple :: (a, b)}
+ deriving (Show, Eq, Ord, Binary, Typeable)
+
+instance Writable a => Writable (WritableTuple a b) where
+ write dst (WritableTuple (x, _)) = write dst x
+
+writableTupleFst :: WritableTuple a b -> a
+writableTupleFst = fst . unWritableTuple
+
+writableTupleSnd :: WritableTuple a b -> b
+writableTupleSnd = snd . unWritableTuple
+
+writableTupleCompiler :: Compiler (a, b) (WritableTuple a b)
+writableTupleCompiler = arr WritableTuple