Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vdom output (react or others). #1

Closed
DylanPiercey opened this issue Oct 22, 2015 · 2 comments
Closed

Support vdom output (react or others). #1

DylanPiercey opened this issue Oct 22, 2015 · 2 comments

Comments

@DylanPiercey
Copy link
Contributor

I haven't had a ton of time to dig into this library but it looks like a pretty solid templating language. I was wondering if there are any effort to support virtual DOM Esq output similar to JSX?

@philidem
Copy link
Member

@DylanPiercey I hadn't thought about compiling HTML to JavaScript code that builds a DOM but that would be possible and you could use htmljs-parser to do that. That's an interesting use case. This parser is generic enough such that it could be used by other libraries to compile to different output formats.

For example, if you wanted to compile HTML to React JS code you could take something like this:

<Person name=(window.isLoggedIn ? window.name : '') />

and compile it to:

var person = React.createElement(
  Person,
  {name: window.isLoggedIn ? window.name : ''}
);

You could also compile the HTML string into DOM creation code.

For example, you could compile:

<div class=(data.getClassName()) />

to:

var el = document.createElement('div');
el.className = (data.getClassName());

htmljs-parser will be used by http://markojs.com/ to compile Marko templates in the next major version (work in progress). Marko currently supports pure HTML-based templates but we want to enhance it to recognize JavaScript expressions. See marko-js/marko#90

Marko templates basically compile to a function that produces an HTML string but it would be interesting to considering creating an alternate compiled output that creates the DOM elements via JavaScript code.

@patrick-steele-idem
Copy link
Contributor

@DylanPiercey Just doing some issue cleanup. Since this is just a parser you could definitely use it as part of a compiler that produce virtual DOM output. I'm closing this issue, but if you have any thoughts or questions please feel free to add them here or open another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants