nested-routes 0.2.2 → 0.2.2.1
raw patch · 3 files changed
+15/−12 lines, 3 filesdep ~pred-trie
Dependency ranges changed: pred-trie
Files
- nested-routes.cabal +2/−2
- src/Web/Routes/Nested.hs +8/−5
- src/Web/Routes/Nested/FileExtListener.hs +5/−5
nested-routes.cabal view
@@ -1,5 +1,5 @@ Name: nested-routes-Version: 0.2.2+Version: 0.2.2.1 Author: Athan Clark <athan.clark@gmail.com> Maintainer: Athan Clark <athan.clark@gmail.com> License: BSD3@@ -32,7 +32,7 @@ , lucid , bytestring , attoparsec- , pred-trie >= 0.0.8+ , pred-trie >= 0.0.8.1 Test-Suite spec Type: exitcode-stdio-1.0
src/Web/Routes/Nested.hs view
@@ -161,7 +161,7 @@ let mMethod = httpMethodToMSym $ requestMethod req mFileext = case pathInfo req of [] -> Just Html -- fucky balls - I need to remove file extensions INCREMENTALLY balls- xs -> possibleExts $ getFileExt $ last xs+ xs -> toExt $ getFileExt $ last xs meitherNotFound = P.lookupNearestParent (pathInfo req) nftrie notFoundBasic <- handleNotFound Html Get meitherNotFound@@ -170,10 +170,8 @@ (Just f, Just v) -> do menf <- handleNotFound f v meitherNotFound let cleanedPathInfo = applyToLast trimFileExt $ pathInfo req- liftIO $ putStrLn $ (T.unpack $ T.intercalate "/" cleanedPathInfo) case P.lookup cleanedPathInfo rtrie of- Just eitherM -> do liftIO $ putStrLn $ "sheeit"- continue f v eitherM $ menf+ Just eitherM -> continue f v eitherM $ menf Nothing -> case pathInfo req of [] -> liftIO $ respond404 $ menf _ -> case trimFileExt $ last $ pathInfo req of@@ -305,7 +303,12 @@ applyToLast f (x:xs) = x : applyToLast f xs trimFileExt :: T.Text -> T.Text- trimFileExt s = T.pack $ takeWhile (/= '.') $ T.unpack s+ trimFileExt s = if (T.unpack s) `endsWithAny` possibleExts+ then T.pack $ takeWhile (/= '.') $ T.unpack s+ else s+ where+ possibleExts = [".html",".htm",".txt",".json"]+ endsWithAny s xs = (dropWhile (/= '.') s) `elem` xs httpMethodToMSym :: Method -> Maybe Verb httpMethodToMSym x | x == methodGet = Just Get
src/Web/Routes/Nested/FileExtListener.hs view
@@ -33,11 +33,11 @@ deriving (Show, Eq, Ord) -possibleExts :: T.Text -> Maybe FileExt-possibleExts x | x `elem` htmls = Just Html- | x `elem` jsons = Just Json- | x `elem` texts = Just Text- | otherwise = Nothing+toExt :: T.Text -> Maybe FileExt+toExt x | x `elem` htmls = Just Html+ | x `elem` jsons = Just Json+ | x `elem` texts = Just Text+ | otherwise = Nothing where htmls = ["", ".htm", ".html"] jsons = [".json"]