Skip to content

Instantly share code, notes, and snippets.

@mitchell-garcia
Created April 8, 2016 17:06
Show Gist options
  • Save mitchell-garcia/d16ad52c03c17902bc42e5e5158145f9 to your computer and use it in GitHub Desktop.
Save mitchell-garcia/d16ad52c03c17902bc42e5e5158145f9 to your computer and use it in GitHub Desktop.
Example of binding attribute to style
export default Ember.Component.extend({
attributeBindings: ['background:style'],
size: 'medium',
background: computed('user.[]', function() {
const email = this.get('user.email');
const size = this.get('size');
const defaultAvatar = `//www.gravatar.com/avatar/${md5(email)}.jpg`;
const avatar_path = this.get('user.avatar') ? this.get('user.avatar') : defaultAvatar;
const color = this.get('calculateTheColor');
let string = '';
if(avatar_path) {
string = 'background:url(' + avatar_path + ') no-repeat center; background-size:cover;';
} else {
string = 'background:' + color + ';';
}
let value = Ember.Handlebars.Utils.escapeExpression(string);
return Ember.String.htmlSafe(value);
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment