@@ -5,23 +5,29 @@ import Control.Lens
5import Data.List
5import Data.List
6import Data.Monoid
6import Data.Monoid
8−data AngularOptions = AngularOptions {
8+data AngularOptions = AngularOptions
9− serviceName :: String,
9+ { serviceName :: String -- ^ When generating code with wrapInService,
10+ -- ^ name of the service to generate
10− prologue :: String -> String -> String,
11+ , prologue :: String -> String -> String -- ^ beginning of the service definition
11− epilogue :: String
12+ , epilogue :: String -- ^ end of the service definition
14defAngularOptions :: AngularOptions
15defAngularOptions :: AngularOptions
15−defAngularOptions = AngularOptions {
16+defAngularOptions = AngularOptions
16− serviceName = "",
17+ { serviceName = ""
17− prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n"
18+ , prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n"
18− <> " return ({",
19+ <> " return ({"
19− epilogue = "});\n});\n"
20+ , epilogue = "});\n});\n"
23+-- | Instead of simply generating top level functions, generates a service instance
24+-- on which your controllers can depend to access your API
25+-- This variant uses default AngularOptions
22wrapInService :: AngularOptions -> [AjaxReq] -> String
26wrapInService :: AngularOptions -> [AjaxReq] -> String
23wrapInService ngOpts reqs = wrapInServiceWith ngOpts defCommonGeneratorOptions reqs
27wrapInService ngOpts reqs = wrapInServiceWith ngOpts defCommonGeneratorOptions reqs
29+-- | Instead of simply generating top level functions, generates a service instance
30+-- on which your controllers can depend to access your API
25wrapInServiceWith :: AngularOptions -> CommonGeneratorOptions -> [AjaxReq] -> String
31wrapInServiceWith :: AngularOptions -> CommonGeneratorOptions -> [AjaxReq] -> String
26wrapInServiceWith ngOpts opts reqs =
32wrapInServiceWith ngOpts opts reqs =
27 ((prologue ngOpts) svc mName)
33 ((prologue ngOpts) svc mName)
@@ -34,10 +40,11 @@ wrapInServiceWith ngOpts opts reqs =
34 then "app."
40 then "app."
35 else (moduleName opts) <> "."
41 else (moduleName opts) <> "."
43+-- js codegen using $http service from Angular using default options
37generateAngularJS :: AngularOptions -> AjaxReq -> String
44generateAngularJS :: AngularOptions -> AjaxReq -> String
38generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions
45generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions
40−-- js codegen using $http
47+-- js codegen using $http service from Angular
41generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
48generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
42generateAngularJSWith ngOptions opts req = "\n" <>
49generateAngularJSWith ngOptions opts req = "\n" <>
43 fname <> fsep <> " function(" <> argsStr <> ")\n"
50 fname <> fsep <> " function(" <> argsStr <> ")\n"
@@ -105,7 +112,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
106 fsep = if hasService then ":" else " ="
113 fsep = if hasService then ":" else " ="
108− fname = namespace <> (functionName opts $ req ^. funcName)
115+ fname = namespace <> (functionRenamer opts $ req ^. funcName)
110 method = req ^. reqMethod
117 method = req ^. reqMethod
111 url = if url' == "'" then "'/'" else url'
118 url = if url' == "'" then "'/'" else url'
@@ -118,4 +125,4 @@ generateAngularJSWith ngOptions opts req = "\n" <>
119 queryArgs = if null queryparams
126 queryArgs = if null queryparams
121− else " + '?" ++ jsParams queryparams
128+ else " + '?" ++ jsParams queryparams