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)
* 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
-----

View File

@ -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

View File

@ -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"

View File

@ -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