-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.js
41 lines (34 loc) · 1019 Bytes
/
adapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const Handlebars = require('handlebars');
const Promise = require('bluebird');
const Adapter = require('@frctl/fractal').Adapter;
const Vue = require('vue');
const VueRenderer = require('vue-server-renderer').createRenderer();
class VueAdapter extends Adapter {
constructor(source, loadPaths) {
super(null, source);
}
render(path, str, context) {
delete require.cache[path];
let component = require(path);
return new Promise(function(resolve, reject) {
component = Object.assign(component, {}, context);
VueRenderer.renderToString(component, (err, html) => {
if (err) throw err;
resolve(html);
});
});
}
renderLayout(path, str, context) {
const template = Handlebars.compile(str);
return Promise.resolve(template(context));
}
}
module.exports = function(config) {
config = config || {}; // not doing anything with config right now!
return {
register(source, app) {
return new VueAdapter(source);
}
};
};