How to apply more than one function to the passed in a template variable?

I am trying to create a Python Unit Test File Template in PyCharm. The overall result I want to achieve is:

  • The user creates a new file with my template, for example, " widget_builder.py"
  • Inside the template, I want to create a class name by taking the file name " widget_builder" and turning it into " WidgetBuilderTests"

Looks like I need to use Live Template to control the file template variable $FILE_NAME$?

How to create a Live Template, which is to pass a variable (in this case $FILE_NAME$), applies the function underscoresToCamelCaseand capitalize?

If I declare the template text as:

$CLASS_NAME$

... and then edit the variables, how can I refer to the passed variable '$ FILE_NAME $'?

I would suggest that it looks something like this, but I just can't get it to work:

Example

I'm sure there must be a way to do this, but I just can't get around it.

Is it possible? Thank!

EDIT

I have some more. If I define a template as follows:

enter image description here

If I use it, this will happen:

enter image description here

So, the end result $CLASS_NAME$( WidgetBuilder) on the left is what I want, but I don't want $FILE_NAME$( widget_builder) to be there as soon as I hit return.

0
source share
1 answer

, , $FILE_NAME$ , . , , - : fileNameWithoutExtension().

, : enter image description here

+1

Source: https://habr.com/ru/post/1655821/


All Articles