git.iko.soy/typeable/servant
on master help sign in
Rename functionRenamer and default to CameCase
ef13160Freezeboy
servant-js/examples/www/angular/index.html+2−2
@@ -21,11 +21,11 @@ counterApp.controller('CounterCtrl', ['$scope', '$http', '$interval', function (
21 var publishCounter = function (response) { $scope.counter = response.value; };
21 var publishCounter = function (response) { $scope.counter = response.value; };
22
22
23 $scope.getCounter = function() {
23 $scope.getCounter = function() {
24− getcounter($http)
24+ getCounter($http)
25 .success(publishCounter);
25 .success(publishCounter);
26 }
26 }
27 $scope.incCounter = function() {
27 $scope.incCounter = function() {
28− postcounter($http)
28+ postCounter($http)
29 .success(publishCounter);
29 .success(publishCounter);
30 }
30 }
31
31
servant-js/examples/www/jquery/index.html+3−3
@@ -17,11 +17,11 @@
17<script type="text/javascript">
17<script type="text/javascript">
18$(document).ready(function() {
18$(document).ready(function() {
19 // we get the current value stored by the server when the page is loaded
19 // we get the current value stored by the server when the page is loaded
20− getcounter(updateCounter, alert);
20+ getCounter(updateCounter, alert);
21
21
22 // we update the value every 1sec, in the same way
22 // we update the value every 1sec, in the same way
23 window.setInterval(function() {
23 window.setInterval(function() {
24− getcounter(updateCounter, alert);
24+ getCounter(updateCounter, alert);
25 }, 1000);
25 }, 1000);
26});
26});
27
27
@@ -33,7 +33,7 @@ function updateCounter(response)
33// when the button is clicked, ask the server to increase
33// when the button is clicked, ask the server to increase
34// the value by one
34// the value by one
35$('#inc').click(function() {
35$('#inc').click(function() {
36− postcounter(updateCounter, alert);
36+ postCounter(updateCounter, alert);
37});
37});
38</script>
38</script>
39</body>
39</body>
servant-js/examples/www/vanilla/index.html+3−3
@@ -16,11 +16,11 @@
16<script type="text/javascript">
16<script type="text/javascript">
17window.addEventListener('load', function() {
17window.addEventListener('load', function() {
18 // we get the current value stored by the server when the page is loaded
18 // we get the current value stored by the server when the page is loaded
19− getcounter(updateCounter, alert);
19+ getCounter(updateCounter, alert);
20
20
21 // we update the value every 1sec, in the same way
21 // we update the value every 1sec, in the same way
22 window.setInterval(function() {
22 window.setInterval(function() {
23− getcounter(updateCounter, alert);
23+ getCounter(updateCounter, alert);
24 }, 1000);
24 }, 1000);
25});
25});
26
26
@@ -32,7 +32,7 @@ function updateCounter(response)
32// when the button is clicked, ask the server to increase
32// when the button is clicked, ask the server to increase
33// the value by one
33// the value by one
34document.getElementById('inc').addEventListener('click', function() {
34document.getElementById('inc').addEventListener('click', function() {
35− postcounter(updateCounter, alert);
35+ postCounter(updateCounter, alert);
36});
36});
37</script>
37</script>
38</body>
38</body>
servant-js/src/Servant/JS.hs+3−3
@@ -80,9 +80,9 @@ module Servant.JS
80 , defCommonGeneratorOptions
80 , defCommonGeneratorOptions
81
81
82 , -- * Function renamers
82 , -- * Function renamers
83− concatRenamer
83+ concatCase
84− , snakeCaseRenamer
84+ , snakeCase
85− , camelCaseRenamer
85+ , camelCase
86
86
87 , -- * Vanilla Javascript code generation
87 , -- * Vanilla Javascript code generation
88 vanillaJS
88 vanillaJS
servant-js/src/Servant/JS/Angular.hs+1−1
@@ -123,7 +123,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
123
123
124 fsep = if hasService then ":" else " ="
124 fsep = if hasService then ":" else " ="
125
125
126− fname = namespace <> (functionRenamer opts $ req ^. funcName)
126+ fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
127
127
128 method = req ^. reqMethod
128 method = req ^. reqMethod
129 url = if url' == "'" then "'/'" else url'
129 url = if url' == "'" then "'/'" else url'
servant-js/src/Servant/JS/Internal.hs+15−15
@@ -29,7 +29,7 @@ import Servant.API
29-- customize the output
29-- customize the output
30data CommonGeneratorOptions = CommonGeneratorOptions
30data CommonGeneratorOptions = CommonGeneratorOptions
31 {
31 {
32− functionRenamer :: FunctionName -> String -- ^ function transforming function names
32+ functionNameBuilder :: FunctionName -> String -- ^ function generating function names
33 , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
33 , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
34 , successCallback :: String -- ^ name of the callback parameter when the request was successful
34 , successCallback :: String -- ^ name of the callback parameter when the request was successful
35 , errorCallback :: String -- ^ name of the callback parameter when the request reported an error
35 , errorCallback :: String -- ^ name of the callback parameter when the request reported an error
@@ -40,7 +40,7 @@ data CommonGeneratorOptions = CommonGeneratorOptions
40--
40--
41-- @
41-- @
42-- > defCommonGeneratorOptions = CommonGeneratorOptions
42-- > defCommonGeneratorOptions = CommonGeneratorOptions
43−-- > { functionRenamer = concatRenamer
43+-- > { functionNameBuilder = camelCase
44-- > , requestBody = "body"
44-- > , requestBody = "body"
45-- > , successCallback = "onSuccess"
45-- > , successCallback = "onSuccess"
46-- > , errorCallback = "onError"
46-- > , errorCallback = "onError"
@@ -50,29 +50,29 @@ data CommonGeneratorOptions = CommonGeneratorOptions
50defCommonGeneratorOptions :: CommonGeneratorOptions
50defCommonGeneratorOptions :: CommonGeneratorOptions
51defCommonGeneratorOptions = CommonGeneratorOptions
51defCommonGeneratorOptions = CommonGeneratorOptions
52 {
52 {
53− functionRenamer = concatRenamer
53+ functionNameBuilder = camelCase
54 , requestBody = "body"
54 , requestBody = "body"
55 , successCallback = "onSuccess"
55 , successCallback = "onSuccess"
56 , errorCallback = "onError"
56 , errorCallback = "onError"
57 , moduleName = ""
57 , moduleName = ""
58 }
58 }
59
59
60−-- | Function renamer that simply concat each part together
60+-- | Function name builder that simply concat each part together
61−concatRenamer :: FunctionName -> String
61+concatCase :: FunctionName -> String
62−concatRenamer = concat
62+concatCase = concat
63
63
64−-- | Function renamer using the snake_case convention.
64+-- | Function name builder using the snake_case convention.
65-- each part is separated by a single underscore character.
65-- each part is separated by a single underscore character.
66−snakeCaseRenamer :: FunctionName -> String
66+snakeCase :: FunctionName -> String
67−snakeCaseRenamer = intercalate "_"
67+snakeCase = intercalate "_"
68
68
69−-- | Function renamer using the CamelCase convention.
69+-- | Function name builder using the CamelCase convention.
70-- each part begins with an upper case character.
70-- each part begins with an upper case character.
71−camelCaseRenamer :: FunctionName -> String
71+camelCase :: FunctionName -> String
72−camelCaseRenamer [] = ""
72+camelCase [] = ""
73−camelCaseRenamer (p:ps) = concat $ p : camelCaseRenamer' ps
73+camelCase (p:ps) = concat $ p : camelCase' ps
74− where camelCaseRenamer' [] = []
74+ where camelCase' [] = []
75− camelCaseRenamer' (r:rs) = capitalize r : camelCaseRenamer' rs
75+ camelCase' (r:rs) = capitalize r : camelCase' rs
76 capitalize [] = []
76 capitalize [] = []
77 capitalize (x:xs) = toUpper x : xs
77 capitalize (x:xs) = toUpper x : xs
78
78
servant-js/src/Servant/JS/JQuery.hs+1−1
@@ -76,7 +76,7 @@ generateJQueryJSWith opts req = "\n" <>
76 namespace = if null (moduleName opts)
76 namespace = if null (moduleName opts)
77 then "var "
77 then "var "
78 else (moduleName opts) <> "."
78 else (moduleName opts) <> "."
79− fname = namespace <> (functionRenamer opts $ req ^. funcName)
79+ fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
80
80
81 method = req ^. reqMethod
81 method = req ^. reqMethod
82 url = if url' == "'" then "'/'" else url'
82 url = if url' == "'" then "'/'" else url'
servant-js/src/Servant/JS/Vanilla.hs+1−1
@@ -83,7 +83,7 @@ generateVanillaJSWith opts req = "\n" <>
83 namespace = if null (moduleName opts)
83 namespace = if null (moduleName opts)
84 then "var "
84 then "var "
85 else (moduleName opts) <> "."
85 else (moduleName opts) <> "."
86− fname = namespace <> (functionRenamer opts $ req ^. funcName)
86+ fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
87
87
88 method = req ^. reqMethod
88 method = req ^. reqMethod
89 url = if url' == "'" then "'/'" else url'
89 url = if url' == "'" then "'/'" else url'