如何将多个函数应用于传入的实时模板变量? [英] How to apply more than one function to a passed in live template variable?
问题描述
我正在尝试在PyCharm中构建一个Python单元测试文件模板。我想要实现的总体结果是:
I'm trying to build a Python Unit Test File Template in PyCharm. The overall result I want to achieve is:
- 用户使用我的模板创建一个新文件,例如
widget_builder .py
- 在模板中我想通过取文件名
widget_builder
并将其变为WidgetBuilderTests
- A user creates a new file with my template, say "
widget_builder.py
" - Inside the template I want to create the class name by taking the file name "
widget_builder
" and turning it into "WidgetBuilderTests
"
看起来我需要使用实时模板来操作文件模板变量 $ FILE_NAME $
?
It looks like I need to use a Live Template to manipulate the file template variable $FILE_NAME$
?
如何创建实时模板给定传入的变量(在本例中为 $ FILE_NAME $
),同时应用 underscoresToCamelCase
和大写
函数吗?
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$
...然后编辑变量,我如何引用传入的'$ FILE_NAME $'变量?
...and then edit variables, how can I reference a passed in variable of '$FILE_NAME$'?
我想它看起来像这样,但我无法得到它到w ork:
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.
这可能吗?谢谢!
编辑
我还有一点。如果我将模板定义为:
I've got a bit further. If I define the template as this:
如果我然后使用它,会发生这种情况:
If I then use it, this happens:
左边的 $ CLASS_NAME $
( WidgetBuilder
)的最终结果是我想要的,但我不知道我希望 $ FILE_NAME $
( widget_builder
)在我点击返回时就在那里。
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.
推荐答案
所以你的问题是 $ FILE_NAME $
不是实时模板中的原生变量,只是一个任意的名字。你真正想要使用的是另一个功能: fileNameWithoutExtension()
。
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:
这篇关于如何将多个函数应用于传入的实时模板变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!