Skip to content

Commit

Permalink
Merge pull request #317 from nebrelbug/master
Browse files Browse the repository at this point in the history
Add Squirrelly as a template engine
  • Loading branch information
doowb authored Jun 27, 2019
2 parents 0c58586 + 62a01ac commit 13a9e53
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [ractive](https://github.com/Rich-Harris/Ractive)
- [react](https://github.com/facebook/react)
- [slm](https://github.com/slm-lang/slm)
- [squirrelly](https://github.com/nebrelbug/squirrelly) [(website)](https://squirrelly.js.org)
- [swig (maintained fork)](https://github.com/node-swig/swig-templates)
- [swig (unmaintained)](https://github.com/paularmstrong/swig)
- [teacup](https://github.com/goodeggs/teacup)
Expand Down
27 changes: 27 additions & 0 deletions lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,33 @@ exports.teacup.render = function(str, options, cb) {
});
};

/**
* Squirrelly support.
*/

exports.squirrelly = fromStringRenderer('squirrelly');

/**
* Squirrelly string support.
*/

exports.squirrelly.render = function(str, options, cb) {
return promisify(cb, function(cb) {
var engine = requires.squirrelly || (requires.squirrelly = require('squirrelly'));
try {
for (var partial in options.partials) {
engine.definePartial(partial, options.partials[partial]);
}
for (var helper in options.helpers) {
engine.defineHelper(helper, options.helpers[helper]);
}
var tmpl = cache(options) || cache(options, engine.Compile(str, options));
cb(null, tmpl(options, engine));
} catch (err) {
cb(err);
}
});
};
/**
* expose the instance of the engine
*/
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,19 @@
"react-dom": "^15.3.2",
"should": "*",
"slm": "^0.5.0",
"swig-templates": "^2.0.2",
"squirrelly": "^5.0.1",
"swig": "^1.4.1",
"swig-templates": "^2.0.2",
"teacup": "^2.0.0",
"templayed": ">=0.2.3",
"tinyliquid": "^0.2.30",
"toffee": "^0.1.12",
"twig": "^0.10.0",
"underscore": "^1.3.3",
"vash": "^0.12.2",
"velocityjs": "^0.8.2",
"walrus": "^0.10.1",
"whiskers": "^0.4.0",
"velocityjs": "^0.8.2"
"whiskers": "^0.4.0"
},
"keywords": [
"engine",
Expand Down
3 changes: 3 additions & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ require('./shared').test('marko');
require('./shared').test('bracket');
require('./shared').test('teacup');
require('./shared').test('velocityjs');
require('./shared').test('squirrelly');
require('./shared/partials').test('squirrelly');
require('./shared/helpers').test('squirrelly');
2 changes: 2 additions & 0 deletions test/fixtures/squirrelly/helpers.squirrelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{myhelper(options.user.name)}}
{{/myhelper}}
1 change: 1 addition & 0 deletions test/fixtures/squirrelly/partials.squirrelly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{include(partial)/}}
1 change: 1 addition & 0 deletions test/fixtures/squirrelly/user.squirrelly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>{{user.name}}</p>
18 changes: 18 additions & 0 deletions test/shared/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var cons = require('../../');
var handlebars = require('handlebars');
var Sqrl = require('squirrelly');
var fs = require('fs');
var readFile = fs.readFile;
var readFileSync = fs.readFileSync;
Expand Down Expand Up @@ -34,6 +35,23 @@ exports.test = function(name) {
done();
});
});
} else if (name === 'squirrelly') {
user = { name: '<strong>Tobi</strong>' };

// Use case: return safe HTML that won’t be escaped in the final render.
it('should support helpers', function(done) {
var str = fs.readFileSync('test/fixtures/' + name + '/helpers.' + name).toString();
Sqrl.defineHelper('myhelper', function(args, content, blocks) {
return args[0].slice(1, -1);
});
var options = { user: user };

cons[name].render(str, options, function(err, html) {
if (err) return done(err);
html.should.equal('strong>Tobi</strong');
done();
});
});
}

if (name === 'vash') {
Expand Down

0 comments on commit 13a9e53

Please sign in to comment.