git.iko.soy/typeable/servant
on master help sign in
Fix top-level raw code-gen issue.
8dfb329Julian K. Arni
src/Servant/JQuery/Internal.hs+5−2
@@ -6,7 +6,9 @@
6{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7module Servant.JQuery.Internal where
7module Servant.JQuery.Internal where
8
8
9+import Control.Applicative
9import Control.Lens
10import Control.Lens
11+import Data.Char (toLower)
10import Data.Monoid
12import Data.Monoid
11import Data.Proxy
13import Data.Proxy
12import GHC.TypeLits
14import GHC.TypeLits
@@ -28,7 +30,7 @@ captureArg (Cap s) = s
28captureArg _ = error "captureArg called on non capture"
30captureArg _ = error "captureArg called on non capture"
29
31
30jsSegments :: [Segment] -> String
32jsSegments :: [Segment] -> String
31−jsSegments [] = ""
33+jsSegments [] = "/'"
32jsSegments [x] = "/" ++ segmentToStr x False
34jsSegments [x] = "/" ++ segmentToStr x False
33jsSegments (x:xs) = "/" ++ segmentToStr x True ++ jsSegments xs
35jsSegments (x:xs) = "/" ++ segmentToStr x True ++ jsSegments xs
34
36
@@ -196,7 +198,8 @@ instance HasJQ Raw where
196 type JQ Raw = Method -> AjaxReq
198 type JQ Raw = Method -> AjaxReq
197
199
198 jqueryFor Proxy req method =
200 jqueryFor Proxy req method =
201+ req & funcName %~ ((toLower <$> method) <>)
199− req & reqMethod .~ method
202+ & reqMethod .~ method
200
203
201instance HasJQ sublayout => HasJQ (ReqBody a :> sublayout) where
204instance HasJQ sublayout => HasJQ (ReqBody a :> sublayout) where
202 type JQ (ReqBody a :> sublayout) = JQ sublayout
205 type JQ (ReqBody a :> sublayout) = JQ sublayout
test/Servant/JQuerySpec.hs+14−4
@@ -1,5 +1,6 @@
1−{-# LANGUAGE TypeOperators #-}
1+{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE QuasiQuotes #-}
2{-# LANGUAGE QuasiQuotes #-}
3+{-# LANGUAGE TypeOperators #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
4{-# OPTIONS_GHC -fno-warn-orphans #-}
4module Servant.JQuerySpec where
5module Servant.JQuerySpec where
5
6
@@ -16,14 +17,23 @@ POST /simple String -> Bool
16GET /has.extension Bool
17GET /has.extension Bool
17|]
18|]
18
19
20+type TopLevelRawAPI = "something" :> Get Int
21+ :<|> Raw
22+
19spec :: Spec
23spec :: Spec
20spec = describe "Servant.JQuery"
24spec = describe "Servant.JQuery"
21 generateJSSpec
25 generateJSSpec
22
26
23generateJSSpec :: Spec
27generateJSSpec :: Spec
24−generateJSSpec = describe "generateJS" $
28+generateJSSpec = describe "generateJS" $ do
25− it "should always generate valid javascript" $ do
29+ it "should generate valid javascript" $ do
26− let (postSimple :<|> getHasExtension) = jquery (Proxy :: Proxy TestAPI)
30+ let (postSimple :<|> getHasExtension ) = jquery (Proxy :: Proxy TestAPI)
27 parseFromString (generateJS postSimple) `shouldSatisfy` isRight
31 parseFromString (generateJS postSimple) `shouldSatisfy` isRight
28 parseFromString (generateJS getHasExtension) `shouldSatisfy` isRight
32 parseFromString (generateJS getHasExtension) `shouldSatisfy` isRight
33+ print $ generateJS getHasExtension
34+
35+ it "should use non-empty function names" $ do
36+ let (_ :<|> topLevel) = jquery (Proxy :: Proxy TopLevelRawAPI)
37+ print $ generateJS $ topLevel "GET"
38+ parseFromString (generateJS $ topLevel "GET") `shouldSatisfy` isRight
29
39