danakt / handlebars-to-jsx Goto Github PK
View Code? Open in Web Editor NEWConverts Handlebars template to React component
License: MIT License
Converts Handlebars template to React component
License: MIT License
Uses handlebars-to-jsx under the hood
Here: https://blikblum.github.io/to-htm/web/dist/
Repository: https://github.com/blikblum/to-htm
For anyone interested
After having a conversation with some of the @glimmer/syntax
maintainers (glimmerjs/glimmer-vm#948), it seems they do not support partials in any form, and the module is specific to Ember's handlebars flavour. Therefore in order to support #3, and to move away from the Ember specific stuff, I think it would make sense to convert this module to use https://github.com/wycats/handlebars.js which provides a .parse
function to generate an AST. @danakt is this something you considered when writing the module, and do you have any reservations?
Need to escape reserved javascript words in handlebars expressions
Currently {{#if}}
is handled but not {{#unless}}
Example tests (there are formatting options for sure - I'm not super opinionated about that):
test('should convert condition unless-then ', () => {
expect(compile('<div>{{#unless variable}}<div/>{{/unless}}</div>')).toBe(
recompile('props => <div>{!Boolean(props.variable) && <div />}</div>;')
)
})
test('should convert condition unless-then-else ', () => {
expect(compile('<div>{{#unless variable}}<div/>{{else}}<span/>{{/unless}}</div>')).toBe(
recompile('props => <div>{!Boolean(props.variable) ? <div /> : <span />}</div>;')
)
})
Hbs code like this:
must be compiled to JSX code like this:
<div>Some {'{'}text{'}'}</div>;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.