[Pkg-javascript-commits] [node-jade] 32/72: Add render fallback for compile
Jelmer Vernooij
jelmer at moszumanska.debian.org
Sun Jul 3 18:03:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
jelmer pushed a commit to annotated tag upstream/1.0.0
in repository node-jade.
commit 7b811b18f52ba3cad94f179e92470826c57baff6
Author: Rob Loach <robloach at gmail.com>
Date: Thu Jun 4 10:16:45 2015 -0400
Add render fallback for compile
---
index.js | 6 ++++++
test/compile.js | 14 +++++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index eb1bf26..95b755c 100644
--- a/index.js
+++ b/index.js
@@ -130,6 +130,12 @@ Transformer.prototype.can = function (method) {
Transformer.prototype.compile = function (str, options) {
if (!this.can('compile')) {
+ if (this.can('render')) {
+ var _this = this;
+ return tr.normalizeFn(function (locals) {
+ return _this._tr.render(str, options, locals);
+ });
+ }
if (this.can('compileAsync')) {
throw new Error('The Transform "' + this.name + '" does not support synchronous compilation');
} else if (this.can('compileFileAsync')) {
diff --git a/test/compile.js b/test/compile.js
index 4d1bede..48baec4 100644
--- a/test/compile.js
+++ b/test/compile.js
@@ -45,10 +45,22 @@ test('compile - without tr.compile', function () {
var tr = createTransformer({
name: 'test',
outputFormat: 'html',
- render: function () {
+ compileClient: function () {
}
});
assert.throws(function () {
tr.compile('example input', {});
}, /does not support compilation/);
});
+
+test('compile - without tr.compile, but with tr.render => fn', function (override) {
+ var tr = createTransformer({
+ name: 'test',
+ outputFormat: 'html',
+ render: function (str, options, locals) {
+ assert(str === 'example input');
+ return locals.name;
+ }
+ });
+ assert(tr.compile('example input', {}).fn({name: 'hola'}) === 'hola');
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jade.git
More information about the Pkg-javascript-commits
mailing list