git.iko.soy/typeable/servant
on master help sign in
Rename functionRenamer and default to CameCase
commitef13160d8b6f81c6d8268e7d6433789f39249a4a authorFreezeboy <freezeboy@users.noreply.github.com> dateTue 28 Jul 2015, 16:41 (11 years ago) parentc01ad63
8 files changed+29−29
servant-js/examples/www/angular/index.html+2−2 servant-js/examples/www/jquery/index.html+3−3 servant-js/examples/www/vanilla/index.html+3−3 servant-js/src/Servant/JS.hs+3−3 servant-js/src/Servant/JS/Angular.hs+1−1 servant-js/src/Servant/JS/Internal.hs+15−15 servant-js/src/Servant/JS/JQuery.hs+1−1 servant-js/src/Servant/JS/Vanilla.hs+1−1
servant-js/examples/www/angular/index.html+2−2
@@ -21,11 +21,11 @@ counterApp.controller('CounterCtrl', ['$scope', '$http', '$interval', function (
2121 var publishCounter = function (response) { $scope.counter = response.value; };
2222
2323 $scope.getCounter = function() {
24− getcounter($http)
24+ getCounter($http)
2525 .success(publishCounter);
2626 }
2727 $scope.incCounter = function() {
28− postcounter($http)
28+ postCounter($http)
2929 .success(publishCounter);
3030 }
3131
servant-js/examples/www/jquery/index.html+3−3
@@ -17,11 +17,11 @@
1717<script type="text/javascript">
1818$(document).ready(function() {
1919 // we get the current value stored by the server when the page is loaded
20− getcounter(updateCounter, alert);
20+ getCounter(updateCounter, alert);
2121
2222 // we update the value every 1sec, in the same way
2323 window.setInterval(function() {
24− getcounter(updateCounter, alert);
24+ getCounter(updateCounter, alert);
2525 }, 1000);
2626});
2727
@@ -33,7 +33,7 @@ function updateCounter(response)
3333// when the button is clicked, ask the server to increase
3434// the value by one
3535$('#inc').click(function() {
36− postcounter(updateCounter, alert);
36+ postCounter(updateCounter, alert);
3737});
3838</script>
3939</body>
servant-js/examples/www/vanilla/index.html+3−3
@@ -16,11 +16,11 @@
1616<script type="text/javascript">
1717window.addEventListener('load', function() {
1818 // we get the current value stored by the server when the page is loaded
19− getcounter(updateCounter, alert);
19+ getCounter(updateCounter, alert);
2020
2121 // we update the value every 1sec, in the same way
2222 window.setInterval(function() {
23− getcounter(updateCounter, alert);
23+ getCounter(updateCounter, alert);
2424 }, 1000);
2525});
2626
@@ -32,7 +32,7 @@ function updateCounter(response)
3232// when the button is clicked, ask the server to increase
3333// the value by one
3434document.getElementById('inc').addEventListener('click', function() {
35− postcounter(updateCounter, alert);
35+ postCounter(updateCounter, alert);
3636});
3737</script>
3838</body>
servant-js/src/Servant/JS.hs+3−3
@@ -80,9 +80,9 @@ module Servant.JS
8080 , defCommonGeneratorOptions
8181
8282 , -- * Function renamers
83− concatRenamer
84− , snakeCaseRenamer
85− , camelCaseRenamer
83+ concatCase
84+ , snakeCase
85+ , camelCase
8686
8787 , -- * Vanilla Javascript code generation
8888 vanillaJS
servant-js/src/Servant/JS/Angular.hs+1−1
@@ -123,7 +123,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
123123
124124 fsep = if hasService then ":" else " ="
125125
126− fname = namespace <> (functionRenamer opts $ req ^. funcName)
126+ fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
127127
128128 method = req ^. reqMethod
129129 url = if url' == "'" then "'/'" else url'
servant-js/src/Servant/JS/Internal.hs+15−15
@@ -29,7 +29,7 @@ import Servant.API
2929-- customize the output
3030data CommonGeneratorOptions = CommonGeneratorOptions
3131 {
32− functionRenamer :: FunctionName -> String -- ^ function transforming function names
32+ functionNameBuilder :: FunctionName -> String -- ^ function generating function names
3333 , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
3434 , successCallback :: String -- ^ name of the callback parameter when the request was successful
3535 , errorCallback :: String -- ^ name of the callback parameter when the request reported an error
@@ -40,7 +40,7 @@ data CommonGeneratorOptions = CommonGeneratorOptions
4040--
4141-- @
4242-- > defCommonGeneratorOptions = CommonGeneratorOptions
43−-- > { functionRenamer = concatRenamer
43+-- > { functionNameBuilder = camelCase
4444-- > , requestBody = "body"
4545-- > , successCallback = "onSuccess"
4646-- > , errorCallback = "onError"
@@ -50,29 +50,29 @@ data CommonGeneratorOptions = CommonGeneratorOptions
5050defCommonGeneratorOptions :: CommonGeneratorOptions
5151defCommonGeneratorOptions = CommonGeneratorOptions
5252 {
53− functionRenamer = concatRenamer
53+ functionNameBuilder = camelCase
5454 , requestBody = "body"
5555 , successCallback = "onSuccess"
5656 , errorCallback = "onError"
5757 , moduleName = ""
5858 }
5959
60−-- | Function renamer that simply concat each part together
61−concatRenamer :: FunctionName -> String
62−concatRenamer = concat
60+-- | Function name builder that simply concat each part together
61+concatCase :: FunctionName -> String
62+concatCase = concat
6363
64−-- | Function renamer using the snake_case convention.
64+-- | Function name builder using the snake_case convention.
6565-- each part is separated by a single underscore character.
66−snakeCaseRenamer :: FunctionName -> String
67−snakeCaseRenamer = intercalate "_"
66+snakeCase :: FunctionName -> String
67+snakeCase = intercalate "_"
6868
69−-- | Function renamer using the CamelCase convention.
69+-- | Function name builder using the CamelCase convention.
7070-- each part begins with an upper case character.
71−camelCaseRenamer :: FunctionName -> String
72−camelCaseRenamer [] = ""
73−camelCaseRenamer (p:ps) = concat $ p : camelCaseRenamer' ps
74− where camelCaseRenamer' [] = []
75− camelCaseRenamer' (r:rs) = capitalize r : camelCaseRenamer' rs
71+camelCase :: FunctionName -> String
72+camelCase [] = ""
73+camelCase (p:ps) = concat $ p : camelCase' ps
74+ where camelCase' [] = []
75+ camelCase' (r:rs) = capitalize r : camelCase' rs
7676 capitalize [] = []
7777 capitalize (x:xs) = toUpper x : xs
7878
servant-js/src/Servant/JS/JQuery.hs+1−1
@@ -76,7 +76,7 @@ generateJQueryJSWith opts req = "\n" <>
7676 namespace = if null (moduleName opts)
7777 then "var "
7878 else (moduleName opts) <> "."
79− fname = namespace <> (functionRenamer opts $ req ^. funcName)
79+ fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
8080
8181 method = req ^. reqMethod
8282 url = if url' == "'" then "'/'" else url'
servant-js/src/Servant/JS/Vanilla.hs+1−1
@@ -83,7 +83,7 @@ generateVanillaJSWith opts req = "\n" <>
8383 namespace = if null (moduleName opts)
8484 then "var "
8585 else (moduleName opts) <> "."
86− fname = namespace <> (functionRenamer opts $ req ^. funcName)
86+ fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
8787
8888 method = req ^. reqMethod
8989 url = if url' == "'" then "'/'" else url'