git.iko.soy/typeable/http-api-data
on master help sign in
Route -> Path in names
3c241dfMichael Snoyman
Web/PathPieces.hs+47−47
@@ -1,7 +1,7 @@
1{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
1{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
2module Web.PathPieces
2module Web.PathPieces
3− ( RoutePiece (..)
3+ ( PathPiece (..)
4− , RouteMultiPiece (..)
4+ , PathMultiPiece (..)
5 -- * Deprecated
5 -- * Deprecated
6 , toSinglePiece
6 , toSinglePiece
7 , toMultiPiece
7 , toMultiPiece
@@ -14,72 +14,72 @@ import qualified Data.Text as S
14import qualified Data.Text.Lazy as L
14import qualified Data.Text.Lazy as L
15import qualified Data.Text.Read
15import qualified Data.Text.Read
16
16
17−class RoutePiece s where
17+class PathPiece s where
18− fromRoutePiece :: S.Text -> Maybe s
18+ fromPathPiece :: S.Text -> Maybe s
19− toRoutePiece :: s -> S.Text
19+ toPathPiece :: s -> S.Text
20
20
21−instance RoutePiece String where
21+instance PathPiece String where
22− fromRoutePiece s = if S.null s then Nothing else Just (S.unpack s)
22+ fromPathPiece s = if S.null s then Nothing else Just (S.unpack s)
23− toRoutePiece = S.pack
23+ toPathPiece = S.pack
24
24
25−instance RoutePiece S.Text where
25+instance PathPiece S.Text where
26− fromRoutePiece s = if S.null s then Nothing else Just s
26+ fromPathPiece s = if S.null s then Nothing else Just s
27− toRoutePiece = id
27+ toPathPiece = id
28
28
29−instance RoutePiece L.Text where
29+instance PathPiece L.Text where
30− fromRoutePiece s = if S.null s then Nothing else Just (L.fromChunks [s])
30+ fromPathPiece s = if S.null s then Nothing else Just (L.fromChunks [s])
31− toRoutePiece = S.concat . L.toChunks
31+ toPathPiece = S.concat . L.toChunks
32
32
33−instance RoutePiece Integer where
33+instance PathPiece Integer where
34− fromRoutePiece s =
34+ fromPathPiece s =
35 case Data.Text.Read.decimal s of
35 case Data.Text.Read.decimal s of
36 Right (i, _) -> Just i
36 Right (i, _) -> Just i
37 Left _ -> Nothing
37 Left _ -> Nothing
38− toRoutePiece = S.pack . show
38+ toPathPiece = S.pack . show
39
39
40−instance RoutePiece Int where
40+instance PathPiece Int where
41− fromRoutePiece s =
41+ fromPathPiece s =
42 case Data.Text.Read.decimal s of
42 case Data.Text.Read.decimal s of
43 Right (i, _) -> Just i
43 Right (i, _) -> Just i
44 Left _ -> Nothing
44 Left _ -> Nothing
45− toRoutePiece = S.pack . show
45+ toPathPiece = S.pack . show
46
46
47−instance RoutePiece Int64 where
47+instance PathPiece Int64 where
48− fromRoutePiece s =
48+ fromPathPiece s =
49 case Data.Text.Read.decimal s of
49 case Data.Text.Read.decimal s of
50 Right (i, _) -> Just i
50 Right (i, _) -> Just i
51 Left _ -> Nothing
51 Left _ -> Nothing
52− toRoutePiece = S.pack . show
52+ toPathPiece = S.pack . show
53
53
54
54
55−class RouteMultiPiece s where
55+class PathMultiPiece s where
56− fromRouteMultiPiece :: [S.Text] -> Maybe s
56+ fromPathMultiPiece :: [S.Text] -> Maybe s
57− toRouteMultiPiece :: s -> [S.Text]
57+ toPathMultiPiece :: s -> [S.Text]
58
58
59−instance RouteMultiPiece [String] where
59+instance PathMultiPiece [String] where
60− fromRouteMultiPiece = Just . map S.unpack
60+ fromPathMultiPiece = Just . map S.unpack
61− toRouteMultiPiece = map S.pack
61+ toPathMultiPiece = map S.pack
62
62
63−instance RouteMultiPiece [S.Text] where
63+instance PathMultiPiece [S.Text] where
64− fromRouteMultiPiece = Just
64+ fromPathMultiPiece = Just
65− toRouteMultiPiece = id
65+ toPathMultiPiece = id
66
66
67−instance RouteMultiPiece [L.Text] where
67+instance PathMultiPiece [L.Text] where
68− fromRouteMultiPiece = Just . map (L.fromChunks . return)
68+ fromPathMultiPiece = Just . map (L.fromChunks . return)
69− toRouteMultiPiece = map $ S.concat . L.toChunks
69+ toPathMultiPiece = map $ S.concat . L.toChunks
70
70
71−{-# DEPRECATED toSinglePiece "Use toRoutePiece instead of toSinglePiece" #-}
71+{-# DEPRECATED toSinglePiece "Use toPathPiece instead of toSinglePiece" #-}
72−toSinglePiece :: RoutePiece p => p -> S.Text
72+toSinglePiece :: PathPiece p => p -> S.Text
73−toSinglePiece = toRoutePiece
73+toSinglePiece = toPathPiece
74
74
75−{-# DEPRECATED fromSinglePiece "Use fromRoutePiece instead of fromSinglePiece" #-}
75+{-# DEPRECATED fromSinglePiece "Use fromPathPiece instead of fromSinglePiece" #-}
76−fromSinglePiece :: RoutePiece p => S.Text -> Maybe p
76+fromSinglePiece :: PathPiece p => S.Text -> Maybe p
77−fromSinglePiece = fromRoutePiece
77+fromSinglePiece = fromPathPiece
78
78
79−{-# DEPRECATED toMultiPiece "Use toRouteMultiPiece instead of toMultiPiece" #-}
79+{-# DEPRECATED toMultiPiece "Use toPathMultiPiece instead of toMultiPiece" #-}
80−toMultiPiece :: RouteMultiPiece ps => ps -> [S.Text]
80+toMultiPiece :: PathMultiPiece ps => ps -> [S.Text]
81−toMultiPiece = toRouteMultiPiece
81+toMultiPiece = toPathMultiPiece
82
82
83−{-# DEPRECATED fromMultiPiece "Use fromRouteMultiPiece instead of fromMultiPiece" #-}
83+{-# DEPRECATED fromMultiPiece "Use fromPathMultiPiece instead of fromMultiPiece" #-}
84−fromMultiPiece :: RouteMultiPiece ps => [S.Text] -> Maybe ps
84+fromMultiPiece :: PathMultiPiece ps => [S.Text] -> Maybe ps
85−fromMultiPiece = fromRouteMultiPiece
85+fromMultiPiece = fromPathMultiPiece