Add title case macro docs IJSDK-698

This commit is contained in:
JohnHake 2020-03-17 18:38:07 -07:00
parent b48295a48b
commit 410c40f937
4 changed files with 6 additions and 14 deletions

View File

@ -16,12 +16,9 @@ repositories {
// See https://github.com/JetBrains/gradle-intellij-plugin/ // See https://github.com/JetBrains/gradle-intellij-plugin/
intellij { intellij {
version 'LATEST-EAP-SNAPSHOT' version '201-EAP-SNAPSHOT'
// Sets <idea-version> in plugin.xml
sameSinceUntilBuild = true sameSinceUntilBuild = true
} }
patchPluginXml { patchPluginXml {
// Sets <version> in plugin.xml
version = project.version version = project.version
} }

View File

@ -8,7 +8,6 @@ import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class TitleCaseMacro extends MacroBase { public class TitleCaseMacro extends MacroBase {
public TitleCaseMacro() { public TitleCaseMacro() {
super("titleCase", "titleCase(String)"); super("titleCase", "titleCase(String)");
} }
@ -22,9 +21,11 @@ public class TitleCaseMacro extends MacroBase {
@Override @Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) { protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
// Retrieve the text from the macro or selection, if any is available.
String text = getTextResult(params, context, true); String text = getTextResult(params, context, true);
if (text != null) { if (text != null) {
if (text.length() > 0) { if (text.length() > 0) {
// Capitalize the start of every word
text = StringUtil.toTitleCase(text); text = StringUtil.toTitleCase(text);
} }
return new TextResult(text); return new TextResult(text);

View File

@ -2,15 +2,12 @@
<idea-plugin> <idea-plugin>
<!-- Unique id for this plugin. Must stay constant for the life of the plugin. -->
<id>org.intellij.sdk.liveTemplates</id> <id>org.intellij.sdk.liveTemplates</id>
<!-- Text to display as name on Preferences/Settings | Plugin page --> <!-- Text to display as name on Preferences/Settings | Plugin page -->
<name>SDK: Live Templates Sample Project</name> <name>SDK: Live Templates Sample Project</name>
<!-- The <version> of this plugin is set by patchPluginXml.version in build.gradle -->
<!-- The <idea-version> compatibility of this plugin is set by intellij.sameSinceUntilBuild in build.gradle -->
<!-- Product and plugin compatibility requirements --> <!-- Product and plugin compatibility requirements -->
<depends>com.intellij.modules.lang</depends> <depends>com.intellij.modules.lang</depends>
@ -34,11 +31,8 @@
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor> <vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
<extensions defaultExtensionNs="com.intellij"> <extensions defaultExtensionNs="com.intellij">
<!-- Declare where the IntelliJ Platform should look to find XML-based Live Templates --> <defaultLiveTemplates file="/liveTemplates/Markdown.xml"/>
<defaultLiveTemplates file="/liveTemplates/Markdown"/>
<!-- Declare the implementation for determining the context for applying Live Templates -->
<liveTemplateContext implementation="org.intellij.sdk.liveTemplates.MarkdownContext"/> <liveTemplateContext implementation="org.intellij.sdk.liveTemplates.MarkdownContext"/>
<!-- Declare implementation-based Live Template -->
<liveTemplateMacro implementation="org.intellij.sdk.liveTemplates.TitleCaseMacro"/> <liveTemplateMacro implementation="org.intellij.sdk.liveTemplates.TitleCaseMacro"/>
</extensions> </extensions>

View File

@ -15,7 +15,7 @@
description="SDK: Convert to title case" description="SDK: Convert to title case"
toReformat="true" toReformat="true"
toShortenFQNames="false"> toShortenFQNames="false">
<variable name="TITLE" expression="titleCase(SELECTION)" defaultValue="the quick brown fox jumped over the lazy dog" alwaysStopAt="true" /> <variable name="TITLE" expression="titleCase(SELECTION)" defaultValue="the quick brown fox" alwaysStopAt="true" />
<context> <context>
<option name="MARKDOWN" value="true" /> <option name="MARKDOWN" value="true" />
</context> </context>