[Pkg-javascript-commits] [node-jade] 47/72: Rewrite renderFile*
Jelmer Vernooij
jelmer at moszumanska.debian.org
Sun Jul 3 18:03:28 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 18dcd3ff9464a2269af21acdb8440c2513ba157d
Author: Timothy Gu <timothygu99 at gmail.com>
Date: Thu Jul 9 08:29:05 2015 +0800
Rewrite renderFile*
- Use this._hasMethod
- Throw errors in renderFile instead of returning a Promise
- Use uniform error messages in renderFile
- Handle !this.can('renderFileAsync') in renderFileAsync
---
index.js | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/index.js b/index.js
index 52ff501..e35376d 100644
--- a/index.js
+++ b/index.js
@@ -303,32 +303,38 @@ Transformer.prototype.renderAsync = function (str, options, locals, cb) {
}
};
Transformer.prototype.renderFile = function (filename, options, locals) {
- if (typeof this._tr.renderFile === 'function') {
+ if (!this.can('renderFile')) { // *Async, *Client
+ throw new Error('The Transform "' + this.name + '" does not support rendering synchronously.');
+ }
+
+ if (this._hasMethod('renderFile')) {
return tr.normalize(this._tr.renderFile(filename, options, locals));
- } else if (typeof this._tr.render === 'function') {
+ } else if (this._hasMethod('render')) {
return tr.normalize(this._tr.render(tr.readFileSync(filename, 'utf8'), options, locals));
- } else if (this._hasMethod('compile') || this._hasMethod('compileFile')) {
+ } else { // compile || compileFile
var compiled = this.compileFile(filename, options);
return tr.normalize({body: compiled.fn(locals || options), dependencies: compiled.dependencies});
- } else {
- return Promise.reject(new Error('This transform does not support synchronous rendering'));
}
};
Transformer.prototype.renderFileAsync = function (filename, options, locals, cb) {
+ if (!this.can('renderFileAsync')) { // *Client
+ throw new Error('The Transform "' + this.name + '" does not support rendering.');
+ }
+
if (typeof locals === 'function') {
cb = locals;
locals = options;
}
- if (typeof this._tr.renderFileAsync === 'function') {
+ if (this._hasMethod('renderFileAsync')) {
return tr.normalizeAsync(this._tr.renderFileAsync(filename, options, locals), cb);
- } else if (typeof this._tr.renderFile === 'function') {
+ } else if (this._hasMethod('renderFile')) {
return tr.normalizeAsync(this._tr.renderFile(filename, options, locals), cb);
} else if (this._hasMethod('compile') || this._hasMethod('compileAsync')
|| this._hasMethod('compileFile') || this._hasMethod('compileFileAsync')) {
return tr.normalizeAsync(this.compileFileAsync(filename, options).then(function (compiled) {
return {body: compiled.fn(locals || options), dependencies: compiled.dependencies};
}), cb);
- } else {
+ } else { // render || renderAsync
return tr.normalizeAsync(tr.readFile(filename, 'utf8').then(function (str) {
return this.renderAsync(str, options, locals);
}.bind(this)), cb);
--
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