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

feature(icon-fingerprinting): Scaffolding for iconAsset fp #427

Closed
Closed
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
7 changes: 6 additions & 1 deletion addon/components/frost-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default Component.extend({
// == Dependencies ==========================================================

// == Keyword Properties ====================================================

classNameBindings: ['iconClass'],
layout,
tagName: 'svg',
Expand Down Expand Up @@ -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 ============================================================
Expand Down
16 changes: 16 additions & 0 deletions addon/initializers/icon-assets.js
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion addon/templates/components/frost-icon.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{! Template for the frost-icon component }}
<use xlink:href="assets/icon-packs/{{pack}}.svg#{{icon}}" />
<use xlink:href="{{pathToIconPack}}#{{icon}}"/>
1 change: 1 addition & 0 deletions app/initializers/icon-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, initialize } from 'ember-frost-core/initializers/icon-assets'
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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})
}
}
26 changes: 26 additions & 0 deletions tests/unit/initializers/icon-assets-test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})