@@ -5,23 +5,29 @@ import Control.Lens
55import Data.List
66import Data.Monoid
77
8−data AngularOptions = AngularOptions {
9− serviceName :: String,
10− prologue :: String -> String -> String,
11− epilogue :: String
12− }
8+data AngularOptions = AngularOptions
9+ { serviceName :: String -- ^ When generating code with wrapInService,
10+ -- ^ name of the service to generate
11+ , prologue :: String -> String -> String -- ^ beginning of the service definition
12+ , epilogue :: String -- ^ end of the service definition
13+ }
1314
1415defAngularOptions :: AngularOptions
15−defAngularOptions = AngularOptions {
16− serviceName = "",
17− prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n"
18− <> " return ({",
19− epilogue = "});\n});\n"
16+defAngularOptions = AngularOptions
17+ { serviceName = ""
18+ , prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n"
19+ <> " return ({"
20+ , epilogue = "});\n});\n"
2021 }
2122
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
2226wrapInService :: AngularOptions -> [AjaxReq] -> String
2327wrapInService ngOpts reqs = wrapInServiceWith ngOpts defCommonGeneratorOptions reqs
2428
29+-- | Instead of simply generating top level functions, generates a service instance
30+-- on which your controllers can depend to access your API
2531wrapInServiceWith :: AngularOptions -> CommonGeneratorOptions -> [AjaxReq] -> String
2632wrapInServiceWith ngOpts opts reqs =
2733 ((prologue ngOpts) svc mName)
@@ -34,10 +40,11 @@ wrapInServiceWith ngOpts opts reqs =
3440 then "app."
3541 else (moduleName opts) <> "."
3642
43+-- js codegen using $http service from Angular using default options
3744generateAngularJS :: AngularOptions -> AjaxReq -> String
3845generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions
3946
40−-- js codegen using $http
47+-- js codegen using $http service from Angular
4148generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
4249generateAngularJSWith ngOptions opts req = "\n" <>
4350 fname <> fsep <> " function(" <> argsStr <> ")\n"
@@ -105,7 +112,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
105112
106113 fsep = if hasService then ":" else " ="
107114
108− fname = namespace <> (functionName opts $ req ^. funcName)
115+ fname = namespace <> (functionRenamer opts $ req ^. funcName)
109116
110117 method = req ^. reqMethod
111118 url = if url' == "'" then "'/'" else url'
@@ -118,4 +125,4 @@ generateAngularJSWith ngOptions opts req = "\n" <>
118125
119126 queryArgs = if null queryparams
120127 then ""
121− else " + '?" ++ jsParams queryparams
128+ else " + '?" ++ jsParams queryparams