mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 14:36:31 +08:00
The avatar helper should be smart enough to find a nested avatar_template. Fixes #243
This commit is contained in:
parent
1492464158
commit
0f48414a72
|
@ -121,23 +121,28 @@ Handlebars.registerHelper('lower', function(property, options) {
|
||||||
@for Handlebars
|
@for Handlebars
|
||||||
**/
|
**/
|
||||||
Handlebars.registerHelper('avatar', function(user, options) {
|
Handlebars.registerHelper('avatar', function(user, options) {
|
||||||
var title, username;
|
|
||||||
if (typeof user === 'string') {
|
if (typeof user === 'string') {
|
||||||
user = Ember.Handlebars.get(this, user, options);
|
user = Ember.Handlebars.get(this, user, options);
|
||||||
}
|
}
|
||||||
username = Em.get(user, 'username');
|
|
||||||
if (!username) {
|
var username = Em.get(user, 'username');
|
||||||
username = Em.get(user, options.hash.usernamePath);
|
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) {
|
if (!options.hash.ignoreTitle) {
|
||||||
title = Em.get(user, 'title') || Em.get(user, 'description');
|
title = Em.get(user, 'title') || Em.get(user, 'description');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Handlebars.SafeString(Discourse.Utilities.avatarImg({
|
return new Handlebars.SafeString(Discourse.Utilities.avatarImg({
|
||||||
size: options.hash.imageSize,
|
size: options.hash.imageSize,
|
||||||
extraClasses: Em.get(user, 'extras') || options.hash.extraClasses,
|
extraClasses: Em.get(user, 'extras') || options.hash.extraClasses,
|
||||||
username: username,
|
username: username,
|
||||||
title: title || username,
|
title: title || username,
|
||||||
avatarTemplate: Ember.get(user, 'avatar_template') || options.hash.avatarTemplate
|
avatarTemplate: avatarTemplate
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{{#each content.allowed_users}}
|
{{#each content.allowed_users}}
|
||||||
<div class='user'>
|
<div class='user'>
|
||||||
<a href='/users/{{lower username}}'>
|
<a href='/users/{{lower username}}'>
|
||||||
{{avatar this avatarTemplatePath="avatar_template" imageSize="small"}}
|
{{avatar this imageSize="small"}}
|
||||||
</a>
|
</a>
|
||||||
<a href='/users/{{lower username}}'>
|
<a href='/users/{{lower username}}'>
|
||||||
{{unbound username}}
|
{{unbound username}}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{#collection contentBinding="stream" itemClass="item"}}
|
{{#collection contentBinding="stream" itemClass="item"}}
|
||||||
{{#with view.content}}
|
{{#with view.content}}
|
||||||
<div class='clearfix info'>
|
<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='time'>{{date path="created_at" leaveAgo="true"}}</span>
|
||||||
<span class="title">
|
<span class="title">
|
||||||
<a href="{{unbound postUrl}}">{{unbound title}}</a>
|
<a href="{{unbound postUrl}}">{{unbound title}}</a>
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
<div class='child-actions'>
|
<div class='child-actions'>
|
||||||
<i class="icon {{unbound icon}}"></i>
|
<i class="icon {{unbound icon}}"></i>
|
||||||
{{#each items}}
|
{{#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}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user