git.iko.soy/typeable/servant
on master help sign in
CommonGeneratorOptions moved to servant-js
commit7ff9e52a508a62482f089e11ef0f1847cbcce9e6 authorDenis Redozubov <denis.redozubov@gmail.com> dateTue 22 Sep 2015, 12:21 (11 years ago) parent6fa4b55
2 files changed+37−40
servant-foreign/src/Servant/Foreign.hs−38 servant-js/src/Servant/JS/Internal.hs+37−2
servant-foreign/src/Servant/Foreign.hs−38
@@ -21,8 +21,6 @@ module Servant.Foreign
2121 , HeaderArg(..)
2222 , ArgType(..)
2323 , Req
24− , CommonGeneratorOptions(..)
25− , defCommonGeneratorOptions
2624 , toValidFunctionName
2725 , captureArg
2826 , defReq
@@ -60,41 +58,6 @@ import GHC.Exts (Constraint)
6058import GHC.TypeLits
6159import Servant.API
6260
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−
9861-- | Function name builder that simply concat each part together
9962concatCase :: FunctionName -> String
10063concatCase = concat
@@ -233,7 +196,6 @@ defReq :: Req
233196defReq = Req defUrl "GET" [] False []
234197
235198type family Elem (a :: *) (ls::[*]) :: Constraint where
236− Elem a '[] = 'False ~ 'True
237199 Elem a (a ': list) = ()
238200 Elem a (b ': list) = Elem a list
239201
servant-js/src/Servant/JS/Internal.hs+37−2
@@ -1,5 +1,7 @@
11module Servant.JS.Internal
22 ( JavaScriptGenerator
3+ , CommonGeneratorOptions(..)
4+ , defCommonGeneratorOptions
35 , AjaxReq
46 , jsSegments
57 , segmentToStr
@@ -12,9 +14,7 @@ module Servant.JS.Internal
1214 , (:<|>)(..)
1315 , (:>)
1416 , defReq
15− , defCommonGeneratorOptions
1617 , reqHeaders
17− , CommonGeneratorOptions(..)
1818 , HasForeign(..)
1919 , HeaderArg(..)
2020 , concatCase
@@ -39,6 +39,41 @@ type AjaxReq = Req
3939-- generators are available in this package.
4040type JavaScriptGenerator = [Req] -> String
4141
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+
4277jsSegments :: [Segment] -> String
4378jsSegments [] = ""
4479jsSegments [x] = "/" ++ segmentToStr x False