I have trouble creating a JavaScript template in WebStorm, which is using velocity template engine.
The final document I am trying to get looks like this:
app.service('Name', ['$http', function($http) {
var singularUrlbase = apiurl + 'SingularName';
var pluralUrlbase = apiurl + 'PluralName';
this.get = function(id){
return $http.get( singularUrlBase + id );
}
}
I am trying with this template:
#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = "singularUrlBase + '/' + s.Id")
app.service('${NAME}', ['$http', function($http) {
var pluralUrlBase = apiurl + '$pluralName';
var singularUrlBase = apiurl + '$singularName';
this.get = function(id) {
return $http.get( $url1 );
};
}
The problems are:
return $http.get ( $url1 )
instead of return $http.get( singularUrlBase + id );
$http
, WebStorm is asking me to setup $http variable, but I don't want to.To escape a $
symbol in jetbrains apps templates, you need to write ${DS}
as shown in the docs
Should look like this:
#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = 'pluralUrlBase + "/" + id')
app.service('${NAME}', ['${DS}http', function(${DS}http) {
var pluralUrlBase = apiurl + '$pluralName';
var singularUrlBase = apiurl + '$singularName';
this.get = function(id) {
if (this.get > 1) {
return ${DS}http.get( $url1 );
}
else {
return ${DS}http.get( $url2 );
}
}
}]);
file name: young_people
pluralName: child
singularName: children
app.service('young_people', ['$http', function ($http) {
var pluralUrlBase = apiurl + 'child';
var singularUrlBase = apiurl + 'children';
this.get = function (id) {
if (this.get > 1) {
return $http.get(singularUrlBase + "/" + id);
}
else {
return $http.get(pluralUrlBase + "/" + id);
}
}
}]);
Note: your syntax was a bit wrong, I fixed the two last lines ;).