forked from frctl/react-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.js
31 lines (24 loc) · 827 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
'use strict';
require("babel-register")({
extensions: [".jsx"],
presets: ['react', 'es2015']
});
const Handlebars = require('handlebars');
const React = require('react');
const ReactDOM = require('react-dom/server');
module.exports = function(source, config){
config = config || {};
return {
render: function(path, str, context){
delete require.cache[path];
const component = require(path);
const element = React.createElement(component, context);
const html = ReactDOM.renderToStaticMarkup(element);
return Promise.resolve(html);
},
renderLayout: function(path, str, context){
const template = Handlebars.compile(str);
return Promise.resolve(template(context));
}
}
};