Skip to content

Commit

Permalink
initial react-js support
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Feb 11, 2015
1 parent 77f6d92 commit e89297a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 26 deletions.
53 changes: 53 additions & 0 deletions lib/consolidate.js
Expand Up @@ -956,3 +956,56 @@ exports.htmling.render = function(str, options, fn) {
fn(err);
}
};



/**
* React JS Support
*/
exports.reactjs = fromStringRenderer('reactjs');

/**
* React JS string support.
*/
exports.reactjs.render = function(str, options, fn) {

// Ensure JSX is transformed on require
var ReactTools = require('react-tools');
require.extensions['.jsx'] = function(module, filename) {
var content = fs.readFileSync(filename, 'utf8');
var compiled = ReactTools.transform(content, {harmony: true});
return module._compile(compiled, filename);
};


// React Import
var engine = requires.reactjs || (requires.reactjs = require('react'));

// Assign HTML
var layout = options.layout;
delete options.layout;

// Parsing
var factory = engine.createFactory(require(str));
var parsed = new factory(options);

try {

var content = engine.renderToStaticMarkup(parsed);

if (layout){
var _ = requires.lodash || (requires.lodash = require('lodash'));

var base = fs.readFileSync(layout);
var compiler = _.template(base, {interpolate: /{{([\s\S]+?)}}/g});

content = compiler({content: content});
}

fn(null, content);

} catch (err) {
fn(err);
}

}
54 changes: 28 additions & 26 deletions package.json
Expand Up @@ -9,40 +9,42 @@
],
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"devDependencies": {
"mocha": "*",
"should": "*",
"jade": "1.9.1",
"ejs": "0.7.1",
"atpl": ">=0.7.6",
"dot": "1.0.1",
"dust": "0.3.0",
"dustjs-helpers": "1.1.1",
"dustjs-linkedin": "1.2",
"eco": "1.1.0-rc-3",
"swig": "1.4.1",
"jazz": "0.0.18",
"jqtpl": "1.1.0",
"liquor": "0.0.4",
"lodash": "1.2.0",
"ect": "0.3.5",
"ejs": "0.7.1",
"haml-coffee": "1.4.0",
"hamlet": "0.3.3",
"hamljs": "0.6.1",
"whiskers": "0.2.2",
"haml-coffee": "1.4.0",
"hogan.js": "2.0.0",
"dust": "0.3.0",
"dustjs-linkedin": "1.2",
"dustjs-helpers":"1.1.1",
"handlebars": "1.0.7",
"underscore": "1.3.3",
"qejs": "3.0.5",
"walrus": "0.9.0",
"mustache": "0.4.0",
"hogan.js": "2.0.0",
"htmling": "0.0.3",
"jade": "1.9.1",
"jazz": "0.0.18",
"jqtpl": "1.1.0",
"just": "0.1.8",
"ect": "0.3.5",
"liquor": "0.0.4",
"lodash": "1.2.0",
"mocha": "*",
"mote": "0.2.0",
"toffee": "0.0.52",
"atpl": ">=0.7.6",
"mustache": "0.4.0",
"nunjucks": "~1.0.0",
"qejs": "3.0.5",
"ractive": "^0.6.1",
"react": "^0.12.2",
"react-tools": "^0.12.2",
"should": "*",
"swig": "1.4.1",
"templayed": ">=0.2.3",
"tinyliquid": "~0.2.22",
"dot": "1.0.1",
"htmling": "0.0.3",
"ractive": "^0.6.1",
"nunjucks": "~1.0.0"
"toffee": "0.0.52",
"underscore": "1.3.3",
"walrus": "0.9.0",
"whiskers": "0.2.2"
},
"main": "index",
"repository": {
Expand Down

0 comments on commit e89297a

Please sign in to comment.