on master help sign in
A bit of cleanup
commit25b8c8b199082ebbc41d1af03fc19202b798f156 authorJasper Van der Jeugt <m@jaspervdj.be> dateSun 25 Nov 2012, 10:45 (14 years ago) parentcae8789
9 files changed+43−75
hakyll.cabal+5−5 src/Hakyll/Core/Compiler/Internal.hs+2 src/Hakyll/Core/Compiler/Require.hs+12−1 src/Hakyll/Core/Configuration.hs+7−5 src/Hakyll/Core/Identifier.hs+2−25 src/Hakyll/Core/Identifier/Pattern.hs+2−1 src/Hakyll/Core/Rules/Internal.hs+6−9 src/Hakyll/Core/Runtime.hs+2−1 src/Hakyll/Core/Util/File.hs+5−28
hakyll.cabal+5−5
@@ -103,13 +103,9 @@ Library
103103 Hakyll.Core.Identifier
104104 Hakyll.Core.Identifier.Pattern
105105 Hakyll.Core.Item
106− Hakyll.Core.Logger
107106 Hakyll.Core.Metadata
108107 Hakyll.Core.Routes
109108 Hakyll.Core.Rules
110− Hakyll.Core.Runtime
111− Hakyll.Core.Store
112− Hakyll.Core.Util.File
113109 Hakyll.Core.Util.String
114110 Hakyll.Core.Writable
115111 Hakyll.Core.Writable.CopyFile
@@ -133,12 +129,16 @@ Library
133129 Hakyll.Core.Compiler.Internal
134130 Hakyll.Core.Compiler.Require
135131 Hakyll.Core.Item.SomeItem
132+ Hakyll.Core.Logger
136133 Hakyll.Core.Provider
137134 Hakyll.Core.Provider.Internal
138135 Hakyll.Core.Provider.Metadata
139136 Hakyll.Core.Provider.MetadataCache
140137 Hakyll.Core.Provider.Modified
141138 Hakyll.Core.Rules.Internal
139+ Hakyll.Core.Runtime
140+ Hakyll.Core.Store
141+ Hakyll.Core.Util.File
142142 Hakyll.Web.Template.Internal
143143 Paths_hakyll
144144
@@ -157,7 +157,7 @@ Library
157157 unix >= 2.4 && < 2.7
158158 Cpp-options:
159159 -DUNIX_FILTER
160− Other-modules:
160+ Exposed-modules:
161161 Hakyll.Core.UnixFilter
162162
163163Test-suite hakyll-tests
src/Hakyll/Core/Compiler/Internal.hs+2
@@ -82,6 +82,8 @@ data CompilerResult a where
8282
8383
8484--------------------------------------------------------------------------------
85+-- | A monad which lets you compile items and takes care of dependency tracking
86+-- for you.
8587newtype Compiler a = Compiler
8688 { unCompiler :: CompilerRead -> IO (CompilerResult a)
8789 }
src/Hakyll/Core/Compiler/Require.hs+12−1
@@ -30,6 +30,8 @@ import qualified Hakyll.Core.Store as Store
3030
3131
3232--------------------------------------------------------------------------------
33+-- | Whilst compiling an item, it possible to save multiple snapshots of it, and
34+-- not just the final result.
3335type Snapshot = String
3436
3537
@@ -39,6 +41,8 @@ save store item = saveSnapshot store final item
3941
4042
4143--------------------------------------------------------------------------------
44+-- | Save a specific snapshot of an item, so you can load it later using
45+-- 'requireSnapshot'.
4246saveSnapshot :: (Binary a, Typeable a)
4347 => Store -> Snapshot -> Item a -> IO ()
4448saveSnapshot store snapshot item =
@@ -46,11 +50,14 @@ saveSnapshot store snapshot item =
4650
4751
4852--------------------------------------------------------------------------------
53+-- | Load an item compiled elsewhere. If the required item is not yet compiled,
54+-- the build system will take care of that automatically.
4955require :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
5056require id' = requireSnapshot id' final
5157
5258
5359--------------------------------------------------------------------------------
60+-- | Require a specific snapshot of an item.
5461requireSnapshot :: (Binary a, Typeable a)
5562 => Identifier -> Snapshot -> Compiler (Item a)
5663requireSnapshot id' snapshot = do
@@ -77,6 +84,9 @@ requireSnapshot id' snapshot = do
7784
7885
7986--------------------------------------------------------------------------------
87+-- | A shortcut for only requiring the body of an item.
88+--
89+-- > requireBody = fmap itemBody . require
8090requireBody :: (Binary a, Typeable a) => Identifier -> Compiler a
8191requireBody id' = requireSnapshotBody id' final
8292
@@ -88,6 +98,7 @@ requireSnapshotBody id' snapshot = fmap itemBody $ requireSnapshot id' snapshot
8898
8999
90100--------------------------------------------------------------------------------
101+-- | This function allows you to 'require' a dynamic list of items
91102requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
92103requireAll pattern = requireAllSnapshots pattern final
93104
@@ -108,4 +119,4 @@ key identifier snapshot =
108119
109120--------------------------------------------------------------------------------
110121final :: Snapshot
111−final = "final"
122+final = "_final"
src/Hakyll/Core/Configuration.hs+7−5
@@ -9,7 +9,7 @@ module Hakyll.Core.Configuration
99
1010--------------------------------------------------------------------------------
1111import Data.List (isPrefixOf, isSuffixOf)
12−import System.FilePath (takeFileName)
12+import System.FilePath (normalise, takeFileName)
1313
1414
1515--------------------------------------------------------------------------------
@@ -79,7 +79,7 @@ defaultConfiguration = Configuration
7979 | "#" `isPrefixOf` fileName = True
8080 | "~" `isSuffixOf` fileName = True
8181 | ".swp" `isSuffixOf` fileName = True
82− | otherwise = False
82+ | otherwise = False
8383 where
8484 fileName = takeFileName path
8585
@@ -88,6 +88,8 @@ defaultConfiguration = Configuration
8888-- | Check if a file should be ignored
8989shouldIgnoreFile :: Configuration -> FilePath -> Bool
9090shouldIgnoreFile conf path =
91− destinationDirectory conf `isPrefixOf` path ||
92− storeDirectory conf `isPrefixOf` path ||
93− ignoreFile conf path
91+ destinationDirectory conf `isPrefixOf` path' ||
92+ storeDirectory conf `isPrefixOf` path' ||
93+ ignoreFile conf path'
94+ where
95+ path' = normalise path
src/Hakyll/Core/Identifier.hs+2−25
@@ -1,34 +1,12 @@
11--------------------------------------------------------------------------------
2−-- | An identifier is a type used to uniquely identify a resource, target...
3−--
4−-- One can think of an identifier as something similar to a file path. An
5−-- identifier is a path as well, with the different elements in the path
6−-- separated by @/@ characters. Examples of identifiers are:
2+-- | An identifier is a type used to uniquely identify an item. An identifier is
3+-- conceptually similar to a file path. Examples of identifiers are:
74--
85-- * @posts/foo.markdown@
96--
107-- * @index@
118--
129-- * @error/404@
13−--
14−-- The most important difference between an 'Identifier' and a file path is that
15−-- the identifier for an item is not necesserily the file path.
16−--
17−-- For example, we could have an @index@ identifier, generated by Hakyll. The
18−-- actual file path would be @index.html@, but we identify it using @index@.
19−--
20−-- @posts/foo.markdown@ could be an identifier of an item that is rendered to
21−-- @posts/foo.html@. In this case, the identifier is the name of the source
22−-- file of the page.
23−--
24−-- An `Identifier` carries the type of the value it identifies. This basically
25−-- means that an @Identifier (Page String)@ refers to a page.
26−--
27−-- It is a phantom type parameter, meaning you can safely change this if you
28−-- know what you are doing. You can change the type using the 'castIdentifier'
29−-- function.
30−--
31−-- If the @a@ type is not known, Hakyll traditionally uses @Identifier ()@.
3210{-# LANGUAGE DeriveDataTypeable #-}
3311{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3412module Hakyll.Core.Identifier
@@ -54,7 +32,6 @@ import GHC.Exts (IsString, fromString)
5432
5533
5634--------------------------------------------------------------------------------
57−-- | An identifier used to uniquely identify a value
5835data Identifier = Identifier
5936 { identifierVersion :: Maybe String
6037 , identifierPath :: String
src/Hakyll/Core/Identifier/Pattern.hs+2−1
@@ -149,7 +149,7 @@ instance Monoid Pattern where
149149
150150
151151--------------------------------------------------------------------------------
152−-- | THis is necessary for good 'isLiteral' results
152+-- | This is necessary for good 'isLiteral' results
153153optimize :: Pattern -> Pattern
154154optimize (Complement x) = Complement (optimize x)
155155optimize (And x Everything) = x
@@ -189,6 +189,7 @@ fromRegex = Regex
189189
190190
191191--------------------------------------------------------------------------------
192+-- | Create a pattern which matches all items with the given version.
192193fromVersion :: Maybe String -> Pattern
193194fromVersion = Version
194195
src/Hakyll/Core/Rules/Internal.hs+6−9
@@ -1,10 +1,9 @@
11--------------------------------------------------------------------------------
2−-- | Internal rules module for types which are not exposed to the user
32{-# LANGUAGE GeneralizedNewtypeDeriving #-}
43{-# LANGUAGE Rank2Types #-}
54module Hakyll.Core.Rules.Internal
65 ( RuleSet (..)
7− , RuleEnvironment (..)
6+ , RulesRead (..)
87 , Rules (..)
98 , runRules
109 ) where
@@ -31,11 +30,10 @@ import Hakyll.Core.Routes
3130
3231
3332--------------------------------------------------------------------------------
34−-- | A collection of rules for the compilation process
3533data RuleSet = RuleSet
36− { -- | Routes used in the compilation structure
34+ { -- | Accumulated routes
3735 rulesRoutes :: Routes
38− , -- | Compilation rules
36+ , -- | Accumulated compilers
3937 rulesCompilers :: [(Identifier, Compiler SomeItem)]
4038 , -- | A set of the actually used files
4139 rulesResources :: Set Identifier
@@ -50,8 +48,7 @@ instance Monoid RuleSet where
5048
5149
5250--------------------------------------------------------------------------------
53−-- | Rule environment
54−data RuleEnvironment = RuleEnvironment
51+data RulesRead = RulesRead
5552 { rulesProvider :: Provider
5653 , rulesPattern :: Pattern
5754 , rulesVersion :: Maybe String
@@ -61,7 +58,7 @@ data RuleEnvironment = RuleEnvironment
6158--------------------------------------------------------------------------------
6259-- | The monad used to compose rules
6360newtype Rules a = Rules
64− { unRules :: RWST RuleEnvironment RuleSet () IO a
61+ { unRules :: RWST RulesRead RuleSet () IO a
6562 } deriving (Monad, Functor, Applicative)
6663
6764
@@ -83,7 +80,7 @@ runRules rules provider = do
8380 (_, _, ruleSet) <- runRWST (unRules rules) env ()
8481 return $ nubCompilers ruleSet
8582 where
86− env = RuleEnvironment
83+ env = RulesRead
8784 { rulesProvider = provider
8885 , rulesPattern = mempty
8986 , rulesVersion = Nothing
src/Hakyll/Core/Runtime.hs+2−1
@@ -48,7 +48,8 @@ run config rules = do
4848 Logger.message logger "Creating store..."
4949 store <- Store.new (inMemoryCache config) $ storeDirectory config
5050 Logger.message logger "Creating provider..."
51− provider <- newProvider store (ignoreFile config) $ providerDirectory config
51+ provider <- newProvider store (shouldIgnoreFile config) $
52+ providerDirectory config
5253 Logger.message logger "Running rules..."
5354 ruleSet <- runRules rules provider
5455
src/Hakyll/Core/Util/File.hs+5−28
@@ -3,23 +3,15 @@
33module Hakyll.Core.Util.File
44 ( makeDirectories
55 , getRecursiveContents
6− , isFileInternal
76 ) where
87
98
109--------------------------------------------------------------------------------
11−import Control.Applicative ((<$>))
12−import Control.Monad (forM)
13−import Data.List (isPrefixOf)
14−import System.Directory (createDirectoryIfMissing,
15− doesDirectoryExist,
16− getDirectoryContents)
17−import System.FilePath (dropTrailingPathSeparator,
18− splitPath, takeDirectory, (</>))
19−
20−
21−--------------------------------------------------------------------------------
22−import Hakyll.Core.Configuration
10+import Control.Applicative ((<$>))
11+import Control.Monad (forM)
12+import System.Directory (createDirectoryIfMissing,
13+ doesDirectoryExist, getDirectoryContents)
14+import System.FilePath (takeDirectory, (</>))
2315
2416
2517--------------------------------------------------------------------------------
@@ -50,18 +42,3 @@ getRecursiveContents top = go ""
5042 else return [rel]
5143
5244 return $ concat paths
53−
54−
55−--------------------------------------------------------------------------------
56−-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in
57−-- the destination or store directory
58−isFileInternal :: Configuration -- ^ Configuration
59− -> FilePath -- ^ File to check
60− -> Bool -- ^ If the given file is internal
61−isFileInternal configuration file =
62− any (`isPrefixOf` split file) dirs
63− where
64− split = map dropTrailingPathSeparator . splitPath
65− dirs = map (split . ($ configuration)) [ destinationDirectory
66− , storeDirectory
67− ]