an identicon.js
addon for ember-cli v1.13.8
apps
ember install ember-cli-identicon
in app/pods/components/user-avatar/component.js
import Ember from 'ember';
export default Ember.Component.extend({
// Inject a reference to the identicon service provided by this addon
identicon: Ember.inject.service(),
// Profile image src. If user does not have an associated image, generate
// an icon using the identicon.js service
src: function() {
// look for an image attribute on the user record and return it if found
var image = this.get('user.image');
if (image) {
return image;
}
// get a reference to the identicon service and any options provided from
// outside this component
var identicon = this.get('identicon'),
options = this.get('options') || {};
// generate an identicon using the user's email address and any provided
// options, with defaults: 20% margin between the edge of the image and the
// generated pattern, 48x48px in dimension, and a background color of
// RGB(224, 224, 224)
return identicon.create(this.get('user.email'), {
margin: options.margin || 0.2,
size: options.size || 48,
bgColors: options.bgColors || [224,224,224]
});
}.property('user')
});
in app/pods/components/user-avatar/template.hbs
git clone
this reponpm install
ember g ember-cli-identicon
ember test
ember test --server
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright (c) 2015 Chris Ludden. Licensed under the MIT license.
For more information on using ember-cli, visit http://www.ember-cli.com/.