Writing a Stash plugin and I want to display avatars for users.
In core Stash pages, I can see there are lots of AUI classes and a 'data-username' attribute around the gravatar images, but I also know that the location of the gravatar server can be modified and that custom, local avatars are in progress.
How can my plugin generate the same avatars that Stash will use for the same users / email?
Community moderators have prevented the ability to post new answers.
Hi Graham,
If you can try using the stash.widget.avatar soy function:
{namespace stash.widget} /** * @param size either 'xsmall', 'small', 'medium', 'large', 'xlarge', 'xxlarge' or 'xxxlarge' * @param person a StashUser or Person * @param? tooltip * @param? extraClasses * @param? imageClasses * @param? badgeContent extra HTML for badge * @param? hideBadge if true, the badge is hidden (but html is still present in the dom) * @param? id */ {template .avatar} ... {/template}
An example in the wild.
{call stash.widget.avatar} {param size: 'large' /} {param person: $user /} {/call}
Technically it's deferring to a Stash-specific soy function called avatarUrl() which takes a Person/StashUser java object ($user in this example). It's not something you can generate purely on the client-side (just as a warning).
Cheers,
Charles
PS. My usual disclaimer, this isn't technically public API and as such is something that may change in future versions (although I suspect it won't). We do plan on expanding and documenting our JS/Soy public API at some stage.
Thanks for the answer, Charles. Doesn't seem to be working in my environment, though. I get a SoyTofuException: "Attempting to render undefined template 'stash.widget.avatar'."
I also added the AvatarEnricher I saw in stash-suggest-reviewers' atlassian-plugin.xml file (I assume that's necessary?), but that didn't fix the problem above.
Stash version is 2.10.2 (2010002). Any ideas?
Cheers,
Graham.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Graham,
What does your atlassian-plugin.xml look like? Does adding the following fix that error?
<dependency>com.atlassian.stash.stash-web-plugin:avatar</dependency>
Ignore the AvatarEnricher unless you want to add the avatarUrls to Stash REST objects that you are returning.
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Charles. That dependency was the missing link.
Two trailing questions:
1) Is there a similar soy template for creating a link to a user profile based off a StashUser?
2) I know you're probably a bit removed from this, but is my use of something that "isn't technically public API" likely to prevent my plugin from being approved fo the marketplace?
Cheers,
Graham.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. {call stash.widget.avatarWithName}{param link: true /}...{/call}
2. I'm not sure what level of approval Marketplace do, but fortunately or unfortunately it's got nothing to do with API compatability.
While I know we need to improve our API documentation, my advice is to have a copy of the Stash source lying around so you can grep for examples. That's what I usually do. :)
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.