Skip to content

Instantly share code, notes, and snippets.

@andreypopp andreypopp/page.rd
Created Feb 18, 2014

Embed
What would you like to do?
---
title: Some new title
...
# some new stuff
And now some text is here
Another test
<Component />
<div className="x"></div>
"use strict";
var marked = require('meta-marked');
var reactTools = require('react-tools');
var runtime = require.resolve('./runtime');
function compile(src) {
var compiled = marked(src);
var meta = compiled.meta;
var wrapper = 'require("' + runtime + '").Wrapper';
var component = meta.component ?
'require("' + meta.component + '")' :
'_runtime.Page'
delete meta.component;
var code = [
'/** @jsx React.DOM */',
'var React = require("react");',
'var _runtime = require(' + JSON.stringify(runtime) + ');',
'var _Wrapper = _runtime.Wrapper;',
'var _Component = ' + component + ';',
'var _markup = <_Wrapper>' + compiled.html + '</_Wrapper>;',
'exports.meta = ' + JSON.stringify(meta) + ';',
'exports.render = function render(props) {',
' props = _runtime.merge(exports.meta, props);',
' return _Component.apply(_Component, [props].concat(_markup));',
'}'
].join('\n');
code = reactTools.transform(code);
return {code: code, meta: meta};
}
module.exports = compile;
"use strict";
var React = require('react');
var merge = require('react/lib/merge');
function Wrapper() {
return Array.prototype.slice.call(arguments, 1);
}
var Page = React.createClass({
displayName: 'Page',
render: function() {
return React.DOM.div(null, this.props.children);
}
});
module.exports = {
Wrapper: Wrapper,
Page: Page,
merge: merge
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.