diff --git a/addon/components/frost-icon.js b/addon/components/frost-icon.js index 5421aa05..01625f36 100644 --- a/addon/components/frost-icon.js +++ b/addon/components/frost-icon.js @@ -13,7 +13,6 @@ export default Component.extend({ // == Dependencies ========================================================== // == Keyword Properties ==================================================== - classNameBindings: ['iconClass'], layout, tagName: 'svg', @@ -51,6 +50,12 @@ export default Component.extend({ return `frost-icon-${pack}-${icon}` }, + @readOnly + @computed('pack') + pathToIconPack (pack) { + return this._iconAssets[`assets/icon-packs/${pack}.svg`] + }, + // == Functions ============================================================= // == DOM Events ============================================================ diff --git a/addon/initializers/icon-assets.js b/addon/initializers/icon-assets.js new file mode 100644 index 00000000..4fa1de57 --- /dev/null +++ b/addon/initializers/icon-assets.js @@ -0,0 +1,16 @@ +import Ember from 'ember' + +export function initialize (application) { + application.deferReadiness() + + return Ember.$.get('assets/assetMap.json') + .then((assetMap) => { + application.register('icon-assets:main', Ember.Object.extend(assetMap.assets)) + application.inject('component:frost-icon', '_iconAssets', 'icon-assets:main') + }).always(() => application.advanceReadiness()) +} + +export default { + name: 'icon-assets', + initialize +} diff --git a/addon/templates/components/frost-icon.hbs b/addon/templates/components/frost-icon.hbs index 9a07af02..20a67cff 100644 --- a/addon/templates/components/frost-icon.hbs +++ b/addon/templates/components/frost-icon.hbs @@ -1,2 +1,2 @@ {{! Template for the frost-icon component }} - + diff --git a/app/initializers/icon-assets.js b/app/initializers/icon-assets.js new file mode 100644 index 00000000..f8bf6267 --- /dev/null +++ b/app/initializers/icon-assets.js @@ -0,0 +1 @@ +export { default, initialize } from 'ember-frost-core/initializers/icon-assets' diff --git a/index.js b/index.js index 2d59ff8b..8bd75d38 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ // 'use strict' +const AssetRev = require('broccoli-asset-rev') const writeFile = require('broccoli-file-creator') const Funnel = require('broccoli-funnel') const mergeTrees = require('broccoli-merge-trees') @@ -169,16 +170,22 @@ module.exports = { return mergeTrees([addonTree, iconNameTree], {overwrite: true}) }, - /* eslint-enable complexity */ - - treeForPublic: function (tree) { + /** + * Override of `treeForPublic` is to merge the + * existing tree for public files with the set of + * svg assets, supplied in the `svg` directory + * @param {[type]} treeForPublic [description] + * @return {[type]} [description] + */ + /* eslint-enable complexity */ + treeForPublic: function (treeForPublic) { const isAddon = this.project.isEmberCLIAddon() const addonPackages = pickBy(this.project.addonPackages, (addonPackage) => { return has(addonPackage.pkg, 'ember-frost-icon-pack') }) - const iconPacks = Object.keys(addonPackages).map((addonName) => { + let iconPacks = Object.keys(addonPackages).map((addonName) => { const addonPackage = addonPackages[addonName] const iconPack = addonPackage.pkg['ember-frost-icon-pack'] const iconPackPath = iconPack.path || 'svgs' @@ -209,6 +216,13 @@ module.exports = { })) } - return mergeTrees(iconPacks, {overwrite: true}) + const mergedIconPacks = mergeTrees(iconPacks, {overwrite: true}) + + const assetRevisedIconPacks = new AssetRev(mergedIconPacks, { + enabled: true, + extensions: ['svg'], + generateAssetMap: true + }) + return mergeTrees([assetRevisedIconPacks, treeForPublic], {overwrite: true}) } } diff --git a/tests/unit/initializers/icon-assets-test.js b/tests/unit/initializers/icon-assets-test.js new file mode 100644 index 00000000..f943e1d4 --- /dev/null +++ b/tests/unit/initializers/icon-assets-test.js @@ -0,0 +1,26 @@ +import { expect } from 'chai' +import Ember from 'ember' +import { describe, it, beforeEach, afterEach } from 'mocha' +import destroyApp from '../../helpers/destroy-app' +import { initialize } from 'dummy/initializers/icon-assets' + +describe('Unit | Initializer | icon assets', function () { + let application + + beforeEach(function () { + Ember.run(function () { + application = Ember.Application.create() + application.deferReadiness() + }) + }) + + afterEach(function () { + destroyApp(application) + }) + + // TODO: Add real tests + it('works', function () { + initialize(application) + expect(true).to.equal(true) + }) +})