Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Emblem.js Without Ember

I'm trying emblem.js right now. It's a really good wrapper of Handlebars to write templates. However, the docs are a bit ember.js and handlebars.js dependent. I want to use Emblem.js without Ember, but there is no real explanation on how to compile the template.

So can we use emblem.js without ember (or better, without Handlebars dependency)? The way I'm doing it right now, I have this function to render the template:

function render(target, tmpl, data) {
    var source   = tmpl.html();
    var template = Emblem.compile(Handlebars, source);
    var result = template(data);

    target.html(result);
}

Is that the correct way to compile Emblem? It works, but I have a gut feeling that there's a better way to do that. In Handlebars, the compile line is quite similar:

var template = Handlebars.compile(source);

Thanks for the answers.

like image 492
Henson Avatar asked May 15 '13 04:05

Henson


1 Answers

You're actually doing it correctly.

Emblem compiles down to a Handlebars runtime, and therefore needs you to specify which Handlebars variant you'd like to compile to. In your case, because you don't want Ember functionality, you'll want

Emblem.compile(Handlebars, source);

If you wanted Ember support, you'd need to use the Ember.Handlebars variant

Emblem.compile(Ember.Handlebars, source);

I'll definitely make sure to add this stuff to the docs.

like image 132
Alexander Wallace Matchneer Avatar answered Sep 30 '22 09:09

Alexander Wallace Matchneer