on master help sign in
Add constRoute

Closes #67

commita27e254e0b1f9359653aa378565cc867049342e2 authorJasper Van der Jeugt <m@jaspervdj.be> dateTue 29 May 2012, 23:39 (14 years ago) parentb182541
2 files changed+12
src/Hakyll/Core/Routes.hs+6 tests/Hakyll/Core/Routes/Tests.hs+6
src/Hakyll/Core/Routes.hs+6
@@ -33,6 +33,7 @@ module Hakyll.Core.Routes
3333 , setExtension
3434 , matchRoute
3535 , customRoute
36+ , constRoute
3637 , gsubRoute
3738 , composeRoutes
3839 ) where
@@ -99,6 +100,11 @@ matchRoute pattern (Routes route) = Routes $ \id' ->
99100customRoute :: (Identifier a -> FilePath) -> Routes
100101customRoute f = Routes $ Just . f . castIdentifier
101102
103+-- | A route that always gives the same result. Obviously, you should only use
104+-- this for a single compilation rule.
105+constRoute :: FilePath -> Routes
106+constRoute = customRoute . const
107+
102108-- | Create a gsub route
103109--
104110-- Example:
tests/Hakyll/Core/Routes/Tests.hs+6
@@ -6,6 +6,7 @@ module Hakyll.Core.Routes.Tests
66import Test.Framework
77import Test.HUnit hiding (Test)
88
9+import Hakyll.Core.Identifier
910import Hakyll.Core.Routes
1011import TestSuite.Util
1112
@@ -16,6 +17,11 @@ tests = fromAssertions "runRoutes"
1617 , Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
1718 , Just "foo.html" @=? runRoutes (setExtension ".html") "foo.markdown"
1819
20+ , Just "neve ro ddo reven" @=?
21+ runRoutes (customRoute (reverse . toFilePath )) "never odd or even"
22+
23+ , Just "foo" @=? runRoutes (constRoute "foo") "bar"
24+
1925 , Just "tags/bar.xml" @=?
2026 runRoutes (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
2127 , Just "tags/bar.xml" @=?