Skip to content

Commit

Permalink
access config from app/addon options
Browse files Browse the repository at this point in the history
  • Loading branch information
siva-sundar committed Oct 4, 2017
1 parent 53dde0b commit d49229f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 67 deletions.
16 changes: 0 additions & 16 deletions blueprints/ember-hbs-minifier/default-config/.hbs-minifyrc.js

This file was deleted.

25 changes: 0 additions & 25 deletions blueprints/ember-hbs-minifier/index.js

This file was deleted.

8 changes: 8 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
// Add options here
'ember-hbs-minifier': {
whiteList: {
elementNodes: ['pre', 'address'],
elementClassNames: ['description'],
components: ['foo-bar'],
partials: []
}
}
});

/*
Expand Down
39 changes: 23 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@
module.exports = {
name: 'ember-hbs-minifier',

setupPreprocessorRegistry(type, registry) {
if (type === 'parent') {
let config;
try {
let path = this.isDevelopingAddon() ? `${this.project.root}/tests/dummy` : this.project.root;
config = require(`${path}/.hbs-minifyrc.js`);
} catch (error) {
throw error;
}
let HbsMinifierPlugin = require('./hbs-minifier-plugin')(config.whiteList);
registry.add('htmlbars-ast-plugin', {
name: 'hbs-minifier-plugin',
plugin: HbsMinifierPlugin,
baseDir() { return __dirname; }
});
}
_getMinifierOptions() {
return (this.parent && this.parent.options) || (this.app && this.app.options) || {};
},

_setupPreprocessorRegistry(app) {
let registry = app.registry;
let options = this._getMinifierOptions(app);
let config = options['ember-hbs-minifier'] || {};

let HbsMinifierPlugin = require('./hbs-minifier-plugin')(config.whiteList || {});
registry.add('htmlbars-ast-plugin', {
name: 'hbs-minifier-plugin',
plugin: HbsMinifierPlugin,
baseDir() { return __dirname; }
});
},
included(app) {
this._super.included.apply(this, arguments);
/*
Calling setupPreprocessorRegistry in included hook since app.options is not accessible
Refer PR: https://github.com/ember-cli/ember-cli/pull/7059
*/
this._setupPreprocessorRegistry(app);
}
};
10 changes: 0 additions & 10 deletions tests/dummy/.hbs-minifyrc.js

This file was deleted.

0 comments on commit d49229f

Please sign in to comment.