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

Added Support for Twing #327

Merged
merged 13 commits into from
Nov 2, 2019
28 changes: 28 additions & 0 deletions lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var fs = require('fs');
var path = require('path');
var Promise = require('bluebird');
var semver = require('semver');
noel-schenk marked this conversation as resolved.
Show resolved Hide resolved

var join = path.join;
var resolve = path.resolve;
Expand Down Expand Up @@ -1760,6 +1761,33 @@ exports.squirrelly.render = function(str, options, cb) {
}
});
};
/**
* Twing support.
*/

exports.twing = fromStringRenderer('twing');

/**
* Twing string support.
*/

exports.twing.render = function(str, options, cb) {
if (!semver.satisfies(process.version, '>=6.0.0')) {
return promisify(cb, function(cb) {
noel-schenk marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('This node version is not supported for Twing. Please upgrade to at least node version 6.0.0 or a recommended version >=8.x');
});
}
return promisify(cb, function(cb) {
var engine = requires.twing || (requires.twing = require('twing'));
try {
var rendTmpl = new engine.TwingEnvironment(new engine.TwingLoaderNull()).createTemplate(str).render(options);
var tmpl = cache(options) || cache(options, rendTmpl);
cb(null, tmpl);
} catch (err) {
cb(err);
}
});
};
/**
* expose the instance of the engine
*/
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"test": "mocha"
},
"dependencies": {
"bluebird": "^3.1.1"
"bluebird": "^3.1.1",
"semver": "^6.3.0"
},
"devDependencies": {
"arc-templates": "^0.5.1",
Expand Down Expand Up @@ -78,6 +79,7 @@
"tinyliquid": "^0.2.30",
"toffee": "^0.1.12",
"twig": "^0.10.0",
"twing": ">=2.3.5",
"underscore": "^1.3.3",
"vash": "^0.12.2",
"velocityjs": "^0.8.2",
Expand Down
4 changes: 4 additions & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var cons = require('../');
var semver = require('semver');
/*eslint-env node*/
/*eslint quotes: [2, "single"] */
require('./shared').test('jade');
Expand Down Expand Up @@ -72,3 +73,6 @@ require('./shared').test('razor');
require('./shared').test('squirrelly');
require('./shared/partials').test('squirrelly');
require('./shared/helpers').test('squirrelly');
if (semver.satisfies(process.version, '>=6.0.0')) {
require('./shared').test('twing');
}
1 change: 1 addition & 0 deletions test/fixtures/twing/user.twing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>{{ user.name }}</p>