From fef87653256f9525fe3ea39bb2a70bf7bee03f1c Mon Sep 17 00:00:00 2001 From: lichengyin Date: Tue, 5 Jan 2016 09:05:46 +0800 Subject: [PATCH] add render method for controller, alias of display --- src/controller/base.js | 10 ++++++++++ test/controller/base.js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/controller/base.js b/src/controller/base.js index 4463d94c..f95bd767 100644 --- a/src/controller/base.js +++ b/src/controller/base.js @@ -234,6 +234,16 @@ export default class extends think.http.base { this._baseAssign(); return this.view().display(templateFile, charset, contentType); } + /** + * alias of display + * @param {String} templateFile [template filepath] + * @param {String} charset [content encoding] + * @param {String} contentType [content type] + * @return {Promise} [] + */ + render(templateFile, charset, contentType){ + return this.display(templateFile, charset, contentType); + } /** * output with jsonp * @param {Object} data [output data] diff --git a/test/controller/base.js b/test/controller/base.js index 8d9c8f0d..47e811f3 100644 --- a/test/controller/base.js +++ b/test/controller/base.js @@ -423,6 +423,17 @@ describe('controller/base.js', function(){ done(); }) }) + it('render', function(done){ + muk(think, 'log', function(){}) + getInstance({ + }).then(function(instance){ + return instance.render(__filename) + }).catch(function(err){ + assert.equal(think.isPrevent(err), true); + muk.restore(); + done(); + }) + }) it('download', function(done){ getInstance({ header: function(type, value){