Cleanup author/profile links

openid
Marcin Kulik 12 years ago
parent 3b2dc7f998
commit 816e09703a

@ -148,6 +148,10 @@ div.wrapper {
-moz-box-shadow: rgba(0,0,0,0.2) 0 0 0 1px,rgba(0,0,0,0.3) 0 1px 3px; -moz-box-shadow: rgba(0,0,0,0.2) 0 0 0 1px,rgba(0,0,0,0.3) 0 1px 3px;
box-shadow: rgba(0, 0, 0, 0.2) 0 0 0 1px, rgba(0, 0, 0, 0.3) 0 1px 3px; box-shadow: rgba(0, 0, 0, 0.2) 0 0 0 1px, rgba(0, 0, 0, 0.3) 0 1px 3px;
} }
.author .avatar {
margin: 1px;
}
} }
.cursor-block { .cursor-block {

@ -112,27 +112,26 @@ class AsciicastDecorator < ApplicationDecorator
end end
end end
def author_profile_link(options = {}) def author_link
if asciicast.user if user
if options[:avatar] user.link
img = avatar_img(asciicast.user) + " "
else else
img = "" author
end
end end
text = img + author def author_img_link
path = h.profile_path(asciicast.user) if user
user.img_link
h.link_to text, path
else else
author h.avatar_image_tag nil
end end
end end
def other_by_user def other_by_user
if asciicast.user if user
AsciicastDecorator.decorate( AsciicastDecorator.decorate(
asciicast.user.asciicasts.where('id <> ?', asciicast.id).limit(3) user.asciicasts.where('id <> ?', asciicast.id).limit(3)
) )
else else
[] []

@ -6,30 +6,17 @@ class UserDecorator < ApplicationDecorator
end end
def asciicasts_count def asciicasts_count
model && model.asciicasts.count model.asciicasts.count
end end
def avatar_img(options = {}) def link(options = {})
klass = options[:class] || "avatar" text = block_given? ? yield : nickname
title = options[:title] || user && nickname h.link_to text, h.profile_path(user), :title => options[:title] || nickname
h.image_tag user && user.avatar_url || default_avatar_url,
:title => title, :alt => title, :class => klass
end
def default_avatar_url
h.image_path "default_avatar.png"
end end
def avatar_profile_link(options = {}) def img_link(options = {})
options = { :class => '' }.merge(options) link(options) do
h.avatar_image_tag(user)
if user
h.link_to h.profile_path(user) do
avatar_img(options)
end
else
avatar_img(options)
end end
end end
end end

@ -40,4 +40,16 @@ module ApplicationHelper
options[:class] ||= "timeago" options[:class] ||= "timeago"
content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601)) content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601))
end end
def avatar_image_tag(user, options = {})
klass = options[:class] || "avatar"
title = options[:title] || user.try(:nickname)
avatar = user.try(:avatar_url) || default_avatar_filename
image_tag avatar, :alt => title, :class => klass
end
def default_avatar_filename
image_path "default_avatar.png"
end
end end

@ -1,11 +1,11 @@
<div class="author"> <div class="author">
<%= @asciicast.user.avatar_profile_link %> <%= @asciicast.author_img_link %>
<h2> <h2>
<%= @asciicast.author_profile_link %> <%= @asciicast.author_link %>
</h2> </h2>
<% if @asciicast.user.asciicasts_count -%> <% if @asciicast.user -%>
<p><%= @asciicast.user.asciicasts_count %> asciicasts</p> <p><%= @asciicast.user.asciicasts_count %> asciicasts</p>
<% end -%> <% end -%>
</div> </div>

@ -11,7 +11,7 @@
</h3> </h3>
<p class="date"> <p class="date">
<%= time_ago_tag asciicast.created_at %> by <%= asciicast.author_profile_link %> <%= time_ago_tag asciicast.created_at %> by <%= asciicast.author_link %>
</p> </p>
</div> </div>
</div> </div>

@ -1,8 +1,8 @@
<ul class="session-info"> <ul class="session-info">
<% if current_user %> <% if current_user %>
<li class="username"> <li class="username">
<%= current_user.avatar_profile_link(:title => '') %> <%= current_user.img_link(:title => '') %>
<%= link_to current_user.nickname, profile_path(current_user) %> <%= current_user.link(:title => '') %>
<ul class="menu"> <ul class="menu">
<li> <li>

@ -20,7 +20,7 @@
<div class="extras"> <div class="extras">
<h1><%= @user.nickname %></h1> <h1><%= @user.nickname %></h1>
<p><%= @user.avatar_img %></p> <p><%= avatar_image_tag @user %></p>
<h3><%= @user.asciicasts_count %> asciicasts</h3> <h3><%= @user.asciicasts_count %> asciicasts</h3>
<% if current_user %> <% if current_user %>

Loading…
Cancel
Save