From ad900cda513b5016e9a80a1253de4d1dbb9f41e1 Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Fri, 27 Mar 2015 10:27:27 +0100 Subject: [PATCH] More PR5 fixes --- CHANGELOG.md | 1 + src/Servant/JQuery.hs | 5 +++-- src/Servant/JQuery/Internal.hs | 21 +-------------------- test/Servant/JQuerySpec.hs | 1 - 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 093c93aa..ceac30d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ --- * Extend `HeaderArg` to support more advanced HTTP header handling (https://github.com/haskell-servant/servant-jquery/pull/6) * Support content-type aware combinators (but require that endpoints support JSON) +* Add support for Matrix params (https://github.com/haskell-servant/servant-jquery/pull/11) 0.2.2 ----- diff --git a/src/Servant/JQuery.hs b/src/Servant/JQuery.hs index 38ff92d8..d979755d 100644 --- a/src/Servant/JQuery.hs +++ b/src/Servant/JQuery.hs @@ -46,7 +46,7 @@ generateJS req = "\n" <> ++ body ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs ++ ["onSuccess", "onError"] - + captures = map captureArg . filter isCapture $ req ^. reqUrl.path @@ -76,7 +76,8 @@ generateJS req = "\n" <> fname = req ^. funcName method = req ^. reqMethod - url = "'" + url = if url' == "'" then "'/'" else url' + url' = "'" ++ urlArgs ++ queryArgs diff --git a/src/Servant/JQuery/Internal.hs b/src/Servant/JQuery/Internal.hs index 24d811f9..738acd7e 100644 --- a/src/Servant/JQuery/Internal.hs +++ b/src/Servant/JQuery/Internal.hs @@ -31,25 +31,6 @@ data SegmentType = Static String -- ^ a static path segment. like "/foo" | Cap Arg -- ^ a capture. like "/:userid" deriving (Eq, Show) -isCapture :: Segment -> Bool -isCapture (Cap _) = True -isCapture _ = False - -captureArg :: Segment -> Arg -captureArg (Cap s) = s -captureArg _ = error "captureArg called on non capture" - -jsSegments :: [Segment] -> String -jsSegments [] = "/'" -jsSegments [x] = "/" ++ segmentToStr x False -jsSegments (x:xs) = "/" ++ segmentToStr x True ++ jsSegments xs - -segmentToStr :: Segment -> Bool -> String -segmentToStr (Static s) notTheEnd = - if notTheEnd then s else s ++ "'" -segmentToStr (Cap s) notTheEnd = - "' + encodeURIComponent(" ++ s ++ if notTheEnd then ") + '" else ")" - type Path = [Segment] data ArgType = @@ -305,7 +286,7 @@ instance (KnownSymbol sym, HasJQ sublayout) jqueryFor Proxy req = jqueryFor (Proxy :: Proxy sublayout) $ - req & reqUrl.path._last.matrix <>~ [QueryArg str Normal] + req & reqUrl.path._last.matrix <>~ [QueryArg strArg Normal] where str = symbolVal (Proxy :: Proxy sym) strArg = str ++ "Value" diff --git a/test/Servant/JQuerySpec.hs b/test/Servant/JQuerySpec.hs index ce06e98f..077b9b87 100644 --- a/test/Servant/JQuerySpec.hs +++ b/test/Servant/JQuerySpec.hs @@ -13,7 +13,6 @@ import Language.ECMAScript3.Parser (parseFromString) import Test.Hspec import Servant.API -import Servant.API.ContentTypes import Servant.JQuery import Servant.JQuerySpec.CustomHeaders