The avatar helper should be smart enough to find a nested avatar_template. Fixes #243

This commit is contained in:
Robin Ward 2013-02-26 15:31:49 -05:00
parent 1492464158
commit 0f48414a72
3 changed files with 14 additions and 9 deletions

View File

@ -121,23 +121,28 @@ Handlebars.registerHelper('lower', function(property, options) {
@for Handlebars
**/
Handlebars.registerHelper('avatar', function(user, options) {
var title, username;
if (typeof user === 'string') {
user = Ember.Handlebars.get(this, user, options);
}
username = Em.get(user, 'username');
if (!username) {
username = Em.get(user, options.hash.usernamePath);
}
var username = Em.get(user, 'username');
if (!username) username = Em.get(user, options.hash.usernamePath);
var avatarTemplate = Ember.get(user, 'avatar_template');
if (!avatarTemplate) avatarTemplate = Em.get(user, 'user.avatar_template');
var title;
if (!options.hash.ignoreTitle) {
title = Em.get(user, 'title') || Em.get(user, 'description');
}
return new Handlebars.SafeString(Discourse.Utilities.avatarImg({
size: options.hash.imageSize,
extraClasses: Em.get(user, 'extras') || options.hash.extraClasses,
username: username,
title: title || username,
avatarTemplate: Ember.get(user, 'avatar_template') || options.hash.avatarTemplate
avatarTemplate: avatarTemplate
}));
});

View File

@ -3,7 +3,7 @@
{{#each content.allowed_users}}
<div class='user'>
<a href='/users/{{lower username}}'>
{{avatar this avatarTemplatePath="avatar_template" imageSize="small"}}
{{avatar this imageSize="small"}}
</a>
<a href='/users/{{lower username}}'>
{{unbound username}}

View File

@ -2,7 +2,7 @@
{{#collection contentBinding="stream" itemClass="item"}}
{{#with view.content}}
<div class='clearfix info'>
<a href="/users/{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" avatarTemplatePath="avatar_template" ignoreTitle="true"}}</div></a>
<a href="/users/{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
<span class="title">
<a href="{{unbound postUrl}}">{{unbound title}}</a>
@ -40,7 +40,7 @@
<div class='child-actions'>
<i class="icon {{unbound icon}}"></i>
{{#each items}}
<a href="/users/{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" avatarTemplatePath="avatar_template" ignoreTitle="true"}}</div></a>
<a href="/users/{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" ignoreTitle="true"}}</div></a>
{{/each}}
</div>
{{/each}}