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;
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 {

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

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

@ -40,4 +40,16 @@ module ApplicationHelper
options[:class] ||= "timeago"
content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601))
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

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

@ -11,7 +11,7 @@
</h3>
<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>
</div>
</div>

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

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

Loading…
Cancel
Save