periodicjs.core.responder
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -28,6 +28,6 @@ 'use strict'; | ||
return Promisie.retry(() => { | ||
let filePath = dirs.shift(); | ||
return fs.statAsync(filePath) | ||
let filePath = dirs.shift(); | ||
return fs.statAsync(filePath) | ||
.then(() => filePath, e => Promise.reject(e)); | ||
}, { times: dirs.length, timeout: 0, }) | ||
}, { times: dirs.length, timeout: 0, }) | ||
.then(fp => fp) | ||
@@ -72,3 +72,2 @@ .catch(() => _default); | ||
dirs.push(path.join(app_prefix_path, 'app/views', `${viewname}${(/^\./.test(fileext)) ? fileext : '.' + fileext}`)); | ||
if (options.resolve_filepath === true) { | ||
@@ -78,4 +77,7 @@ return findValidViewFromPaths(viewname, dirs); | ||
return findValidViewFromPaths(`${ viewname }${ (/^\./.test(fileext)) ? fileext : '.' + fileext }`, dirs) | ||
.then(filePath => Promisie.all(fs.readFileAsync(filePath, 'utf8'), filePath)) | ||
.spread((filestr, filename) => { | ||
.then(filePath => { | ||
return Promisie.all(fs.readFileAsync(filePath, 'utf8'), filePath); | ||
}) | ||
.then(result => { | ||
let [filestr, filename, ] = result; | ||
filestr = filestr.toString(); | ||
@@ -130,12 +132,12 @@ return Promisie.resolve(this.engine.render(filestr, data, Object.assign({ filename, }, options.engine_configuration || this.engine_configuration))); | ||
constructor(options = {}) { | ||
super(options); | ||
this.engine = (options.engine && typeof options.engine.render === 'function') ? options.engine : ejs; | ||
this.engine_configuration = options.engine_configuration; | ||
this.extname = options.extname; | ||
this.themename = options.themename || 'periodicjs.theme.default'; | ||
this.viewname = options.viewname; | ||
this.fileext = options.fileext || '.ejs'; | ||
this.locals = (options.locals && typeof options.locals === 'object') ? options.locals : {}; | ||
this.custom_error_path = options.custom_error_path; | ||
} | ||
super(options); | ||
this.engine = (options.engine && typeof options.engine.render === 'function') ? options.engine : ejs; | ||
this.engine_configuration = options.engine_configuration; | ||
this.extname = options.extname; | ||
this.themename = options.themename || 'periodicjs.theme.default'; | ||
this.viewname = options.viewname; | ||
this.fileext = options.fileext || '.ejs'; | ||
this.locals = (options.locals && typeof options.locals === 'object') ? options.locals : {}; | ||
this.custom_error_path = options.custom_error_path; | ||
} | ||
/** | ||
@@ -153,9 +155,9 @@ * Renders HTML from provided data and template | ||
render(data, options = {}, cb = false) { | ||
if (typeof options === 'function') { | ||
cb = options; | ||
options = {}; | ||
} | ||
if (options.req && options.res) { | ||
data.flash_messages = {}; | ||
try { | ||
if (typeof options === 'function') { | ||
cb = options; | ||
options = {}; | ||
} | ||
if (options.req && options.res) { | ||
data.flash_messages = {}; | ||
try { | ||
data.flash_messages = (typeof options.req.flash === 'function') ? options.req.flash() : {}; | ||
@@ -165,3 +167,3 @@ } catch (e) { | ||
} | ||
return _RENDER.call(this, {}, Object.assign(options, { resolve_filepath: true, })) | ||
return _RENDER.call(this, {}, Object.assign(options, { resolve_filepath: true, })) | ||
.then(filepath => Promisie.promisify(options.res.render, options.res)(filepath, data)) | ||
@@ -177,6 +179,6 @@ .then(rendered => { | ||
.catch(err => this.error(err, options, cb)); | ||
} else { | ||
options.formatRender = (typeof options.formatRender === 'function') ? options.formatRender : _RENDER.bind(this); | ||
options.sync = true; | ||
return super.render(Object.assign({ flash_messages: {}, }, this.locals, data), options) | ||
} else { | ||
options.formatRender = (typeof options.formatRender === 'function') ? options.formatRender : _RENDER.bind(this); | ||
options.sync = true; | ||
return super.render(Object.assign({ flash_messages: {}, }, this.locals, data), options) | ||
.then(result => { | ||
@@ -189,4 +191,4 @@ if (typeof cb === 'function') cb(null, result); | ||
}); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -193,0 +195,0 @@ * Renders error view from template |
@@ -44,3 +44,3 @@ { | ||
"mustache": "^2.3.0", | ||
"promisie": "~1.5.3", | ||
"promisie": "~2.0.0-alpha.0", | ||
"pug": "^2.0.0-beta6" | ||
@@ -90,4 +90,4 @@ }, | ||
}, | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"license": "MIT" | ||
} |
1244083
1950