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

泪湿孤枕 提交于 2019-12-25 04:21:42

问题


I'm trying to build a Python Unit Test File Template in PyCharm. The overall result I want to achieve is:

  1. A user creates a new file with my template, say "widget_builder.py"
  2. Inside the template I want to create the class name by taking the file name "widget_builder" and turning it into "WidgetBuilderTests"

It looks like I need to use a Live Template to manipulate the file template variable $FILE_NAME$?

How can I create a Live Template that given a passed in variable (in this case $FILE_NAME$), applies both the underscoresToCamelCase and capitalize functions to it?

If I declare the Template text as:

$CLASS_NAME$

...and then edit variables, how can I reference a passed in variable of '$FILE_NAME$'?

I'd imagine it to look something like this, but I just can't get it to work:

I'm sure there must be a way to do this, but I just can't quite wrap my head round it.

Is this possible? Thanks!

EDIT

I've got a bit further. If I define the template as this:

If I then use it, this happens:

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


回答1:


So your problem here is that $FILE_NAME$ is not a native variable in the live templates, merely an arbitrary name. What you actually want to be using is another function: fileNameWithoutExtension().

So your template would look something like:



来源:https://stackoverflow.com/questions/39660195/how-to-apply-more-than-one-function-to-a-passed-in-live-template-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!