More PR5 fixes

This commit is contained in:
Julian K. Arni 2015-03-27 10:27:27 +01:00
parent 467df6dd66
commit ad900cda51
4 changed files with 5 additions and 23 deletions

View file

@ -2,6 +2,7 @@
--- ---
* Extend `HeaderArg` to support more advanced HTTP header handling (https://github.com/haskell-servant/servant-jquery/pull/6) * 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) * 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 0.2.2
----- -----

View file

@ -46,7 +46,7 @@ generateJS req = "\n" <>
++ body ++ body
++ map (toValidFunctionName . (<>) "header" . headerArgName) hs ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs
++ ["onSuccess", "onError"] ++ ["onSuccess", "onError"]
captures = map captureArg captures = map captureArg
. filter isCapture . filter isCapture
$ req ^. reqUrl.path $ req ^. reqUrl.path
@ -76,7 +76,8 @@ generateJS req = "\n" <>
fname = req ^. funcName fname = req ^. funcName
method = req ^. reqMethod method = req ^. reqMethod
url = "'" url = if url' == "'" then "'/'" else url'
url' = "'"
++ urlArgs ++ urlArgs
++ queryArgs ++ queryArgs

View file

@ -31,25 +31,6 @@ data SegmentType = Static String -- ^ a static path segment. like "/foo"
| Cap Arg -- ^ a capture. like "/:userid" | Cap Arg -- ^ a capture. like "/:userid"
deriving (Eq, Show) 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] type Path = [Segment]
data ArgType = data ArgType =
@ -305,7 +286,7 @@ instance (KnownSymbol sym, HasJQ sublayout)
jqueryFor Proxy req = jqueryFor Proxy req =
jqueryFor (Proxy :: Proxy sublayout) $ 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) where str = symbolVal (Proxy :: Proxy sym)
strArg = str ++ "Value" strArg = str ++ "Value"

View file

@ -13,7 +13,6 @@ import Language.ECMAScript3.Parser (parseFromString)
import Test.Hspec import Test.Hspec
import Servant.API import Servant.API
import Servant.API.ContentTypes
import Servant.JQuery import Servant.JQuery
import Servant.JQuerySpec.CustomHeaders import Servant.JQuerySpec.CustomHeaders