on master help sign in
CommonGeneratorOptions moved to servant-js
7ff9e52Denis Redozubov
servant-foreign/src/Servant/Foreign.hs−38
@@ -21,8 +21,6 @@ module Servant.Foreign
21 , HeaderArg(..)
21 , HeaderArg(..)
22 , ArgType(..)
22 , ArgType(..)
23 , Req
23 , Req
24− , CommonGeneratorOptions(..)
25− , defCommonGeneratorOptions
26 , toValidFunctionName
24 , toValidFunctionName
27 , captureArg
25 , captureArg
28 , defReq
26 , defReq
@@ -60,41 +58,6 @@ import GHC.Exts (Constraint)
60import GHC.TypeLits
58import GHC.TypeLits
61import Servant.API
59import Servant.API
62
60
63−-- | This structure is used by specific implementations to let you
64−-- customize the output
65−data CommonGeneratorOptions = CommonGeneratorOptions
66− {
67− functionNameBuilder :: FunctionName -> String -- ^ function generating function names
68− , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
69− , successCallback :: String -- ^ name of the callback parameter when the request was successful
70− , errorCallback :: String -- ^ name of the callback parameter when the request reported an error
71− , moduleName :: String -- ^ namespace on which we define the foreign function (empty mean local var)
72− , urlPrefix :: String -- ^ a prefix we should add to the Url in the codegen
73− }
74−
75−-- | Default options.
76−--
77−-- @
78−-- > defCommonGeneratorOptions = CommonGeneratorOptions
79−-- > { functionNameBuilder = camelCase
80−-- > , requestBody = "body"
81−-- > , successCallback = "onSuccess"
82−-- > , errorCallback = "onError"
83−-- > , moduleName = ""
84−-- > , urlPrefix = ""
85−-- > }
86−-- @
87−defCommonGeneratorOptions :: CommonGeneratorOptions
88−defCommonGeneratorOptions = CommonGeneratorOptions
89− {
90− functionNameBuilder = camelCase
91− , requestBody = "body"
92− , successCallback = "onSuccess"
93− , errorCallback = "onError"
94− , moduleName = ""
95− , urlPrefix = ""
96− }
97−
98-- | Function name builder that simply concat each part together
61-- | Function name builder that simply concat each part together
99concatCase :: FunctionName -> String
62concatCase :: FunctionName -> String
100concatCase = concat
63concatCase = concat
@@ -233,7 +196,6 @@ defReq :: Req
233defReq = Req defUrl "GET" [] False []
196defReq = Req defUrl "GET" [] False []
234
197
235type family Elem (a :: *) (ls::[*]) :: Constraint where
198type family Elem (a :: *) (ls::[*]) :: Constraint where
236− Elem a '[] = 'False ~ 'True
237 Elem a (a ': list) = ()
199 Elem a (a ': list) = ()
238 Elem a (b ': list) = Elem a list
200 Elem a (b ': list) = Elem a list
239
201
servant-js/src/Servant/JS/Internal.hs+37−2
@@ -1,5 +1,7 @@
1module Servant.JS.Internal
1module Servant.JS.Internal
2 ( JavaScriptGenerator
2 ( JavaScriptGenerator
3+ , CommonGeneratorOptions(..)
4+ , defCommonGeneratorOptions
3 , AjaxReq
5 , AjaxReq
4 , jsSegments
6 , jsSegments
5 , segmentToStr
7 , segmentToStr
@@ -12,9 +14,7 @@ module Servant.JS.Internal
12 , (:<|>)(..)
14 , (:<|>)(..)
13 , (:>)
15 , (:>)
14 , defReq
16 , defReq
15− , defCommonGeneratorOptions
16 , reqHeaders
17 , reqHeaders
17− , CommonGeneratorOptions(..)
18 , HasForeign(..)
18 , HasForeign(..)
19 , HeaderArg(..)
19 , HeaderArg(..)
20 , concatCase
20 , concatCase
@@ -39,6 +39,41 @@ type AjaxReq = Req
39-- generators are available in this package.
39-- generators are available in this package.
40type JavaScriptGenerator = [Req] -> String
40type JavaScriptGenerator = [Req] -> String
41
41
42+-- | This structure is used by specific implementations to let you
43+-- customize the output
44+data CommonGeneratorOptions = CommonGeneratorOptions
45+ {
46+ functionNameBuilder :: FunctionName -> String -- ^ function generating function names
47+ , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
48+ , successCallback :: String -- ^ name of the callback parameter when the request was successful
49+ , errorCallback :: String -- ^ name of the callback parameter when the request reported an error
50+ , moduleName :: String -- ^ namespace on which we define the foreign function (empty mean local var)
51+ , urlPrefix :: String -- ^ a prefix we should add to the Url in the codegen
52+ }
53+
54+-- | Default options.
55+--
56+-- @
57+-- > defCommonGeneratorOptions = CommonGeneratorOptions
58+-- > { functionNameBuilder = camelCase
59+-- > , requestBody = "body"
60+-- > , successCallback = "onSuccess"
61+-- > , errorCallback = "onError"
62+-- > , moduleName = ""
63+-- > , urlPrefix = ""
64+-- > }
65+-- @
66+defCommonGeneratorOptions :: CommonGeneratorOptions
67+defCommonGeneratorOptions = CommonGeneratorOptions
68+ {
69+ functionNameBuilder = camelCase
70+ , requestBody = "body"
71+ , successCallback = "onSuccess"
72+ , errorCallback = "onError"
73+ , moduleName = ""
74+ , urlPrefix = ""
75+ }
76+
42jsSegments :: [Segment] -> String
77jsSegments :: [Segment] -> String
43jsSegments [] = ""
78jsSegments [] = ""
44jsSegments [x] = "/" ++ segmentToStr x False
79jsSegments [x] = "/" ++ segmentToStr x False