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

Ensure EmberENV is pass through to the template compiler. #57

Merged
merged 1 commit into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {

var htmlbarsOptions = {
isHTMLBars: true,
FEATURES: EmberENV.FEATURES,
EmberENV: EmberENV,
templateCompiler: require(templateCompilerPath),

plugins: {
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ TemplateCompiler.prototype.registerPlugins = function registerPlugins() {
};

TemplateCompiler.prototype.initializeFeatures = function initializeFeatures() {
var EmberENV = this.options.EmberENV;
var FEATURES = this.options.FEATURES;
var templateCompiler = this.options.templateCompiler;

utils.initializeFeatures(templateCompiler, FEATURES);
if (FEATURES) {
console.warn('Using `options.FEATURES` with ember-cli-htmlbars is deprecated. Please provide the full EmberENV as options.EmberENV instead.');
EmberENV = EmberENV || {};
EmberENV.FEATURES = FEATURES;
}

utils.initializeEmberENV(templateCompiler, EmberENV);
};

TemplateCompiler.prototype.processString = function (string, relativePath) {
Expand Down
26 changes: 21 additions & 5 deletions test/template_compiler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ describe('templateCompilerFilter', function(){
htmlbarsPrecompile = htmlbarsOptions.templateCompiler.precompile;
});

afterEach(function() {

});

it('precompiles templates into htmlbars', function(){
var tree = templateCompilerFilter(sourcePath, htmlbarsOptions);

Expand All @@ -43,7 +39,7 @@ describe('templateCompilerFilter', function(){
});
});

it('passes FEATURES to compiler', function(){
it('passes FEATURES to compiler when provided as `FEATURES` [DEPRECATED]', function(){
htmlbarsOptions.FEATURES = {
'ember-htmlbars-component-generation': true
};
Expand All @@ -59,4 +55,24 @@ describe('templateCompilerFilter', function(){
assert.equal(actual,expected,'They dont match!');
});
});

it('passes FEATURES to compiler when provided as `EmberENV.FEATURES`', function(){
htmlbarsOptions.EmberENV = {
FEATURES: {
'ember-htmlbars-component-generation': true
}
};

var tree = templateCompilerFilter(sourcePath, htmlbarsOptions);

builder = new broccoli.Builder(tree);
return builder.build().then(function(results) {
var actual = fs.readFileSync(results.directory + '/web-component-template.js', { encoding: 'utf8'});
var source = fs.readFileSync(sourcePath + '/web-component-template.hbs', { encoding: 'utf8' });
var expected = 'export default Ember.HTMLBars.template(' + htmlbarsPrecompile(source, { moduleName: 'web-component-template.hbs' }) + ');';

assert.equal(actual,expected,'They dont match!');
});
});

});
34 changes: 34 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';
var utils = require('../utils');
var assert = require('assert');

describe('utils', function(){
var templateCompiler;

beforeEach(function() {
templateCompiler = require('../bower_components/ember/ember-template-compiler');
});


it('passes other ENV variables to compiler when provided', function(){
var EmberENV = {
FOO_BAR: true
};

utils.initializeEmberENV(templateCompiler, EmberENV);

assert.equal(templateCompiler._Ember.ENV.FOO_BAR, true);
});

it('passes features through when provided', function(){
var EmberENV = {
FEATURES: {
BLAH: true
}
};

utils.initializeEmberENV(templateCompiler, EmberENV);

assert.equal(templateCompiler._Ember.FEATURES.BLAH, true);
});
});
26 changes: 21 additions & 5 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
'use strict';

module.exports = {
initializeFeatures: function(templateCompiler, FEATURES) {
if (FEATURES && templateCompiler) {
for (var feature in FEATURES) {
templateCompiler._Ember.FEATURES[feature] = FEATURES[feature];
}
initializeEmberENV: function(templateCompiler, EmberENV) {
if (!templateCompiler || !EmberENV) { return; }

var props;

if (EmberENV.FEATURES) {
props = Object.keys(EmberENV.FEATURES);

props.forEach(function(prop) {
templateCompiler._Ember.FEATURES[prop] = EmberENV.FEATURES[prop];
});
}

if (EmberENV) {
props = Object.keys(EmberENV);

props.forEach(function(prop) {
if (prop === 'FEATURES') { return; }

templateCompiler._Ember.ENV[prop] = EmberENV[prop];
});
}
},

Expand Down