refactor: filepath resolving into getTemplate

This commit is contained in:
harttle
2016-10-05 12:08:30 +08:00
parent 77930e2d20
commit 8b4b89cf82
4 changed files with 12 additions and 14 deletions
+5 -6
View File
@@ -273,18 +273,17 @@ var _engine = {
if (!filepath) throw new Error('filepath cannot be null');
filepath = resolvePath(this.options.root, filepath);
if (!filepath.match(/\.\w+$/)) {
filepath += this.options.extname;
}
return this.getTemplate(filepath).then(function (html) {
var tpl = _this2.options.cache && _this2.cache[filepath] || _this2.parse(html);
return _this2.options.cache ? _this2.cache[filepath] = tpl : tpl;
});
},
getTemplate: function getTemplate(filepath) {
filepath = resolvePath(this.options.root, filepath);
if (!filepath.match(/\.\w+$/)) {
filepath += this.options.extname;
}
return new Promise(function (resolve, reject) {
fs.readFile(filepath, 'utf8', function (err, html) {
err ? reject(err) : resolve(html);
+1 -1
View File
File diff suppressed because one or more lines are too long