Skip to content

Instantly share code, notes, and snippets.

@russellf9
Last active August 7, 2016 19:51
Show Gist options
  • Save russellf9/3fb4fbbf0a24ddcbdb58718126370bae to your computer and use it in GitHub Desktop.
Save russellf9/3fb4fbbf0a24ddcbdb58718126370bae to your computer and use it in GitHub Desktop.
A Webstorm Live Template, which generates an Angular 1 Directve with a Controller.
<template name="ngsd" value="(function () {&#10;&#10; 'use strict';&#10;&#10;&#10; /**&#10; *&#10; * @author $name$&#10; * @date $date$&#10; *&#10; * @name&#10; * $module$:$directiveName$&#10; *&#10; * @param {data} $input1$ An input two-way binding&#10; * @param {function} $function1$ An output function&#10; * &#10; * @description $description$&#10; * Trying to follow the style guidelines from: {https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#angular-docs Angular 1 Style Guide &lt;br&gt;&#10; * @example&#10; &lt;pre&gt;&#10; &lt;$nameDash$&#10; $inputDash1$='data'&#10; $functionDash1$='update'&gt;&#10; &lt;$nameDash$/&gt;&#10; &lt;pre&gt;&#10; *&#10; */&#10;&#10; try {&#10; module = angular.module('$module$');&#10; } catch (err) {&#10; module = angular.module('$module$', [])&#10; }&#10; &#10; module.directive('$directiveName$', $directiveName$);&#10;&#10; function $directiveName$Controller($log) {&#10; &#10; function _callUpdate() {&#10; if (typeof $scope.$function1$ == 'function') {&#10; $scope.$function1$()();&#10; } else {&#10; $log.error('An update function is required!');&#10; }&#10; }&#10; }&#10;&#10; function $directiveName$() {&#10; return {&#10; restrict: 'AE',&#10; scope: {&#10; $input1$: '=',&#10; $function1$: '&amp;'&#10; },&#10; templateUrl: '/publc/ $nameSnake$.html',&#10; controller: $directiveName$Controller&#10; }&#10; }&#10;}());&#10;$end$" description="An Angular Directive with a Controller function" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="date" expression="date()" defaultValue="" alwaysStopAt="true" />
<variable name="module" expression="" defaultValue="&quot;module.name&quot;" alwaysStopAt="true" />
<variable name="directiveName" expression="fileNameWithoutExtension()" defaultValue="" alwaysStopAt="true" />
<variable name="input1" expression="" defaultValue="&quot;input&quot;" alwaysStopAt="true" />
<variable name="function1" expression="" defaultValue="&quot;updateFn&quot;" alwaysStopAt="true" />
<variable name="description" expression="" defaultValue="&quot;Add a description of what your Directive does!&quot;" alwaysStopAt="true" />
<variable name="inputDash1" expression="lowercaseAndDash(input1)" defaultValue="" alwaysStopAt="true" />
<variable name="functionDash1" expression="lowercaseAndDash(function1)" defaultValue="" alwaysStopAt="true" />
<variable name="nameSnake" expression="snakeCase(directiveName)" defaultValue="" alwaysStopAt="true" />
<variable name="nameDash" expression="lowercaseAndDash(directiveName)" defaultValue="" alwaysStopAt="true" />
<variable name="end" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
</context>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment