Skip to content

Commit ed2c6f1

Browse files
committed
Add support for node.js npm module
1 parent 2bfb274 commit ed2c6f1

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Underscore.js global template helpers
22

3+
### Install
4+
5+
npm install underscore-template-helpers
6+
7+
38
This [underscore.js](https://github.com/documentcloud/underscore) mixin allows you to define global template helpers that will be available in all your underscore templates. For example, you can define aa "if and only if" function that will only output text if its first argument evaluates to `true`:
49

510
_.addTemplateHelpers( {

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "underscore-template-helpers",
3+
"version": "0.0.1",
4+
"description": "Underscore.js global template helpers",
5+
"main": "underscore.template-helpers.js",
6+
"dependencies": {
7+
"underscore": "~1.5.1"
8+
},
9+
"devDependencies": {},
10+
"scripts": {
11+
"test": "echo \"Error: no test specified\" && exit 1"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/demchenkoe/underscore-template-helpers.git"
16+
},
17+
"keywords": [
18+
"underscore",
19+
"template",
20+
"helpers"
21+
],
22+
"author": "David Beck",
23+
"license": "https://raw.github.com/demchenkoe/underscore-template-helpers/master/LICENSE.html"
24+
}

underscore.template-helpers.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
(function() {
2+
3+
if(typeof _ === 'undefined') {
4+
if(typeof module === 'object' && typeof module.exports === 'object') {
5+
//this is node.js
6+
var _ = require('underscore');
7+
}
8+
else {
9+
throw 'please include the "underscore" library';
10+
}
11+
}
12+
213
var originalUnderscoreTemplateFunction = _.template;
314
var templateHelpers = {};
415

@@ -33,4 +44,4 @@
3344
return wrappedTemplate;
3445
}
3546
} );
36-
} )();
47+
} )();

0 commit comments

Comments
 (0)