Luke Plant avatar Luke Plant committed f9a3540

Moved processors to Web.Processors.General

Comments (0)

Files changed (6)

src/Blog/Routes.hs

 import Blog.Views
 import Blog.Processors
 import Web.Framework
-import Web.Framework.Processors (addSlashRedirectProcessor)
+import Web.Processors.General (addSlashRedirectProcessor)
 import Web.GenUtils (apply)
 
 -- * Routes

src/Web/Framework/Processors.hs

-module Web.Framework.Processors
-    ( addSlashRedirectProcessor
-    )
-
-where
-
-import Data.List (isSuffixOf)
-import Web.Request
-import Web.Response
-
--- TODO -- need to include query string, and think about how to handle
--- POSTs etc
-addSlashRedirectProcessor view req =
-    let uri = requestUriRaw req
-    in case uri of
-        Nothing -> view req -- Can't do a redirect if we don't know original URI
-        Just "" -> view req -- Don't redirect if empty
-        Just x ->  if not ("/" `isSuffixOf` x)
-                   then return $ Just $ redirectResponse (x ++ "/")
-                   else view req

src/Web/Processors/General.hs

+module Web.Processors.General
+    ( addSlashRedirectProcessor
+    )
+
+where
+
+import Data.List (isSuffixOf)
+import Web.Request
+import Web.Response
+
+-- TODO -- need to include query string, and think about how to handle
+-- POSTs etc
+addSlashRedirectProcessor view req =
+    let uri = requestUriRaw req
+    in case uri of
+        Nothing -> view req -- Can't do a redirect if we don't know original URI
+        Just "" -> view req -- Don't redirect if empty
+        Just x ->  if not ("/" `isSuffixOf` x)
+                   then return $ Just $ redirectResponse (x ++ "/")
+                   else view req

testsuite/tests/Main.hs

 import qualified Tests.Web.Request as Request
 import qualified Tests.Web.Response as Response
 import qualified Tests.Web.Framework as Framework
-import qualified Tests.Web.Framework.Processors as Processors
+import qualified Tests.Web.Processors.General as GeneralProcessors
 import Test.HUnit
 
 main = runTestTT (test [
                   , Request.tests
                   , Response.tests
                   , Framework.tests
-                  , Processors.tests
+                  , GeneralProcessors.tests
                   ])

testsuite/tests/Tests/Web/Framework/Processors.hs

-{-# OPTIONS_GHC -fglasgow-exts -XOverloadedStrings #-}
-module Tests.Web.Framework.Processors
-
-where
-
-import Data.Maybe (fromJust)
-import Web.Framework.Processors
-import Web.GenUtils ()
-import Web.Response
-import Web.Request
-import Test.HUnit
-import Tests.Web.Framework -- reuse view functions
-
-testAddSlashRedirectProcessor1 =
-    (do
-      resp <- addSlashRedirectProcessor alwaysSucceedView1 (mkGetReq "/posts")
-      return (resp == (Just $ redirectResponse "/posts/"))
-    ) ~? "addSlashRedirectProcessor should add a slash if not present at end"
-
-
-testAddSlashRedirectProcessor2 =
-    (do
-      resp <- addSlashRedirectProcessor alwaysSucceedView1 (mkGetReq "/posts/")
-      return (resp == (Just resp1))
-    ) ~? "addSlashRedirectProcessor should not redirect if slash present at end"
-
-testAddSlashRedirectProcessor3 =
-    (do
-      resp <- addSlashRedirectProcessor alwaysSucceedView1 (mkRequest
-                                                            [("REQUEST_METHOD", "GET")
-                                                            ,("PATH_INFO", "/posts")
-                                                            ,("REQUEST_URI","/foo/posts")]
-                                                            "" utf8Encoding)
-      return (resp == (Just $ redirectResponse "/foo/posts/"))
-    ) ~? "addSlashRedirectProcessor should redirect based on request URI, not path info"
-
-
-
-tests = test [ testAddSlashRedirectProcessor1
-             , testAddSlashRedirectProcessor2
-             , testAddSlashRedirectProcessor3
-             ]

testsuite/tests/Tests/Web/Processors/General.hs

+{-# OPTIONS_GHC -fglasgow-exts -XOverloadedStrings #-}
+module Tests.Web.Processors.General
+
+where
+
+import Data.Maybe (fromJust)
+import Web.Processors.General
+import Web.GenUtils ()
+import Web.Response
+import Web.Request
+import Test.HUnit
+import Tests.Web.Framework -- reuse view functions
+
+testAddSlashRedirectProcessor1 =
+    (do
+      resp <- addSlashRedirectProcessor alwaysSucceedView1 (mkGetReq "/posts")
+      return (resp == (Just $ redirectResponse "/posts/"))
+    ) ~? "addSlashRedirectProcessor should add a slash if not present at end"
+
+
+testAddSlashRedirectProcessor2 =
+    (do
+      resp <- addSlashRedirectProcessor alwaysSucceedView1 (mkGetReq "/posts/")
+      return (resp == (Just resp1))
+    ) ~? "addSlashRedirectProcessor should not redirect if slash present at end"
+
+testAddSlashRedirectProcessor3 =
+    (do
+      resp <- addSlashRedirectProcessor alwaysSucceedView1 (mkRequest
+                                                            [("REQUEST_METHOD", "GET")
+                                                            ,("PATH_INFO", "/posts")
+                                                            ,("REQUEST_URI","/foo/posts")]
+                                                            "" utf8Encoding)
+      return (resp == (Just $ redirectResponse "/foo/posts/"))
+    ) ~? "addSlashRedirectProcessor should redirect based on request URI, not path info"
+
+
+
+tests = test [ testAddSlashRedirectProcessor1
+             , testAddSlashRedirectProcessor2
+             , testAddSlashRedirectProcessor3
+             ]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.