An open API service indexing awesome lists of open source software.

https://github.com/lovasoa/musreact

Mustache template to react component compiler
https://github.com/lovasoa/musreact

Last synced: 10 months ago
JSON representation

Mustache template to react component compiler

Awesome Lists containing this project

README

          

musreact
========

Mustache template to react component compiler

## Demo
http://lovasoa.github.io/musreact/

## How to use

### Directly in html
Compile the mustache template on the client.

```html

var mustacheStr = "<p>Your name is <em>{{name}}</em></p>";
var jsondata = {name: "Gérard Bouchard"};

var source = parser.parse(mustacheStr);

// Create a react component
var reactComponent = eval(source);

// Use it
React.render(
React.createElement(reactComponent, jsondata),
document.getElementById("mountpoint")
);

```

### Server compiling
Just save the output of `parser.parse(mustacheString)`, and serve it as a normal js file.

An simple script could be:
```js
var fs = require("fs");
var parse = require("musreact").parse;

var jsSource = parse(fs.readFileSync("react-component.mustache", "utf-8"));

fs.writeFileSync("react-component.js", "MyComponent = " + jsSource);
```

It reads the template from `react-component.mustache` and saves the compiled
react component to `react-component.js`. The component will then be accessible through
the global variable `MyComponent`.