on master help sign in
Add WritableTuple
21789abJasper Van der Jeugt
src/Hakyll.hs+4−2
@@ -2,7 +2,6 @@
2--
2--
3module Hakyll
3module Hakyll
4 ( module Hakyll.Core.Compiler
4 ( module Hakyll.Core.Compiler
5− , module Hakyll.Core.CopyFile
6 , module Hakyll.Core.Configuration
5 , module Hakyll.Core.Configuration
7 , module Hakyll.Core.Identifier
6 , module Hakyll.Core.Identifier
8 , module Hakyll.Core.Identifier.Pattern
7 , module Hakyll.Core.Identifier.Pattern
@@ -14,6 +13,8 @@ module Hakyll
14 , module Hakyll.Core.Util.File
13 , module Hakyll.Core.Util.File
15 , module Hakyll.Core.Util.String
14 , module Hakyll.Core.Util.String
16 , module Hakyll.Core.Writable
15 , module Hakyll.Core.Writable
16+ , module Hakyll.Core.Writable.CopyFile
17+ , module Hakyll.Core.Writable.WritableTuple
17 , module Hakyll.Main
18 , module Hakyll.Main
18 , module Hakyll.Web.CompressCss
19 , module Hakyll.Web.CompressCss
19 , module Hakyll.Web.Feed
20 , module Hakyll.Web.Feed
@@ -29,7 +30,6 @@ module Hakyll
29 ) where
30 ) where
30
31
31import Hakyll.Core.Compiler
32import Hakyll.Core.Compiler
32−import Hakyll.Core.CopyFile
33import Hakyll.Core.Configuration
33import Hakyll.Core.Configuration
34import Hakyll.Core.Identifier
34import Hakyll.Core.Identifier
35import Hakyll.Core.Identifier.Pattern
35import Hakyll.Core.Identifier.Pattern
@@ -41,6 +41,8 @@ import Hakyll.Core.Util.Arrow
41import Hakyll.Core.Util.File
41import Hakyll.Core.Util.File
42import Hakyll.Core.Util.String
42import Hakyll.Core.Util.String
43import Hakyll.Core.Writable
43import Hakyll.Core.Writable
44+import Hakyll.Core.Writable.CopyFile
45+import Hakyll.Core.Writable.WritableTuple
44import Hakyll.Main
46import Hakyll.Main
45import Hakyll.Web.CompressCss
47import Hakyll.Web.CompressCss
46import Hakyll.Web.Feed
48import Hakyll.Web.Feed
src/Hakyll/Core/CompiledItem.hs+3−2
@@ -15,7 +15,7 @@ module Hakyll.Core.CompiledItem
15 ) where
15 ) where
16
16
17import Data.Binary (Binary)
17import Data.Binary (Binary)
18−import Data.Typeable (Typeable, cast)
18+import Data.Typeable (Typeable, cast, typeOf)
19import Data.Maybe (fromMaybe)
19import Data.Maybe (fromMaybe)
20
20
21import Hakyll.Core.Writable
21import Hakyll.Core.Writable
@@ -42,4 +42,5 @@ unCompiledItem :: (Binary a, Typeable a, Writable a)
42 -> a
42 -> a
43unCompiledItem (CompiledItem x) = fromMaybe error' $ cast x
43unCompiledItem (CompiledItem x) = fromMaybe error' $ cast x
44 where
44 where
45− error' = error "Hakyll.Core.CompiledItem.unCompiledItem: Unsupported type"
45+ error' = error $ "Hakyll.Core.CompiledItem.unCompiledItem: "
46+ ++ "unsupported type (got " ++ show (typeOf x) ++ ")"
src/Hakyll/Core/CopyFile.hs → src/Hakyll/Core/Writable/CopyFile.hsrenamed+1−1
@@ -1,7 +1,7 @@
1-- | Exports simple compilers to just copy files
1-- | Exports simple compilers to just copy files
2--
2--
3{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
4−module Hakyll.Core.CopyFile
4+module Hakyll.Core.Writable.CopyFile
5 ( CopyFile (..)
5 ( CopyFile (..)
6 , copyFileCompiler
6 , copyFileCompiler
7 ) where
7 ) where
src/Hakyll/Core/Writable/WritableTuple.hsnew file+37
@@ -0,0 +1,37 @@
1+-- | This module exposes a writable type 'WritableTuple' which is a simple
2+-- newtype wrapper around a tuple.
3+--
4+-- The idea is that, given a tuple @(a, b)@, @a@ is the value you actually want
5+-- to save to the disk, and @b@ is some additional info that you /don't/ want to
6+-- save, but that you need later, for example in a 'require' clause.
7+--
8+{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
9+module Hakyll.Core.Writable.WritableTuple
10+ ( WritableTuple (..)
11+ , writableTupleFst
12+ , writableTupleSnd
13+ , writableTupleCompiler
14+ ) where
15+
16+import Control.Arrow (arr)
17+
18+import Data.Typeable (Typeable)
19+import Data.Binary (Binary)
20+
21+import Hakyll.Core.Writable
22+import Hakyll.Core.Compiler
23+
24+newtype WritableTuple a b = WritableTuple {unWritableTuple :: (a, b)}
25+ deriving (Show, Eq, Ord, Binary, Typeable)
26+
27+instance Writable a => Writable (WritableTuple a b) where
28+ write dst (WritableTuple (x, _)) = write dst x
29+
30+writableTupleFst :: WritableTuple a b -> a
31+writableTupleFst = fst . unWritableTuple
32+
33+writableTupleSnd :: WritableTuple a b -> b
34+writableTupleSnd = snd . unWritableTuple
35+
36+writableTupleCompiler :: Compiler (a, b) (WritableTuple a b)
37+writableTupleCompiler = arr WritableTuple