[WebStorm] Create Meteor template (HTML and JS files) from undefined Spacebars template?
Hi,
Is it possible to create HTML and JS files based on templates I define (think of a Live Template) from an as yet undefined Meteor template? Since that probably doesn't make much sense, here's an example.
Let's say you're working with the following basic template.
<template name="header">
<h1>My App</h1>
<p>My App is so cool.</p>
</template>
Then you expand it by adding a new template to it.
<template name="header">
<h1>My App</h1>
<p>My App is so cool.</p>
{{> personalizedWelcome}}
</template>
I've now used a template that does not exist yet which means I have to create at least one HTML file and, most likely, a corresponding JS file.
Can I have WebStorm create those two files for me? It would make personalized_welcome.html and personalized_welcome.js.
The HTML file could be filled with:
<template name="personalizedWelcome">
</template>
And the JS file could be filled with:
Template.personalizedWelcome.helpers({
});
Template.personalizedWelcome.events({
});
p.s. I'm new to the community here but this forum REALLY needs a better editor with syntax highlighting. Yikes.
Please sign in to leave a comment.
You can't create new files using Live Templates. I can suggest to either create file templates (Settings/Editor/File and code templates) for your .js and .html files and add the corresponding files via File/New, or develop a custom intention to auto-create missing files.
The custom intentions must use the regular API for intentions. The intention classes need to implement the IntentionAction interface and to be registered using the <intentionAction> bean in the plugin.xml (http://confluence.jetbrains.com/display/IDEADEV/Developing+Custom+Language+Plugins+for+IntelliJ+IDEA)
See https://github.com/JetBrains/intellij-community/blob/master/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitIfIntention.java - custom intention example for Groovi
See also http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment, http://devnet.jetbrains.com/message/5298765http://devnet.jetbrains.com/message/5298765
Note: when creating file templates, you can use standard java String functions along with Apache Velocity StringUtils class methods (https://velocity.apache.org/engine/releases/velocity-1.7/apidocs/org/apache/velocity/util/StringUtils.html) to work with strings.
For example, the ugly code below will create 'personalizedWelcome' value from a file name 'personalized_welcome':
#set($name_remove_under = ${StringUtils.removeAndHump(${NAME})})
#set($name_low = $name_remove_under.substring(0,1).toLowerCase().concat($name_remove_under.substring(1,$name_remove_under.length())))
<template name="$name_low">
</template>