-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8ed5bfd
Showing
6 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.tags | ||
/lib-cov/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test/ | ||
/.tags | ||
/lib-cov/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var INTERPOLATE = /{([\s\S]+?)}/g | ||
|
||
module.exports = function(str, data) { | ||
var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + | ||
'with(obj||{}){__p.push(\'' + | ||
str.replace(/\\/g, '\\\\') | ||
.replace(/'/g, "\\'") | ||
.replace(INTERPOLATE, function(match, code) { | ||
return "'," + code.replace(/\\'/g, "'") + ",'" | ||
}) | ||
.replace(/\r/g, '\\r') | ||
.replace(/\n/g, '\\n') | ||
.replace(/\t/g, '\\t') | ||
+ "');}return __p.join('');" | ||
var func = new Function('obj', tmpl) | ||
return data ? func(data) : func | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "tmpl", | ||
"description": "JavaScript micro templates.", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/nshah/nodejs-tmpl", | ||
"author": "Naitik Shah <[email protected]>", | ||
"main": "lib/tmpl", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nshah/nodejs-tmpl" | ||
}, | ||
"scripts": { "test": "./node_modules/.bin/expresso -c" }, | ||
"devDependencies": { | ||
"expresso": ">= 0.8.1" | ||
}, | ||
"engines": { "node": ">= 0.4.1" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tmpl | ||
==== | ||
|
||
Simple string formatting using `{}`. | ||
|
||
```javascript | ||
assert.equal( | ||
tmpl('the answer is {answer}', { answer: 42 }), | ||
'the answer is 42') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var tmpl = require('tmpl') | ||
, assert = require('assert') | ||
|
||
exports['basic name substitution'] = function(beforeExit) { | ||
assert.equal( | ||
tmpl('the answer is {answer}', { answer: 42 }), | ||
'the answer is 42') | ||
} |