Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
A-312 authored Jul 1, 2019
2 parents 854ffbe + d81266c commit 12095dc
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
| [pug](https://github.com/pugjs/pug) | [`npm install pug`](https://www.npmjs.com/package/pug) | [(website)](http://jade-lang.com/) / **(formerly jade)** |
| [qejs](https://github.com/jepso/QEJS) | [`npm install qejs`](https://www.npmjs.com/package/qejs) | - |
| [ractive](https://github.com/ractivejs/ractive) | [`npm install ractive`](https://www.npmjs.com/package/ractive) | - |
| [razor](https://github.com/kinogam/kino.razor) | [`npm install razor`](https://www.npmjs.com/package/razor) | - |
| [react](https://github.com/facebook/react) | [`npm install react`](https://www.npmjs.com/package/react) | - |
| [slm](https://github.com/slm-lang/slm) | [`npm install slm`](https://www.npmjs.com/package/slm) | - |
| ~~[swig](https://github.com/paularmstrong/swig)~~ | [`npm install swig`](https://www.npmjs.com/package/swig) | **(unmaintained)** |
Expand All @@ -52,7 +53,6 @@
| [walrus](https://github.com/jeremyruppel/walrus) | [`npm install walrus`](https://www.npmjs.com/package/walrus) | [(website)](http://documentup.com/jeremyruppel/walrus/) |
| [whiskers](https://github.com/gsf/whiskers.js) | [`npm install whiskers`](https://www.npmjs.com/package/whiskers) | - |


__NOTE__: you must still install the engines you wish to use, add them to your package.json dependencies.

## API
Expand Down
84 changes: 83 additions & 1 deletion lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,59 @@ exports.swig.render = function(str, options, cb) {
});
};

/**
* Razor support.
*/

exports.razor = function(path, options, cb) {
return promisify(cb, function(cb) {
var engine = requires.razor;
if (!engine) {
try {
engine = requires.razor = require('razor-tmpl');

} catch (err) {

throw err;

}
}
try {

var tmpl = cache(options) || cache(options, (locals) => {
console.log('Rendering razor file', path);
return engine.renderFileSync(path, locals);
});
cb(null, tmpl(options));
} catch (err) {
cb(err);
}
});
};

/**
* razor string support.
*/

exports.razor.render = function(str, options, cb) {
return promisify(cb, function(cb) {

try {
var engine = requires.razor = require('razor-tmpl');
} catch (err) {
throw err;
}

try {
var tf = engine.compile(str);
var tmpl = cache(options) || cache(options, tf);
cb(null, tmpl(options));
} catch (err) {
cb(err);
}
});
};

/**
* Atpl support.
*/
Expand Down Expand Up @@ -619,7 +672,9 @@ exports.twig.render = function(str, options, cb) {
return promisify(cb, function(cb) {
var engine = requires.twig || (requires.twig = require('twig').twig);
var templateData = {
data: str
data: str,
allowInlineIncludes: options.allowInlineIncludes,
path: options.path
};
try {
var tmpl = cache(templateData) || cache(templateData, engine(templateData));
Expand Down Expand Up @@ -1678,6 +1733,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
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,24 @@
"pug": "^2.0.0-beta6",
"qejs": "^3.0.5",
"ractive": "^0.8.4",
"react": "^15.3.2",
"razor-tmpl": "^1.3.1",
"react": "^15.6.2",
"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
4 changes: 4 additions & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ require('./shared').test('marko');
require('./shared').test('bracket');
require('./shared').test('teacup');
require('./shared').test('velocityjs');
require('./shared').test('razor');
require('./shared').test('squirrelly');
require('./shared/partials').test('squirrelly');
require('./shared/helpers').test('squirrelly');
1 change: 1 addition & 0 deletions test/fixtures/razor/user.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p> @locals.user.name </p>
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 12095dc

Please sign in to comment.