0.2.0 • Published 8 years ago
fray.compiler v0.2.0
fray.compiler
Component code generator
Usage
CLI
cat ast.json | parser
parser ast.json
Programmatically
var compiler = require('fray.compiler');
var ast = require('/path/to/ast.json');
console.log(compiler(ast));
ast.json
AST generated by fray.parser
from the template <div class="greeting">Hello { user.name }!</div>
{
"type": "Root",
"children": [
{
"type": "ElementNode",
"name": "div",
"attrs": {
"class": "greeting"
},
"children": [
{
"type": "TextNode",
"value": "Hello"
},
{
"type": "ExpressionNode",
"value": [
"user",
"name"
]
},
{
"type": "TextNode",
"value": "!"
}
]
}
]
}
Output
/* eslint no-unused-vars: "off" */
'use strict';
var h = require('fray/h');
var component = require('fray/component');
var render = function (state) {
return h('div', {}, [
h('div', { class: 'greeting' }, [
'Hello',
state.user.name,
'!'
])
]);
};
module.exports = component.bind(null, render);
Install
npm install fray.compiler
Contributing
PRs are welcome!
Unit tests
git clone https://github.com/frayjs/compiler
cd compiler
npm install
npm test
License
MIT