Skip to content

Commit 62a01ac

Browse files
committed
Added Squirrelly as a template engine, tests passing (except for Hamlet), added Squirrelly to ReadMe
1 parent 0c58586 commit 62a01ac

File tree

8 files changed

+57
-3
lines changed

8 files changed

+57
-3
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [ractive](https://github.com/Rich-Harris/Ractive)
4040
- [react](https://github.com/facebook/react)
4141
- [slm](https://github.com/slm-lang/slm)
42+
- [squirrelly](https://github.com/nebrelbug/squirrelly) [(website)](https://squirrelly.js.org)
4243
- [swig (maintained fork)](https://github.com/node-swig/swig-templates)
4344
- [swig (unmaintained)](https://github.com/paularmstrong/swig)
4445
- [teacup](https://github.com/goodeggs/teacup)

lib/consolidate.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,33 @@ exports.teacup.render = function(str, options, cb) {
16781678
});
16791679
};
16801680

1681+
/**
1682+
* Squirrelly support.
1683+
*/
1684+
1685+
exports.squirrelly = fromStringRenderer('squirrelly');
1686+
1687+
/**
1688+
* Squirrelly string support.
1689+
*/
1690+
1691+
exports.squirrelly.render = function(str, options, cb) {
1692+
return promisify(cb, function(cb) {
1693+
var engine = requires.squirrelly || (requires.squirrelly = require('squirrelly'));
1694+
try {
1695+
for (var partial in options.partials) {
1696+
engine.definePartial(partial, options.partials[partial]);
1697+
}
1698+
for (var helper in options.helpers) {
1699+
engine.defineHelper(helper, options.helpers[helper]);
1700+
}
1701+
var tmpl = cache(options) || cache(options, engine.Compile(str, options));
1702+
cb(null, tmpl(options, engine));
1703+
} catch (err) {
1704+
cb(err);
1705+
}
1706+
});
1707+
};
16811708
/**
16821709
* expose the instance of the engine
16831710
*/

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,19 @@
6969
"react-dom": "^15.3.2",
7070
"should": "*",
7171
"slm": "^0.5.0",
72-
"swig-templates": "^2.0.2",
72+
"squirrelly": "^5.0.1",
7373
"swig": "^1.4.1",
74+
"swig-templates": "^2.0.2",
7475
"teacup": "^2.0.0",
7576
"templayed": ">=0.2.3",
7677
"tinyliquid": "^0.2.30",
7778
"toffee": "^0.1.12",
7879
"twig": "^0.10.0",
7980
"underscore": "^1.3.3",
8081
"vash": "^0.12.2",
82+
"velocityjs": "^0.8.2",
8183
"walrus": "^0.10.1",
82-
"whiskers": "^0.4.0",
83-
"velocityjs": "^0.8.2"
84+
"whiskers": "^0.4.0"
8485
},
8586
"keywords": [
8687
"engine",

test/consolidate.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ require('./shared').test('marko');
6868
require('./shared').test('bracket');
6969
require('./shared').test('teacup');
7070
require('./shared').test('velocityjs');
71+
require('./shared').test('squirrelly');
72+
require('./shared/partials').test('squirrelly');
73+
require('./shared/helpers').test('squirrelly');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{myhelper(options.user.name)}}
2+
{{/myhelper}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{include(partial)/}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>{{user.name}}</p>

test/shared/helpers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
var cons = require('../../');
33
var handlebars = require('handlebars');
4+
var Sqrl = require('squirrelly');
45
var fs = require('fs');
56
var readFile = fs.readFile;
67
var readFileSync = fs.readFileSync;
@@ -34,6 +35,23 @@ exports.test = function(name) {
3435
done();
3536
});
3637
});
38+
} else if (name === 'squirrelly') {
39+
user = { name: '<strong>Tobi</strong>' };
40+
41+
// Use case: return safe HTML that won’t be escaped in the final render.
42+
it('should support helpers', function(done) {
43+
var str = fs.readFileSync('test/fixtures/' + name + '/helpers.' + name).toString();
44+
Sqrl.defineHelper('myhelper', function(args, content, blocks) {
45+
return args[0].slice(1, -1);
46+
});
47+
var options = { user: user };
48+
49+
cons[name].render(str, options, function(err, html) {
50+
if (err) return done(err);
51+
html.should.equal('strong>Tobi</strong');
52+
done();
53+
});
54+
});
3755
}
3856

3957
if (name === 'vash') {

0 commit comments

Comments
 (0)