Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Squirrelly as a template engine #317

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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