@@ -1,16 +1,16 @@
1module Servant.JS.Angular where
1module Servant.JS.Angular where
3−import Servant.JS.Internal
4−import Control.Lens
3+import Control.Lens
5−import Data.List
4+import Data.List
6−import Data.Monoid
5+import Data.Monoid
6+import Servant.JS.Internal
8-- | Options specific to the angular code generator
8-- | Options specific to the angular code generator
9data AngularOptions = AngularOptions
9data AngularOptions = AngularOptions
10 { serviceName :: String -- ^ When generating code with wrapInService,
10 { serviceName :: String -- ^ When generating code with wrapInService,
11 -- name of the service to generate
11 -- name of the service to generate
12− , prologue :: String -> String -> String -- ^ beginning of the service definition
12+ , prologue :: String -> String -> String -- ^ beginning of the service definition
13− , epilogue :: String -- ^ end of the service definition
13+ , epilogue :: String -- ^ end of the service definition
16-- | Default options for the Angular codegen. Used by 'wrapInService'.
16-- | Default options for the Angular codegen. Used by 'wrapInService'.
@@ -31,7 +31,7 @@ angularService ngOpts = angularServiceWith ngOpts defCommonGeneratorOptions
31-- | Instead of simply generating top level functions, generates a service instance
31-- | Instead of simply generating top level functions, generates a service instance
32-- on which your controllers can depend to access your API
32-- on which your controllers can depend to access your API
33angularServiceWith :: AngularOptions -> CommonGeneratorOptions -> JavaScriptGenerator
33angularServiceWith :: AngularOptions -> CommonGeneratorOptions -> JavaScriptGenerator
34−angularServiceWith ngOpts opts reqs =
34+angularServiceWith ngOpts opts reqs =
35 prologue ngOpts svc mName
35 prologue ngOpts svc mName
36 <> intercalate "," (map generator reqs) <>
36 <> intercalate "," (map generator reqs) <>
37 epilogue ngOpts
37 epilogue ngOpts
@@ -54,7 +54,7 @@ angularWith ngopts opts = intercalate "\n\n" . map (generateAngularJSWith ngopts
54-- | js codegen using $http service from Angular using default options
54-- | js codegen using $http service from Angular using default options
55generateAngularJS :: AngularOptions -> AjaxReq -> String
55generateAngularJS :: AngularOptions -> AjaxReq -> String
56generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions
56generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions
58-- | js codegen using $http service from Angular
58-- | js codegen using $http service from Angular
59generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
59generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
60generateAngularJSWith ngOptions opts req = "\n" <>
60generateAngularJSWith ngOptions opts req = "\n" <>
@@ -74,7 +74,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
74 ++ map (view argName) queryparams
74 ++ map (view argName) queryparams
76 ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs
76 ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs
78 -- If we want to generate Top Level Function, they must depend on
78 -- If we want to generate Top Level Function, they must depend on
79 -- the $http service, if we generate a service, the functions will
79 -- the $http service, if we generate a service, the functions will
80 -- inherit this dependency from the service
80 -- inherit this dependency from the service
@@ -118,13 +118,13 @@ generateAngularJSWith ngOptions opts req = "\n" <>
118 else (moduleName opts) <> "."
118 else (moduleName opts) <> "."
120 hasNoModule = null (moduleName opts)
120 hasNoModule = null (moduleName opts)
122 hasService = not $ null (serviceName ngOptions)
122 hasService = not $ null (serviceName ngOptions)
124 fsep = if hasService then ":" else " ="
124 fsep = if hasService then ":" else " ="
126 fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
126 fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
128 method = req ^. reqMethod
128 method = req ^. reqMethod
129 url = if url' == "'" then "'/'" else url'
129 url = if url' == "'" then "'/'" else url'
130 url' = "'"
130 url' = "'"