nested-routes 2.0.0 → 2.0.1
raw patch · 2 files changed
+26/−18 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
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 -> Maybe 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) => UrlChunks xs -> Maybe childType -> Maybe (HandlerT z childType m ()) -> HandlerT z result m ()
Files
- nested-routes.cabal +10/−8
- src/Web/Routes/Nested.hs +16/−10
nested-routes.cabal view
@@ -1,5 +1,5 @@ Name: nested-routes-Version: 2.0.0+Version: 2.0.1 Author: Athan Clark <athan.clark@gmail.com> Maintainer: Athan Clark <athan.clark@gmail.com> License: BSD3@@ -20,29 +20,31 @@ <https://hackage.haskell.org/package/attoparsec Attoparsec> parsers and <https://hackage.haskell.org/package/regex-compat Regular Expressions> /directly/ in our routes, with our handlers- reflecting their results. As an example:+ reflecting their results. You can find more information on the <https://www.fpcomplete.com/user/AthanClark/nested-routes demo>. .+ As an example:+ . > router :: Application > router = route handlers > where > handlers = do > handle o- > (get $ text "home")+ > (Just $ get $ text "home") > Nothing > handle ("foo" </> "bar")- > (get $ text "foobar") $ Just $+ > (Just $ get $ text "foobar") $ Just $ > handle (p ("baz", double) </> o)- > (\d -> get $ text $ LT.pack (show d) <> " bazs")+ > (Just $ \d -> get $ text $ LT.pack (show d) <> " bazs") > Nothing > handle (p ("num",double) </> o)- > (\d -> get $ text $ LT.pack $ show d) $ Just $ do+ > (Just $ \d -> get $ text $ LT.pack $ show d) $ Just $ do > handle "bar"- > (\d -> get $ do+ > (Just $ \d -> get $ do > text $ (LT.pack $ show d) <> " bars") > json $ (LT.pack $ show d) <> " bars!") > Nothing > handle (r ("email", mkRegex "(^[-a-zA-Z0-9_.]+@[-a-zA-Z0-9]+\\.[-a-zA-Z0-9.]+$)") </> o)- > (\d e -> get $ textOnly $ (LT.pack $ show d) <> " " <> (LT.pack $ show e)+ > (Just $ \d e -> get $ textOnly $ (LT.pack $ show d) <> " " <> (LT.pack $ show e) . The route specification syntax is a little strange right now - @l@ specifies a "literal chunk" of a handlable url (ie - @l \"foo\" \<\/\> l \"bar\" \<\/\> o@ would
src/Web/Routes/Nested.hs view
@@ -70,15 +70,6 @@ type ActionT z m a = VerbListenerT z (FileExtListenerT Response m a) m a -type family LastIsNothing (xs :: [Maybe *]) :: Constraint where- LastIsNothing '[] = ()- LastIsNothing ('Nothing ': '[]) = ()- LastIsNothing (x ': xs) = LastIsNothing xs--type family LastIsJust (xs :: [Maybe *]) :: Constraint where- LastIsJust (('Just x) ': '[]) = ()- LastIsJust (x ': xs) = LastIsJust xs- -- | For routes ending with a literal. handle :: ( Monad m , Functor m@@ -93,7 +84,6 @@ (RUPTrie T.Text result) , (ArityMinusTypeList childType cleanxs) ~ result , childType ~ TypeListToArity cleanxs result- , LastIsNothing xs ) => UrlChunks xs -- ^ Path to match against -> Maybe childType -- ^ Possibly a function, ending in @ActionT z m ()@.@@ -106,6 +96,22 @@ HandlerT $ tell (extrude ts $ Rooted mvl ctrie, mempty) handle _ Nothing Nothing = return () +-- categorize :: ( Monad m+-- , Functor m+-- , cleanxs ~ OnlyJusts xs+-- , HasResult childType (ActionT z m ())+-- , ExpectArity cleanxs childType+-- , Singleton (UrlChunks xs)+-- childType+-- (RUPTrie T.Text result)+-- , Extrude (UrlChunks xs)+-- (RUPTrie T.Text childType)+-- (RUPTrie T.Text result)+-- , (ArityMinusTypeList childType cleanxs) ~ result+-- , childType ~ TypeListToArity cleanxs result+-- , LastIsNothing xs+-- ) =>+-- categorize notFound :: ( Monad m , Functor m