machty / emblem.js

Emblem.js - Ember-friendly, indented syntax alternative for Handlebars.js
http://emblemjs.com
MIT License
1.04k stars 81 forks source link

WIP Ember-CLI, Refactor to printing #196

Closed mixonic closed 9 years ago

mixonic commented 9 years ago

Emblem is languishing due to an inability to keep up with the Handlebars AST. In theory the Handlebars AST is stable- in practice it has been changing fairly rapidly.

To add Emblem support for Ember.js 1.9 (Handlebars 2.0), Ember.js 1.10+ (HTMLBars), and even the upcoming Handlebars 3.0, the library must de-couple from the AST and target a more stable output format.

In Ember, at the least, we've already taken massive pains to ensure template syntax is the same across versions regardless of the template engine. The template syntax itself is the stable target we should be compiling Emblem to. Emblem becomes a "Handlebars printer" instead of an AST-targeting compiler.

To achieve this transition, @bantic and I have leaned on a few lessons from tildeio/htmlbars internals.

The Emblem compilation pipeline used to work something like this:

The leaking of what AST version should be built into the parser couples Emblem to the details of that those ASTs, and makes the parser very complex.

Our refactor changes Emblem's compilation pipeline to be more traditional:

In practice the AST and template compiler are fairly simple. The parser, responsible for the grammar of Emblem, remains very complex.

A side benefit of compiling to a uncompiled Handlebars template is that with a small amount of effort into pretty-printing, Emblem users will have an escape path if they want to start using standard Ember templates. Removing the current threat of "lock in" only makes Emblem more attractive as a tool.

There are a few TODOs that likely need to land before this branch of Emblem can be considered a totally complete replacement for the current master. That said, we are soon to be using it in production and have tested it in a real app with ~180 templates.

TODO:

Also worth noting are the https://github.com/bantic/emblem.js/blob/ember-cli/ROADMAP.md and https://github.com/bantic/emblem.js/blob/ember-cli/VANILLA_HANDLEBARS.md documents.

thec0keman commented 9 years ago

I've run into a few issues with compiling emblem templates:

Thanks so much for all of your hard work!

mixonic commented 9 years ago

@thec0keman you mean compiling them this with branch? Thanks for the check! We will add those to the list of things to confirm/fix.

atsjj commented 9 years ago

@mixonic @bantic thanks for killin' it with this work; it's totally awesome!

mixonic commented 9 years ago

@atsjj Thanks. We will put in some more time on this next week, hopefully close enough gaps to get it mergeable.

mphasize commented 9 years ago

This looks like an awesome piece of work and I really like the idea of offering a way to go back to Handlebars if necessary.

drewcovi commented 9 years ago

out of curiosity, is the escape path bi-directional?

as a front-end designer, having emblem has proven invaluable to quick changes in scaffolding and layout, but in-light of recent events we've had to abandon emblem temporarily.

it would be stellar if we could (at some point) quickly convert files back and forth.

mixonic commented 9 years ago

@drewcovi We have no plans to write an Emblem printer for Handlebars syntax.

mmun commented 9 years ago

It's not trivial to transpile Handlebars to Emblem because that requires an HTML parser. Seems in-scope for HTMLBars though.

jimmay5469 commented 9 years ago

Does this PR include the work to get this to work outside of ember-cli as well? We are using emblem with ember-rails.

bantic commented 9 years ago

@jimmay5469 Yeah, when this lands it will be possible to use the updated emblem parser outside of ember-cli. The emblem gem will need to be updated to use the updated version of emblem.

bantic commented 9 years ago

@thec0keman thanks for testing this branch out last week. a0b9484 above should fix your issue with the underscores, and the others will be fixed soon.

thec0keman commented 9 years ago

Thanks guys for all of your hard work. Our 500+ templates are compiling great now!

Two things:

mixonic commented 9 years ago

replaced by https://github.com/machty/emblem.js/pull/206, and tickets in https://github.com/machty/emblem.js/milestones/0.5.0