pfaffman
(Jay Pfaffman)
June 8, 2017, 4:30pm
1
I’m doing an import and all of the usernames are integers. Most users have avatars, but those that don’t end up with something like as their avatar.
Is there some way to have them generated by their name rather than username?
Perhaps the importer can call LetterAvatar::Identity.generate(name, SOME_SIZE)
?
Falco
(Falco)
June 8, 2017, 4:47pm
2
You can write a plugin (maybe a pr?) that will allow you to use the first name char on the setting external system avatars url
.
Currently it accepts: “Allowed substitutions are {username} {first_letter} {color} {size}”
Adding {name_first _letter} to that is the way to go.
1 Like
pfaffman
(Jay Pfaffman)
June 8, 2017, 4:51pm
3
Oh. So you’re saying that what I want is to be able to change external system avatars url
to
/letter_avatar_proxy/v2/letter/{name_first_letter}/{color}/{size}.png
And that “all” I would have to do is make a PR that defined name_first_letter
?
That seems “easy” if I knew where to find the file that defines those substitutions.
pfaffman
(Jay Pfaffman)
June 8, 2017, 4:54pm
5
OMG. I might actually submit a PR that doesn’t involve shell scripts.
1 Like
Falco
(Falco)
June 8, 2017, 4:57pm
6
Well I would first start with a plugin, so you can get it immediately working.
1 Like
pfaffman
(Jay Pfaffman)
June 8, 2017, 5:02pm
7
But it seems like I could make a PR that involved about 2 lines of code, something like
u=User.find_by_username(username)
name = some stuff if that search fails or there's no name
...
url.gsub! "{name_first_letter", name[0].downcase
...
And it’d take me a Long Time to figure out how to make a plugin do that.
And it’d need to be a bit more complicated not not needlessly do a username lookup every time, so it might not be as easy a PR as I’d thought, so maybe I"ll have to figure out the plugin after all.
pfaffman
(Jay Pfaffman)
June 8, 2017, 5:54pm
9
I wouldn’t have thought it possible, but with your help, I did it!
Thanks, @falco !
This plugin adds the ability to use name_first_letter in site setting external system avatars url.
The default value for external system avatars url is
/letter_avatar_proxy/v2/letter/{first_letter}/{color}/{size}.png.
This plugin allows you to use
/letter_avatar_proxy/v2/letter/{name_first_letter}/{color}/{size}.png
to have the avatar be the first letter of the name rather than username. If there is no name, the username is used.
You must change the site setting for the plugin to have any …
7 Likes