Created
May 9, 2014 00:00
-
-
Save blvrd/75eb064e2b4b7eda493a to your computer and use it in GitHub Desktop.
Generate default avatars
This file contains 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
#### Model | |
def initials | |
[Person.first_letter(first_name), Person.first_letter(last_name)].compact.join("") | |
end | |
# "try" is a method Ryan showed me. It sends whatever method you specify | |
# and if it doesn't work, it returns nil instead of an error. | |
def self.first_letter(string) | |
string.try(:split, "").try(:first) | |
end | |
#### Application helper | |
def avatar_for(person) | |
content_tag(:div, content_tag(:div, person.initials, class: "initials"), class: "avatar") | |
end | |
#### Stylesheet | |
@mixin borderRadius($dims:200px){ | |
-webkit-border-radius: $dims; | |
-moz-border-radius: $dims; | |
border-radius: $dims; | |
} | |
.avatar { | |
display: inline-block; | |
margin-right: 10px; | |
position: relative; | |
width: 50px; | |
height: 50px; | |
line-height: 3.5; | |
@include borderRadius(50px); | |
background: #ccc; | |
color: white; | |
.initials { | |
vertical-align: middle; | |
text-align: center; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment