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

Accept arguments matching Handlebars.precompile #138

Closed wbyoung closed 5 years ago

wbyoung commented 10 years ago

It'd be nice if somehow we could get an object from Emblem.js that compiled input with the same arguments that Handlebars.precompile does.

This would really just be a convenience wrapper around methods that Emblem already exposes, but could make things more clear when used in certain circumstances. A discussion has popped up related to gulp.js on fuseelements/gulp-ember-handlebars#12. We're trying to reduce four different gulp.js plugins to one without making it too hard on the user.

I'd like to propose something like this:

Simple

Emblem.compiler().compile(contents, options);

Emblem + Ember

var EmberHandlebars = require('ember-template-compiler').EmberHandlebars;
Emblem.compiler(EmberHandlebars).compile(contents, options);

This will allow a gulp.js workflow which would be a bit easier (on the brain) than currying Emblem.precompile:

gulp.task('templates', function(){
  gulp.src(['templates/*.hbs'])
    .pipe(handlebars(
      compiler: Emblem.compiler(require('ember-template-compiler').EmberHandlebars)
    ))
    .pipe(defineModule('node'))
    .pipe(gulp.dest('build/templates/'));
});
phated commented 10 years ago

I really dig this approach, but I think the method should be called variant since it is creating a variant of the compiler.

wbyoung commented 10 years ago

Variant works for me… updated:

Simple

Emblem.compile(contents, options);
Emblem.precompile(contents, options);

Emblem + Ember

var EmberHandlebars = require('ember-template-compiler').EmberHandlebars;
Emblem.variant(EmberHandlebars).compile(contents, options);