summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-05-29 23:39:07 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2012-05-29 23:39:07 +0200
commita27e254e0b1f9359653aa378565cc867049342e2 (patch)
treeb019f605737f7db47950750ea4272b66f4640cc0
parentb182541b587a1d79d7c3794afadb41de9907a70d (diff)
downloadhakyll-a27e254e0b1f9359653aa378565cc867049342e2.tar.gz
Add constRoute
Closes #67
-rw-r--r--src/Hakyll/Core/Routes.hs6
-rw-r--r--tests/Hakyll/Core/Routes/Tests.hs6
2 files changed, 12 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Routes.hs b/src/Hakyll/Core/Routes.hs
index f351447..c4a0db4 100644
--- a/src/Hakyll/Core/Routes.hs
+++ b/src/Hakyll/Core/Routes.hs
@@ -33,6 +33,7 @@ module Hakyll.Core.Routes
, setExtension
, matchRoute
, customRoute
+ , constRoute
, gsubRoute
, composeRoutes
) where
@@ -99,6 +100,11 @@ matchRoute pattern (Routes route) = Routes $ \id' ->
customRoute :: (Identifier a -> FilePath) -> Routes
customRoute f = Routes $ Just . f . castIdentifier
+-- | A route that always gives the same result. Obviously, you should only use
+-- this for a single compilation rule.
+constRoute :: FilePath -> Routes
+constRoute = customRoute . const
+
-- | Create a gsub route
--
-- Example:
diff --git a/tests/Hakyll/Core/Routes/Tests.hs b/tests/Hakyll/Core/Routes/Tests.hs
index 3361846..d204b16 100644
--- a/tests/Hakyll/Core/Routes/Tests.hs
+++ b/tests/Hakyll/Core/Routes/Tests.hs
@@ -6,6 +6,7 @@ module Hakyll.Core.Routes.Tests
import Test.Framework
import Test.HUnit hiding (Test)
+import Hakyll.Core.Identifier
import Hakyll.Core.Routes
import TestSuite.Util
@@ -16,6 +17,11 @@ tests = fromAssertions "runRoutes"
, Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
, Just "foo.html" @=? runRoutes (setExtension ".html") "foo.markdown"
+ , Just "neve ro ddo reven" @=?
+ runRoutes (customRoute (reverse . toFilePath )) "never odd or even"
+
+ , Just "foo" @=? runRoutes (constRoute "foo") "bar"
+
, Just "tags/bar.xml" @=?
runRoutes (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
, Just "tags/bar.xml" @=?