Skip to content

Instantly share code, notes, and snippets.

@russellf9
Created July 31, 2016 09:53
Show Gist options
  • Save russellf9/8db3952620f11eff28c2af22c728b820 to your computer and use it in GitHub Desktop.
Save russellf9/8db3952620f11eff28c2af22c728b820 to your computer and use it in GitHub Desktop.
A IntelliJ Live Template to create an Angular Factory Service
<template name="ngf" value="(function () {&#10;&#10; 'use strict';&#10;&#10;&#10; /**&#10; *&#10; * @author $name$&#10; * @date $date$&#10; *&#10; * @name&#10; * $module$:$factoryName$&#10; *&#10; * @param {obj} $value1$ An accessible member&#10; * @param {function} $function1$ A function the Factory returns&#10; * @param {function} $function2$ A function the Factory returns&#10; *&#10; * // define module requirements&#10; * @requires $dependancy1$&#10; * @requires $dependancy2$&#10; *&#10; * // define `imports`&#10; * @requires $import1$&#10; * @requires $import2$&#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; *&#10; */&#10; &#10; // Ideally each Directive will have a unique package, so this try, catch won`t be required &lt;br&gt;&#10; // Each package needs to be defined in their own module &lt;br&gt;&#10; var module;&#10;&#10; try {&#10; module = angular.module('$module$');&#10; } catch (err) {&#10; module = angular.module('$module$', [])&#10; }&#10; &#10; module.factory('$factoryName$', $factoryName$);&#10; &#10; $factoryName$.$$inject = ['$dependancy1$', '$dependancy2$'];&#10;&#10; function $factoryName$($import1$, $import2$) {&#10; &#10; // ==== ACCESSIBLE MEMBERS ==== &#10; var $value1$ = '';&#10; &#10; var service = { };&#10; &#10; service.$function1$ = $function1$;&#10; service.$function2$ = $function2$;&#10; &#10; return service;&#10; &#10; // ==== IMPLEMENTATION OF FUNCTIONS ====&#10; function $function1$() {&#10; // implementation details go here&#10; }&#10; &#10; function $function2$() {&#10; // implementation details go here&#10; }&#10; }&#10;}());&#10;$end$" description="An Angular Facory" 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="factoryName" expression="fileNameWithoutExtension()" defaultValue="" alwaysStopAt="true" />
<variable name="value1" expression="" defaultValue="&quot;currentName&quot;" alwaysStopAt="true" />
<variable name="function1" expression="" defaultValue="&quot;setValue&quot;" alwaysStopAt="true" />
<variable name="function2" expression="" defaultValue="&quot;getValue&quot;" alwaysStopAt="true" />
<variable name="dependancy1" expression="" defaultValue="&quot;module1&quot;" alwaysStopAt="true" />
<variable name="dependancy2" expression="" defaultValue="&quot;module2&quot;" alwaysStopAt="true" />
<variable name="import1" expression="" defaultValue="&quot;import1&quot;" alwaysStopAt="true" />
<variable name="import2" expression="" defaultValue="&quot;import1&quot;" alwaysStopAt="true" />
<variable name="description" expression="" defaultValue="&quot;Add a description of what your Factory Service does!&quot;" 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