joinPath takes Text

This commit is contained in:
Michael Snoyman 2011-04-15 07:33:52 +03:00
parent 69abcb344a
commit 18e04175eb
2 changed files with 4 additions and 6 deletions

View File

@ -206,11 +206,11 @@ class RenderRoute (Route a) => Yesod a where
-- | Join the pieces of a path together into an absolute URL. This should -- | Join the pieces of a path together into an absolute URL. This should
-- be the inverse of 'splitPath'. -- be the inverse of 'splitPath'.
joinPath :: a joinPath :: a
-> Builder -- ^ application root -> TS.Text -- ^ application root
-> [TS.Text] -- ^ path pieces -> [TS.Text] -- ^ path pieces
-> [(TS.Text, TS.Text)] -- ^ query string -> [(TS.Text, TS.Text)] -- ^ query string
-> Builder -> Builder
joinPath _ ar pieces' qs' = ar `mappend` encodePath pieces qs joinPath _ ar pieces' qs' = fromText ar `mappend` encodePath pieces qs
where where
pieces = if null pieces' then [""] else pieces' pieces = if null pieces' then [""] else pieces'
qs = map (TE.encodeUtf8 *** go) qs' qs = map (TE.encodeUtf8 *** go) qs'
@ -569,7 +569,7 @@ yesodRender :: Yesod y
yesodRender y u qs = yesodRender y u qs =
TE.decodeUtf8 $ toByteString $ TE.decodeUtf8 $ toByteString $
fromMaybe fromMaybe
(joinPath y (fromText $ approot y) ps (joinPath y (approot y) ps
$ qs ++ qs') $ qs ++ qs')
(urlRenderOverride y u) (urlRenderOverride y u)
where where

View File

@ -23,8 +23,6 @@ import Network.HTTP.Types (status301)
import Data.Text (Text) import Data.Text (Text)
import Data.Monoid (mappend) import Data.Monoid (mappend)
import qualified Blaze.ByteString.Builder import qualified Blaze.ByteString.Builder
import qualified Blaze.ByteString.Builder.Char8
import Blaze.ByteString.Builder.Char.Utf8 (fromText)
import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Char8 as S8
{-| {-|
@ -87,7 +85,7 @@ sendRedirect y segments' env =
, ("Location", Blaze.ByteString.Builder.toByteString dest') , ("Location", Blaze.ByteString.Builder.toByteString dest')
] "Redirecting" ] "Redirecting"
where where
dest = joinPath y (fromText $ approot y) segments' [] dest = joinPath y (approot y) segments' []
dest' = dest' =
if S.null (W.rawQueryString env) if S.null (W.rawQueryString env)
then dest then dest