Rename functionRenamer and default to CameCase
This commit is contained in:
parent
c01ad63112
commit
ef13160d8b
8 changed files with 29 additions and 29 deletions
|
@ -21,11 +21,11 @@ counterApp.controller('CounterCtrl', ['$scope', '$http', '$interval', function (
|
|||
var publishCounter = function (response) { $scope.counter = response.value; };
|
||||
|
||||
$scope.getCounter = function() {
|
||||
getcounter($http)
|
||||
getCounter($http)
|
||||
.success(publishCounter);
|
||||
}
|
||||
$scope.incCounter = function() {
|
||||
postcounter($http)
|
||||
postCounter($http)
|
||||
.success(publishCounter);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
// we get the current value stored by the server when the page is loaded
|
||||
getcounter(updateCounter, alert);
|
||||
getCounter(updateCounter, alert);
|
||||
|
||||
// we update the value every 1sec, in the same way
|
||||
window.setInterval(function() {
|
||||
getcounter(updateCounter, alert);
|
||||
getCounter(updateCounter, alert);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
|
@ -33,7 +33,7 @@ function updateCounter(response)
|
|||
// when the button is clicked, ask the server to increase
|
||||
// the value by one
|
||||
$('#inc').click(function() {
|
||||
postcounter(updateCounter, alert);
|
||||
postCounter(updateCounter, alert);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
<script type="text/javascript">
|
||||
window.addEventListener('load', function() {
|
||||
// we get the current value stored by the server when the page is loaded
|
||||
getcounter(updateCounter, alert);
|
||||
getCounter(updateCounter, alert);
|
||||
|
||||
// we update the value every 1sec, in the same way
|
||||
window.setInterval(function() {
|
||||
getcounter(updateCounter, alert);
|
||||
getCounter(updateCounter, alert);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
|
@ -32,7 +32,7 @@ function updateCounter(response)
|
|||
// when the button is clicked, ask the server to increase
|
||||
// the value by one
|
||||
document.getElementById('inc').addEventListener('click', function() {
|
||||
postcounter(updateCounter, alert);
|
||||
postCounter(updateCounter, alert);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -80,9 +80,9 @@ module Servant.JS
|
|||
, defCommonGeneratorOptions
|
||||
|
||||
, -- * Function renamers
|
||||
concatRenamer
|
||||
, snakeCaseRenamer
|
||||
, camelCaseRenamer
|
||||
concatCase
|
||||
, snakeCase
|
||||
, camelCase
|
||||
|
||||
, -- * Vanilla Javascript code generation
|
||||
vanillaJS
|
||||
|
|
|
@ -123,7 +123,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
|
|||
|
||||
fsep = if hasService then ":" else " ="
|
||||
|
||||
fname = namespace <> (functionRenamer opts $ req ^. funcName)
|
||||
fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
|
||||
|
||||
method = req ^. reqMethod
|
||||
url = if url' == "'" then "'/'" else url'
|
||||
|
|
|
@ -29,7 +29,7 @@ import Servant.API
|
|||
-- customize the output
|
||||
data CommonGeneratorOptions = CommonGeneratorOptions
|
||||
{
|
||||
functionRenamer :: FunctionName -> String -- ^ function transforming function names
|
||||
functionNameBuilder :: FunctionName -> String -- ^ function generating function names
|
||||
, requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
|
||||
, successCallback :: String -- ^ name of the callback parameter when the request was successful
|
||||
, errorCallback :: String -- ^ name of the callback parameter when the request reported an error
|
||||
|
@ -40,7 +40,7 @@ data CommonGeneratorOptions = CommonGeneratorOptions
|
|||
--
|
||||
-- @
|
||||
-- > defCommonGeneratorOptions = CommonGeneratorOptions
|
||||
-- > { functionRenamer = concatRenamer
|
||||
-- > { functionNameBuilder = camelCase
|
||||
-- > , requestBody = "body"
|
||||
-- > , successCallback = "onSuccess"
|
||||
-- > , errorCallback = "onError"
|
||||
|
@ -50,29 +50,29 @@ data CommonGeneratorOptions = CommonGeneratorOptions
|
|||
defCommonGeneratorOptions :: CommonGeneratorOptions
|
||||
defCommonGeneratorOptions = CommonGeneratorOptions
|
||||
{
|
||||
functionRenamer = concatRenamer
|
||||
functionNameBuilder = camelCase
|
||||
, requestBody = "body"
|
||||
, successCallback = "onSuccess"
|
||||
, errorCallback = "onError"
|
||||
, moduleName = ""
|
||||
}
|
||||
|
||||
-- | Function renamer that simply concat each part together
|
||||
concatRenamer :: FunctionName -> String
|
||||
concatRenamer = concat
|
||||
-- | Function name builder that simply concat each part together
|
||||
concatCase :: FunctionName -> String
|
||||
concatCase = concat
|
||||
|
||||
-- | Function renamer using the snake_case convention.
|
||||
-- | Function name builder using the snake_case convention.
|
||||
-- each part is separated by a single underscore character.
|
||||
snakeCaseRenamer :: FunctionName -> String
|
||||
snakeCaseRenamer = intercalate "_"
|
||||
snakeCase :: FunctionName -> String
|
||||
snakeCase = intercalate "_"
|
||||
|
||||
-- | Function renamer using the CamelCase convention.
|
||||
-- | Function name builder using the CamelCase convention.
|
||||
-- each part begins with an upper case character.
|
||||
camelCaseRenamer :: FunctionName -> String
|
||||
camelCaseRenamer [] = ""
|
||||
camelCaseRenamer (p:ps) = concat $ p : camelCaseRenamer' ps
|
||||
where camelCaseRenamer' [] = []
|
||||
camelCaseRenamer' (r:rs) = capitalize r : camelCaseRenamer' rs
|
||||
camelCase :: FunctionName -> String
|
||||
camelCase [] = ""
|
||||
camelCase (p:ps) = concat $ p : camelCase' ps
|
||||
where camelCase' [] = []
|
||||
camelCase' (r:rs) = capitalize r : camelCase' rs
|
||||
capitalize [] = []
|
||||
capitalize (x:xs) = toUpper x : xs
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ generateJQueryJSWith opts req = "\n" <>
|
|||
namespace = if null (moduleName opts)
|
||||
then "var "
|
||||
else (moduleName opts) <> "."
|
||||
fname = namespace <> (functionRenamer opts $ req ^. funcName)
|
||||
fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
|
||||
|
||||
method = req ^. reqMethod
|
||||
url = if url' == "'" then "'/'" else url'
|
||||
|
|
|
@ -83,7 +83,7 @@ generateVanillaJSWith opts req = "\n" <>
|
|||
namespace = if null (moduleName opts)
|
||||
then "var "
|
||||
else (moduleName opts) <> "."
|
||||
fname = namespace <> (functionRenamer opts $ req ^. funcName)
|
||||
fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
|
||||
|
||||
method = req ^. reqMethod
|
||||
url = if url' == "'" then "'/'" else url'
|
||||
|
|
Loading…
Reference in a new issue