Skip to content

Instantly share code, notes, and snippets.

@ppcano ppcano/description.md
Last active Aug 29, 2015

Embed
What would you like to do?
Precompiling templates with Ember < 1.13 or = 1.13

We are not using ember-cli, so we need to precompile handlebars templates in our build process.

When upgrading from version 1.12 to 1.13, we encounter the error that input bindings were working as ONE-WAY bindings.

The solution was to change to the HTMLBarsPrecompiler filter (based on ember-cli-htmlbars).

//based on ember-cli-handlebars and working with Em 1.13
/*jshint node: true */
var Filter = require('broccoli-filter');
HTMLBarsPrecompiler.prototype = Object.create(Filter.prototype);
HTMLBarsPrecompiler.prototype.constructor = HTMLBarsPrecompiler;
function HTMLBarsPrecompiler (inputTree, options) {
if (!(this instanceof HTMLBarsPrecompiler)) { return new HTMLBarsPrecompiler(inputTree, options); }
options = options || {};
this.inputTree = inputTree;
this.templateCompiler = require('../../modules-bower/ember/ember-template-compiler');
}
HTMLBarsPrecompiler.prototype.extensions = ['hbs'];
HTMLBarsPrecompiler.prototype.targetExtension = 'js';
HTMLBarsPrecompiler.prototype.processString = function(content, relativePath) {
var precompiled = this.templateCompiler.precompile(content, {moduleName: relativePath});
var result = 'export default Ember.HTMLBars.template('+ precompiled +');';
return result;
};
HTMLBarsPrecompiler.prototype.read = function() {
return Filter.prototype.read.apply(this, arguments);
};
module.exports = HTMLBarsPrecompiler;
// This filter is not working with Em 1.13
//using htmlbars (0.13.30 or 0.13.32)
//based on broccoli-ember-inline-template-precompiler
//https://github.com/emberjs/emberjs-build/blob/master/lib/utils/inline-template-precompiler.js
var Filter = require('broccoli-filter');
EmberTemplatePrecompiler.prototype = Object.create(Filter.prototype);
EmberTemplatePrecompiler.prototype.constructor = EmberTemplatePrecompiler;
function EmberTemplatePrecompiler (inputTree, options) {
if (!(this instanceof EmberTemplatePrecompiler)) { return new EmberTemplatePrecompiler(inputTree, options); }
options = options || {};
this.inputTree = inputTree;
this.htmlbarsCompiler = require('htmlbars').compileSpec;
this.revision = 'Ember@'+require('../../modules-bower/ember/bower.json').version;
}
EmberTemplatePrecompiler.prototype.extensions = ['hbs'];
EmberTemplatePrecompiler.prototype.targetExtension = 'js';
EmberTemplatePrecompiler.prototype.processString = function(content, relativePath) {
var compileOptions = {
revision: this.revision
};
var compiledSpec = this.htmlbarsCompiler(content, compileOptions);
var template = 'import template from "ember-template-compiler/system/template";\n';
template += 'export default template('+ compiledSpec +');';
return template;
};
EmberTemplatePrecompiler.prototype.read = function() {
return Filter.prototype.read.apply(this, arguments);
};
module.exports = EmberTemplatePrecompiler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.