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