Webstorm code templates: insert class name and name/email in js files

Hi,

 

I'm trying to set a template for js files like below:

 

/*
* Created by ${MyName} <${MyEmail}> on ${DATE}
*/
import BaseObject from "@shared/BaseObject.js";

export default class ${CLASS_NAME} extends BaseObject{
}

 

My intention is that CLASS_NAME would be derived from the file name and MyName + MyEmail to be globally defined in the IDE itself, but I can't quite find how to accomplish that.

I saw Vue.js template has this line: "name: "${COMPONENT_NAME}"" where COMPONENT_NAME resolves from the file name, but I can't find how I can define my custom variable to behave in the same way.

So far I tried FILE_NAME but that gave wired result as it was trying to include extension delimited by a new line.

Also I'm not sure how do I define my name and email variables globally? (username doesn't work here as it doesn't represent my full name)

 

Would appreciate any input. Thanks!

 

3 comments
Comment actions Permalink

>So far I tried FILE_NAME but that gave wired result as it was trying to include extension delimited by a new line.

Try using $NAME

 

>Also I'm not sure how do I define my name and email variables globally?

you can only do this right in template using #set:

#set( $MyEmail = "me@gmail.com")
/*
* Created by ${USER} <${MyEmail}> on ${DATE}
*/
import BaseObject from "@shared/BaseObject.js";

export default class $NAME extends BaseObject{
}

1
Comment actions Permalink

Thanks Elena! $NAME worked here.

 

Also thanks for the #set - this is what I was doing but was hoping I could specify it in one place to reuse in all templates.

 

Thanks again for your help!

0
Comment actions Permalink

Hi there,

You may also try the File Template Variables plugin for your custom shared variables: https://plugins.jetbrains.com/plugin/7398-file-template-variables

1

Please sign in to leave a comment.