on master help sign in
Merge branch 'master' into dev-metadata-route
4c40ceaJasper Van der Jeugt
hakyll.cabal+2−1
@@ -64,10 +64,11 @@ Data-files:
64Extra-source-files:
64Extra-source-files:
65 tests/data/example.md
65 tests/data/example.md
66 tests/data/example.md.metadata
66 tests/data/example.md.metadata
67+ tests/data/images/favicon.ico
68+ tests/data/posts/2010-08-26-birthday.md
67 tests/data/russian.md
69 tests/data/russian.md
68 tests/data/template.html
70 tests/data/template.html
69 tests/data/template.html.out
71 tests/data/template.html.out
70− tests/data/posts/2010-08-26-birthday.md
71
72
72Source-Repository head
73Source-Repository head
73 Type: git
74 Type: git
src/Hakyll/Core/Rules/Internal.hs+8−16
@@ -16,9 +16,9 @@ import Control.Applicative (Applicative, (<$>))
16import Control.Monad.Reader (ask)
16import Control.Monad.Reader (ask)
17import Control.Monad.RWS (RWST, runRWST)
17import Control.Monad.RWS (RWST, runRWST)
18import Control.Monad.Trans (liftIO)
18import Control.Monad.Trans (liftIO)
19+import qualified Data.Map as M
19import Data.Monoid (Monoid, mappend, mempty)
20import Data.Monoid (Monoid, mappend, mempty)
20import Data.Set (Set)
21import Data.Set (Set)
21−import qualified Data.Set as S
22
22
23
23
24--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
@@ -92,25 +92,17 @@ instance MonadMetadata Rules where
92runRules :: Rules a -> Provider -> IO RuleSet
92runRules :: Rules a -> Provider -> IO RuleSet
93runRules rules provider = do
93runRules rules provider = do
94 (_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
94 (_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
95− case findDuplicate (map fst $ rulesCompilers ruleSet) of
96− Nothing -> return ruleSet
97− Just id' -> error $
98− "Hakyll.Core.Rules.Internal: two different rules for " ++
99− show id' ++ " exist, bailing out"
100
95
96+ -- Ensure compiler uniqueness
97+ let ruleSet' = ruleSet
98+ { rulesCompilers = M.toList $
99+ M.fromListWith (flip const) (rulesCompilers ruleSet)
100+ }
101+
102+ return ruleSet'
101 where
103 where
102 env = RulesRead
104 env = RulesRead
103 { rulesProvider = provider
105 { rulesProvider = provider
104 , rulesMatches = []
106 , rulesMatches = []
105 , rulesVersion = Nothing
107 , rulesVersion = Nothing
106 }
108 }
107−
108−
109−--------------------------------------------------------------------------------
110−findDuplicate :: Ord a => [a] -> Maybe a
111−findDuplicate = go S.empty
112− where
113− go _ [] = Nothing
114− go s (x : xs)
115− | x `S.member` s = Just x
116− | otherwise = go (S.insert x s) xs
tests/Hakyll/Core/Rules/Tests.hs+7−9
@@ -10,7 +10,6 @@ import Data.IORef (IORef, newIORef, readIORef,
10 writeIORef)
10 writeIORef)
11import qualified Data.Set as S
11import qualified Data.Set as S
12import Test.Framework (Test, testGroup)
12import Test.Framework (Test, testGroup)
13−import Test.Framework.Providers.HUnit (testCase)
14import Test.HUnit (Assertion, assert, (@=?))
13import Test.HUnit (Assertion, assert, (@=?))
15
14
16
15
@@ -28,18 +27,17 @@ import TestSuite.Util
28
27
29--------------------------------------------------------------------------------
28--------------------------------------------------------------------------------
30tests :: Test
29tests :: Test
31−tests = testGroup "Hakyll.Core.Rules.Tests"
30+tests = testGroup "Hakyll.Core.Rules.Tests" $ fromAssertions "runRules"
32− [ testCase "runRules" rulesTest
31+ [case01]
33− ]
34
32
35
33
36--------------------------------------------------------------------------------
34--------------------------------------------------------------------------------
37−rulesTest :: Assertion
35+case01 :: Assertion
38−rulesTest = do
36+case01 = do
39 ioref <- newIORef False
37 ioref <- newIORef False
40 store <- newTestStore
38 store <- newTestStore
41 provider <- newTestProvider store
39 provider <- newTestProvider store
42− ruleSet <- runRules (rules ioref) provider
40+ ruleSet <- runRules (rules01 ioref) provider
43 let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
41 let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
44 routes = rulesRoutes ruleSet
42 routes = rulesRoutes ruleSet
45 checkRoute ex i =
43 checkRoute ex i =
@@ -66,8 +64,8 @@ rulesTest = do
66
64
67
65
68--------------------------------------------------------------------------------
66--------------------------------------------------------------------------------
69−rules :: IORef Bool -> Rules ()
67+rules01 :: IORef Bool -> Rules ()
70−rules ioref = do
68+rules01 ioref = do
71 -- Compile some posts
69 -- Compile some posts
72 match "*.md" $ do
70 match "*.md" $ do
73 route $ setExtension "html"
71 route $ setExtension "html"
tests/Hakyll/Core/Runtime/Tests.hs+21−1
@@ -20,7 +20,8 @@ import TestSuite.Util
20
20
21--------------------------------------------------------------------------------
21--------------------------------------------------------------------------------
22tests :: Test
22tests :: Test
23−tests = testGroup "Hakyll.Core.Runtime.Tests" $ fromAssertions "run" [case01]
23+tests = testGroup "Hakyll.Core.Runtime.Tests" $
24+ fromAssertions "run" [case01, case02]
24
25
25
26
26--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
@@ -48,3 +49,22 @@ case01 = do
48 head (lines bodies) @?= "This is an example."
49 head (lines bodies) @?= "This is an example."
49
50
50 cleanTestEnv
51 cleanTestEnv
52+
53+
54+--------------------------------------------------------------------------------
55+case02 :: Assertion
56+case02 = do
57+ _ <- run testConfiguration Logger.Error $ do
58+ match "images/favicon.ico" $ do
59+ route $ gsubRoute "images/" (const "")
60+ compile $ makeItem ("Test" :: String)
61+
62+ match "images/**" $ do
63+ route idRoute
64+ compile copyFileCompiler
65+
66+ favicon <- readFile $
67+ destinationDirectory testConfiguration </> "favicon.ico"
68+ favicon @?= "Test"
69+
70+ cleanTestEnv
tests/data/images/favicon.iconew file

Binary file not shown.