具有预定义变量列表和添加参数的复杂逻辑的实时模板

Live template with predefined list of variable and complex logic of add parameters

我想为生成 fa-icons 创建实时模板。例如下一个

<i class="ace-icon fa fa-arrow-right icon-on-right align-top bigger-125"></i>
<i class="ace-icon fa fa-arrow-left icon-on-left bigger-140"></i>
<i class="ace-icon fa fa-times icon-on-right"></i>
<i class="fa fa-bars"></i>

下一个要生成的规则:

  1. 生成的最小模板为<i class="fa fa-$ICON_NAME$"></i>
  2. 需要有能力添加 classes ace-icon 并且如果添加设置 icon-on-[right|left]
  3. 如果 $ICON_NAME$fa-arrow-[right|left] 并且设置 ace-icon 设置方向部分,因为它在 icon-on-[right|left]
  4. 中设置
  5. 能够选择性地编写额外的 classes,例如 align-top
  6. 如果在 bigger-$SIZE$ 中设置 $SIZE$ 添加这个 class 否则跳过
  7. 必须预定义 $ICON_NAME$$SIZE$ 的选项。

假定的实时模板

<i class="$ACE_CLASS$ fa fa-$ICON_NAME$ icon-on-$ACE_DIRECTION$ $OPTIONAL_CLASS$ bigger-$SIZE$"></i>

我的问题:

  1. 如何设置 $ICON_NAME$$ACE_DIRECTION$$SIZE$ 的预定义选项列表?
  2. 如果大小为空,如何不渲染 bigger-$SIZE$
  3. 如何检查$ICON_NAME$是否包含$ACE_DIRECTION$并切换?
  4. 如何仅在 $ACE_CLASS$ 为真时渲染 icon-on-$ACE_DIRECTION$bigger-$SIZE$

How to setup predefined option list for $ICON_NAME$, $ACE_DIRECTION$ and $SIZE$?

enum(sCompletionString1,sCompletionString2,...) -- https://www.jetbrains.com/help/phpstorm/2017.1/live-template-variables.html#predefined_functions


How to not render bigger-$SIZE$ if size is empty?

不可能 -- 实时模板没有 conditions or loops

我可能只建议再设置一个 enum,其中包含所有 bigger-XXX 个选项,包括空选项(基本上 - 而不是 bigger-$SIZE$$BIGGER-SIZE$)。

2017.2 应该有 GroovyScript support -- maybe you can then code your own Live Template function or something (see this link 一些文档链接)...


How check if $ICON_NAME$ contains $ACE_DIRECTION$ and switch it?

同上:不可能 -- 实时模板没有条件。


How to render icon-on-$ACE_DIRECTION$ and bigger-$SIZE$ only if $ACE_CLASS$ is true?

同上:不可能 -- 实时模板没有条件。

您可以创建多个涵盖几个不同场景的实时模板(当然,它们会有不同的缩写:例如,fai 代表一种情况,fai2 代表另一种情况等)。