on master help sign in
Add create in addition to match
commit18b6ac5ad42e50e75b9ee9fcfc8aef00f5a00957 authorJasper Van der Jeugt <m@jaspervdj.be> dateSun 6 Jan 2013, 09:51 (14 years ago) parent6b7fbad
7 files changed+30−39
src/Hakyll/Core/Identifier/Pattern.hs−14 src/Hakyll/Core/Rules.hs+23−6 src/Hakyll/Core/Rules/Internal.hs+2−2 src/Hakyll/Web/Tags.hs+1−1 tests/Hakyll/Core/Identifier/Tests.hs+1−12 tests/Hakyll/Core/Runtime/Tests.hs+1−1 web/site.hs+2−3
src/Hakyll/Core/Identifier/Pattern.hs−14
@@ -44,7 +44,6 @@ module Hakyll.Core.Identifier.Pattern
4444 , complement
4545 , withVersion
4646 , noVersion
47− , fromLiteral
4847
4948 -- * Applying patterns
5049 , matches
@@ -234,19 +233,6 @@ noVersion :: Pattern -> Pattern
234233noVersion p = optimize $ And p $ fromVersion Nothing
235234
236235
237−--------------------------------------------------------------------------------
238−-- | Check if a pattern is a literal. @\"*.markdown\"@ is not a literal but
239−-- @\"posts.markdown\"@ is.
240−fromLiteral :: Pattern -> Maybe Identifier
241−fromLiteral pattern = case pattern of
242− Glob p -> fmap fromFilePath $ foldr fromLiteral' (Just "") p
243− _ -> Nothing
244− where
245− fromLiteral' (Literal x) (Just y) = Just $ x ++ y
246− fromLiteral' _ _ = Nothing
247−
248−
249−
250236--------------------------------------------------------------------------------
251237-- | Check if an identifier matches a pattern
252238matches :: Pattern -> Identifier -> Bool
src/Hakyll/Core/Rules.hs+23−6
@@ -19,6 +19,7 @@
1919module Hakyll.Core.Rules
2020 ( Rules
2121 , match
22+ , create
2223 , version
2324 , compile
2425 , route
@@ -34,7 +35,7 @@ import Control.Monad.Reader (ask, local)
3435import Control.Monad.State (get, modify, put)
3536import Control.Monad.Writer (censor, tell)
3637import Data.Maybe (fromMaybe)
37−import Data.Monoid (mappend, mempty)
38+import Data.Monoid (mempty)
3839import qualified Data.Set as S
3940
4041
@@ -82,15 +83,21 @@ flush = Rules $ do
8283 case mcompiler of
8384 Nothing -> return ()
8485 Just compiler -> do
85− pattern <- rulesPattern <$> ask
86+ matches' <- rulesMatches <$> ask
8687 version' <- rulesVersion <$> ask
8788 route' <- fromMaybe mempty . rulesRoute <$> get
89+
90+ -- The version is possibly not set correctly at this point (yet)
91+ let ids = map (setVersion version') matches'
92+
93+ {-
8894 ids <- case fromLiteral pattern of
8995 Just id' -> return [setVersion version' id']
9096 Nothing -> do
9197 ids <- unRules $ getMatches pattern
9298 unRules $ tellResources ids
9399 return $ map (setVersion version') ids
100+ -}
94101
95102 -- Create a fast pattern for routing that matches exactly the
96103 -- compilers created in the block given to match
@@ -107,11 +114,21 @@ flush = Rules $ do
107114match :: Pattern -> Rules () -> Rules ()
108115match pattern rules = do
109116 flush
110− Rules $ local addPattern $ unRules $ rules >> flush
117+ ids <- getMatches pattern
118+ tellResources ids
119+ Rules $ local (setMatches ids) $ unRules $ rules >> flush
111120 where
112− addPattern env = env
113− { rulesPattern = rulesPattern env `mappend` pattern
114− }
121+ setMatches ids env = env {rulesMatches = ids}
122+
123+
124+--------------------------------------------------------------------------------
125+create :: [Identifier] -> Rules () -> Rules ()
126+create ids rules = do
127+ flush
128+ -- TODO Maybe check if the resources exist and call tellResources on that
129+ Rules $ local setMatches $ unRules $ rules >> flush
130+ where
131+ setMatches env = env {rulesMatches = ids}
115132
116133
117134--------------------------------------------------------------------------------
src/Hakyll/Core/Rules/Internal.hs+2−2
@@ -34,7 +34,7 @@ import Hakyll.Core.Routes
3434--------------------------------------------------------------------------------
3535data RulesRead = RulesRead
3636 { rulesProvider :: Provider
37− , rulesPattern :: Pattern
37+ , rulesMatches :: [Identifier]
3838 , rulesVersion :: Maybe String
3939 }
4040
@@ -96,7 +96,7 @@ runRules rules provider = do
9696 where
9797 env = RulesRead
9898 { rulesProvider = provider
99− , rulesPattern = mempty
99+ , rulesMatches = []
100100 , rulesVersion = Nothing
101101 }
102102
src/Hakyll/Web/Tags.hs+1−1
@@ -143,7 +143,7 @@ buildCategories = buildTagsWith getCategory
143143tagsRules :: Tags -> (String -> Pattern -> Rules ()) -> Rules ()
144144tagsRules tags rules =
145145 forM_ (tagsMap tags) $ \(tag, identifiers) ->
146− match (fromGlob $ toFilePath $ tagsMakeId tags tag) $
146+ create [tagsMakeId tags tag] $
147147 rulesExtraDependencies [tagsDependency tags] $
148148 rules tag $ fromList identifiers
149149
tests/Hakyll/Core/Identifier/Tests.hs+1−12
@@ -6,7 +6,6 @@ module Hakyll.Core.Identifier.Tests
66
77
88--------------------------------------------------------------------------------
9−import Data.Monoid (mappend, mempty)
109import Test.Framework (Test, testGroup)
1110import Test.HUnit ((@=?))
1211
@@ -20,21 +19,11 @@ import TestSuite.Util
2019--------------------------------------------------------------------------------
2120tests :: Test
2221tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
23− [ isLiteralTests
24− , captureTests
22+ [ captureTests
2523 , matchesTests
2624 ]
2725
2826
29−--------------------------------------------------------------------------------
30−isLiteralTests :: [Test]
31−isLiteralTests = fromAssertions "isLiteral"
32− [ Just "index.html" @=? fromLiteral "index.html"
33− , Nothing @=? fromLiteral "posts/*.markdown"
34− , Just "test.txt" @=? fromLiteral ("test.txt" `mappend` mempty)
35− ]
36−
37−
3827--------------------------------------------------------------------------------
3928captureTests :: [Test]
4029captureTests = fromAssertions "capture"
tests/Hakyll/Core/Runtime/Tests.hs+1−1
@@ -34,7 +34,7 @@ case01 = withTestConfiguration $ \config -> do
3434 >>= saveSnapshot "raw"
3535 >>= return . renderPandoc
3636
37− match "bodies.txt" $ do
37+ create ["bodies.txt"] $ do
3838 route idRoute
3939 compile $ do
4040 items <- loadAllSnapshots "*.md" "raw"
web/site.hs+2−3
@@ -48,7 +48,7 @@ main = hakyllWith config $ do
4848 >>= relativizeUrls
4949
5050 -- Tutorial list
51− match "tutorials.html" $ do
51+ create ["tutorials.html"] $ do
5252 route idRoute
5353 compile $ do
5454 tutorials <- loadAll "tutorials/*"
@@ -79,8 +79,7 @@ main = hakyllWith config $ do
7979--------------------------------------------------------------------------------
8080config :: Configuration
8181config = defaultConfiguration
82− { verbosity = Debug
83− , deployCommand = "rsync --checksum -ave 'ssh -p 2222' \
82+ { deployCommand = "rsync --checksum -ave 'ssh -p 2222' \
8483 \_site/* jaspervdj@jaspervdj.be:jaspervdj.be/tmp/hakyll4"
8584 }
8685