Skip to content

Instantly share code, notes, and snippets.

@dschinkel
Last active January 24, 2017 04:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschinkel/8bf56f5db0be5e55fa1a1f8ff8c43c16 to your computer and use it in GitHub Desktop.
Save dschinkel/8bf56f5db0be5e55fa1a1f8ff8c43c16 to your computer and use it in GitHub Desktop.
/*
This list will be continually updated with new templates.
If you have requests for any, please add a comment using the comment box at the bottom of this page.
NOTE: the comments are just to facilitate reading this gist, don't include those in your IntelliJ Live Templates.
some comments are just suggested template abbreviations for the live templates once you add them to your IDE
OSX templates file location examples:
~/Library/Preferences/WebStorm2016.3/templates
~/Library/Preferences/IdeaIC2016.2/templates (IntelliJ)
$SOMENAME$ - are tab to points. You can name them anything but JetBrains tabs top down to each pair of $$
How to add an individual live template in your JetBrains IDE:
Mac (PC is almost exactly the same with the exception of step 1):
1) command +, to quickly get to the IDE properties (which also presents you with a search box)
2) if you haven't already, search "live templates"
3) highlight the template group in which you intend to add a new live template to
(don't add them to the out of box groups, create your own; this is a JetBrains good practice)
4) click the + and choose "Live Template"
5) Give it an abbreviation which you'll use as the live template shortcut when you code
6) Paste in the template text
7) Click the define link and tell it where you want to be able to use this template
usually it's either JavaScript: expression or JavaScript:statement or both depending on what the script is
8) click apply
How to import all the definitions in this Gist:
(instructions & sharable xml file you can import into your IDE coming soon)
*/
/* TESTING */
/* SPEC FILE */
// Mocha + Chai (expect) + enzyme + jsdom
// abbrev: spec-web
'use strict';
require('jsdom'); // I've got my own helper module, may or may not be useful to you
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';
import {shallow, mount} from 'enzyme';
const expect = require('chai').expect
chai.use(chaiEnzyme());
describe('$DESCF$', () => {
it('should $DESCT$', () => {
$END$
expect(true).to.be.true;
});
});
// Mocha & Chai (expect)
// abbrev: spec
'use strict';
import {chai, expect} from 'chai';
describe('$DESCF$', () => {
it('should $DESCT$', () => {
$END$
expect(true).to.be.true;
});
});
// abbrev: desc
describe('$DESCRIPTION$', () => {
$END$
});
// abbrev: it
// note: $DONE$ is optional. If you want it to be an async test add 'done' there
it('should $DESCT$', ($DONE$) => {
$END$
expect(true).to.be.true;
});
/* JS - ES5 or prior */
// abbrev: strict
'use strict'
$END$
// abbrev: log
console.log($END$);
// abbrev: var
var $NAME$ = $VALUE$;
// abbrev: arr
[$ITEMS$]
// abbrev: lit
{$PROPERTY$:$VALUE$}
// abbrev: objc
Object.create($OBJECT$, {
$PROPERTY$: {
//configurable, enumerable, value, writable, get, set
}
});
// abbrev: objaddprops
Object.defineProperties($OBJECT$, {
$PROPERTY$: {
//configurable, enumerable, value, writable, get, set
}
});
// abbrev: switch
switch ($condition$) {
case $case$:
break;
$END$
default:
return $VALUE$;
};
// abbrev: for
for (var $INDEX$ = 0, len = $ARRAY$.length; $INDEX$ < len; $INDEX$++) {
var $VAR$ = $ARRAY$[$INDEX$];
$END$
}
// abbrev: if
if ($COND$) {
$END$
}
// abbrev: ifelse
if ($COND$) {
$END$
}
else {
$END$
}
// abbrev: map
$ARRAY$.map(($PARAMS$) =>
$BODY$
);
// abbrev: turn
$EXPRESSION$ ? $TRUEVAL$ : $FALSEVAL$;
// module pattern
//abbrev: mod
var $NAME$ = (() => {
var $NAME$ = {},
privateVariable = 1;
function privateMethod() {
$BODY$
}
$NAME$.moduleProperty = $VALUE$;
$NAME$.moduleMethod = () => {
$BODY$
};
return $NAME$;
}());
/* ES6 */
// abbrev: imp
import {$MEMBERS$} from '$MODULE$';
// abbrev: cst
const $NAME$ = $VALUE$;
// abbrev: let
let $NAME$ = $VALUE$;
// abbrev: objass
Object.assign({}, $OBJECT$);
// abbrev: arrow
($PARAMS$) => {
return $BODY$;
}$END$
// abbrev: iife
(function($PARAMS$){
$BODY$
}($PARAMS$));
// abbrev: prom
Promise.resolve()
.then(() => {
return $END$
})
/* REACT.JS
misc references:
https://github.com/minwe/jetbrains-react
https://github.com/garretto/intellij-live-templates-react
http://reactpatterns.com
*/
/* abbrev: rcondand
conditional rendering of react components
ex:
<div className="all-20">
{this.state.rendered && <TableOfContents company={company}/>}
</div>
*/
{$COND$ && $JSX$}
// abbrev: rcondor
{$COND$ || $JSX$}
// abbrev: rclass
className="$NAME$"
// abbrev: rprop
this.props.$NAME$
// abbrev: rpropconst
const $NAME$ = this.props.$NAME$;
// abbrev: rpropt
React.PropTypes.$TYPE$.isRequired
// abbrev: rpropdefault
getDefaultProps: () => {
return {
$PROP$: $VALUE$
}
}
// abbrev: render
render(){
$BODY$
return($VALUE$);
}
// abbrev: rstatelessfunc
const $NAME$ = ($PROPS$, $CONTEXT$) =>
<div className="$VALUES$">Hi {props.name}</div>
// abbrev: rreturn
return <div>{$CONTENT$}</div>
// abbrev: rbutton
<button type="button"$END$>
// abbrev: rbuttonprops
const Button = props$END$ => <button type="button" {...props}$END$>
/* REDUX */
// coming soon
/* Node.js */
// coming soon
@Gryff
Copy link

Gryff commented Jan 23, 2017

Nice list!
In my version of it I like to put a $DONE$ within the parentheses incase I want to write done for an async test. I can just hit enter if it isn't.

it('should $DESCT$', ($DONE$) => {
        $END$
        expect(true).to.be.true;
    });

@dschinkel
Copy link
Author

dschinkel commented Jan 23, 2017

@Gryff thx. good one! I'll add that to mine as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment