packages feed

nested-routes 1.0.0.1 → 2.0.0

raw patch · 2 files changed

+33/−31 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Web.Routes.Nested: handle :: (Monad m, Functor m, cleanxs ~ OnlyJusts xs, HasResult childType (ActionT z m ()), ExpectArity cleanxs childType, Singleton (UrlChunks xs) childType (RUPTrie Text result), Extrude (UrlChunks xs) (RUPTrie Text childType) (RUPTrie Text result), (ArityMinusTypeList childType cleanxs) ~ result, childType ~ TypeListToArity cleanxs result, LastIsNothing xs) => UrlChunks xs -> childType -> Maybe (HandlerT z childType m ()) -> HandlerT z result m ()
+ Web.Routes.Nested: handle :: (Monad m, Functor m, cleanxs ~ OnlyJusts xs, HasResult childType (ActionT z m ()), ExpectArity cleanxs childType, Singleton (UrlChunks xs) childType (RUPTrie Text result), Extrude (UrlChunks xs) (RUPTrie Text childType) (RUPTrie Text result), (ArityMinusTypeList childType cleanxs) ~ result, childType ~ TypeListToArity cleanxs result, LastIsNothing xs) => UrlChunks xs -> Maybe childType -> Maybe (HandlerT z childType m ()) -> HandlerT z result m ()
- Web.Routes.Nested: notFound :: (Monad m, Functor m, cleanxs ~ OnlyJusts xs, HasResult childType (ActionT z m ()), ExpectArity cleanxs childType, Singleton (UrlChunks xs) childType (RUPTrie Text result), Extrude (UrlChunks xs) (RUPTrie Text childType) (RUPTrie Text result), (ArityMinusTypeList childType cleanxs) ~ result, childType ~ TypeListToArity cleanxs result) => UrlChunks xs -> childType -> Maybe (HandlerT z childType m ()) -> HandlerT z result m ()
+ Web.Routes.Nested: notFound :: (Monad m, Functor m, cleanxs ~ OnlyJusts xs, HasResult childType (ActionT z m ()), ExpectArity cleanxs childType, Singleton (UrlChunks xs) childType (RUPTrie Text result), Extrude (UrlChunks xs) (RUPTrie Text childType) (RUPTrie Text result), (ArityMinusTypeList childType cleanxs) ~ result, childType ~ TypeListToArity cleanxs result) => UrlChunks xs -> Maybe childType -> Maybe (HandlerT z childType m ()) -> HandlerT z result m ()

Files

nested-routes.cabal view
@@ -1,5 +1,5 @@ Name:                   nested-routes-Version:                1.0.0.1+Version:                2.0.0 Author:                 Athan Clark <athan.clark@gmail.com> Maintainer:             Athan Clark <athan.clark@gmail.com> License:                BSD3
src/Web/Routes/Nested.hs view
@@ -96,14 +96,15 @@           , LastIsNothing xs           ) =>           UrlChunks xs -- ^ Path to match against-       -> childType -- ^ Possibly a function, ending in @ActionT z m ()@.+       -> Maybe childType -- ^ Possibly a function, ending in @ActionT z m ()@.        -> Maybe (HandlerT z childType m ()) -- ^ Potential child routes        -> HandlerT z result m ()-handle ts vl Nothing =+handle ts (Just vl) Nothing =   HandlerT $ tell (singleton ts vl, mempty)-handle ts vl (Just cs) = do+handle ts mvl (Just cs) = do   ((Rooted _ ctrie),_) <- lift $ execWriterT $ runHandler cs-  HandlerT $ tell (extrude ts $ Rooted (Just vl) ctrie, mempty)+  HandlerT $ tell (extrude ts $ Rooted mvl ctrie, mempty)+handle _ Nothing Nothing = return ()   notFound :: ( Monad m@@ -121,14 +122,15 @@             , childType ~ TypeListToArity cleanxs result             ) =>             UrlChunks xs-         -> childType+         -> Maybe childType          -> Maybe (HandlerT z childType m ())          -> HandlerT z result m ()-notFound ts vl Nothing = do+notFound ts (Just vl) Nothing = do   HandlerT $ tell (mempty, singleton ts vl)-notFound ts vl (Just cs) = do+notFound ts mvl (Just cs) = do   ((Rooted _ ctrie),_) <- lift $ execWriterT $ runHandler cs-  HandlerT $ tell (mempty, extrude ts $ Rooted (Just vl) ctrie)+  HandlerT $ tell (mempty, extrude ts $ Rooted mvl ctrie)+notFound _ Nothing Nothing = return ()   -- | Turns a @HandlerT@ into a Wai @Application@@@ -151,21 +153,22 @@    notFoundBasic <- handleNotFound acceptBS Html Get mnftrans -  maybe (liftIO $ respond404 notFoundBasic) (\v -> do-    menf <- handleNotFound acceptBS fe v mnftrans-    let cleanedPathInfo = applyToLast trimFileExt $ pathInfo req-        fail = liftIO $ respond404 menf+  case mMethod of+    Nothing -> liftIO $ respond404 notFoundBasic+    Just v  -> do+      menf <- handleNotFound acceptBS fe v mnftrans+      let cleanedPathInfo = applyToLast trimFileExt $ pathInfo req+          fail = liftIO $ respond404 menf -    maybe (case pathInfo req of-        [] -> fail-        _  -> case trimFileExt $ last $ pathInfo req of-          "index" -> maybe fail-                       (\foundM -> continue acceptBS fe v foundM menf)-                       (P.lookup (init $ pathInfo req) rtrie)-          _ -> fail-      ) (\foundM -> continue acceptBS fe v foundM menf)-      (P.lookup cleanedPathInfo rtrie)-    ) mMethod+      case P.lookup cleanedPathInfo rtrie of+        Nothing -> case pathInfo req of+          [] -> fail+          _  -> case trimFileExt $ last $ pathInfo req of+                  "index" -> maybe fail+                               (\foundM -> continue acceptBS fe v foundM menf) $+                               P.lookup (init $ pathInfo req) rtrie+                  _ -> fail+        Just foundM -> continue acceptBS fe v foundM menf    where     onJustM :: Monad m => (a -> m (Maybe b)) -> Maybe a -> m (Maybe b)@@ -182,9 +185,9 @@       let handleEither nfcomp = do             vmapLit <- execWriterT $ runVerbListenerT nfcomp             onJustM (\(_, femonad) -> do-                femap <- execWriterT $ runFileExtListenerT femonad-                return $ lookupProper acceptBS f $ unFileExts femap-              ) $ M.lookup v $ unVerbs vmapLit+              femap <- execWriterT $ runFileExtListenerT femonad+              return $ lookupProper acceptBS f $ unFileExts femap) $+                M.lookup v $ unVerbs vmapLit       in       onJustM handleEither mnfcomp @@ -240,11 +243,10 @@      lookupProper :: Maybe B.ByteString -> FileExt -> M.Map FileExt a -> Maybe a     lookupProper maccept k map =-      let-        attempts = maybe-                     [Html,Text,Json,JavaScript,Css]-                     (\accept -> possibleFileExts k accept)-                     maccept+      let attempts = maybe+                       [Html,Text,Json,JavaScript,Css]+                       (\accept -> possibleFileExts k accept)+                       maccept       in       foldr (go map) Nothing attempts       where