Last active
August 29, 2015 14:11
-
-
Save pwfisher/3095ebc74220203583f8 to your computer and use it in GitHub Desktop.
SVG Sprite Icons in Ember.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp.task('build-svg-icon-sprite', function () { | |
return gulp.src(conf.get('build:svg-sprite-icons:source')) | |
.pipe(svgo({ | |
full: false, | |
plugins: [ | |
{ cleanupIDs: true }, | |
{ removeUnknownsAndDefaults: false } | |
] | |
})) | |
.pipe(fc2json('svg-icon-sprite.json')) | |
.pipe(gulp.dest( conf.get('build:icons:dest') )); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.initializer({ | |
name: 'svg-sprite-icons', | |
initialize: function (container, application) { | |
application.inject('component', 'store', 'store:main'); | |
container.lookup('store:main').findAll('svg-sprite-icon'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.SvgSpriteIcon = DS.Model.extend({ | |
svg: DS.attr() | |
}); | |
App.SvgSpriteIconAdapter = DS.Adapter.extend({ | |
findAll: function (store, type, sinceToken) { | |
return $.ajax({ | |
dataType: 'json', | |
url: this.buildURL(type.typeKey) | |
}); | |
}, | |
buildURL: function () { | |
return assetService.buildURL('svg-icon-sprite.json'); | |
} | |
}); | |
App.SvgSpriteIconSerializer = DS.RESTSerializer.extend({ | |
normalizePayload: function (payload) { | |
var icons = []; | |
for (var icon in payload) { | |
icons.push({ | |
id: icon.replace('.svg', ''), | |
svg: payload[icon] | |
}); | |
} | |
return this._super({ svg_sprite_icons: icons }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment