- Update all deps - Apply midwest changes - Convert all templates to JSX - Preact instead of Marko - Babel & Eslint
32 lines
779 B
JavaScript
32 lines
779 B
JavaScript
module.exports = function (Component, Master) {
|
|
const locals = Object.assign({}, this.app.locals, this.locals);
|
|
|
|
let preamble = '';
|
|
let html;
|
|
|
|
if (typeof Master === 'function') {
|
|
preamble = '<!doctype html>';
|
|
|
|
if (typeof Component === 'function') {
|
|
return this.send(preamble + (
|
|
<Master {...locals}>
|
|
<Component {...locals}/>
|
|
</Master>
|
|
));
|
|
}
|
|
|
|
Component = Master;
|
|
}
|
|
|
|
if (typeof Component !== 'function') {
|
|
throw new Error('Not a Component');
|
|
} else if (Component.prototype && Component.prototype.render) {
|
|
const instance = new Component(locals);
|
|
html = instance.render(instance.props, instance.state);
|
|
} else {
|
|
html = Component(locals);
|
|
}
|
|
|
|
this.send(preamble ? preamble + html : html);
|
|
};
|