diff --git a/app/assets/stylesheets/base.css.scss b/app/assets/stylesheets/base.css.scss index 6faf734..76f088b 100644 --- a/app/assets/stylesheets/base.css.scss +++ b/app/assets/stylesheets/base.css.scss @@ -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 { diff --git a/app/decorators/asciicast_decorator.rb b/app/decorators/asciicast_decorator.rb index db7671c..c8fdcca 100644 --- a/app/decorators/asciicast_decorator.rb +++ b/app/decorators/asciicast_decorator.rb @@ -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 [] diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 770142c..6f7ada9 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6bd73c5..c9d93c3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/asciicasts/_author.html.erb b/app/views/asciicasts/_author.html.erb index e7f3340..f2a446d 100644 --- a/app/views/asciicasts/_author.html.erb +++ b/app/views/asciicasts/_author.html.erb @@ -1,11 +1,11 @@
- <%= @asciicast.user.avatar_profile_link %> + <%= @asciicast.author_img_link %>

- <%= @asciicast.author_profile_link %> + <%= @asciicast.author_link %>

- <% if @asciicast.user.asciicasts_count -%> + <% if @asciicast.user -%>

<%= @asciicast.user.asciicasts_count %> asciicasts

<% end -%>
diff --git a/app/views/asciicasts/_preview.html.erb b/app/views/asciicasts/_preview.html.erb index f3d37b9..66bbc27 100644 --- a/app/views/asciicasts/_preview.html.erb +++ b/app/views/asciicasts/_preview.html.erb @@ -11,7 +11,7 @@

- <%= time_ago_tag asciicast.created_at %> by <%= asciicast.author_profile_link %> + <%= time_ago_tag asciicast.created_at %> by <%= asciicast.author_link %>

diff --git a/app/views/layouts/_session_info.html.erb b/app/views/layouts/_session_info.html.erb index a2c43e5..96c18ed 100644 --- a/app/views/layouts/_session_info.html.erb +++ b/app/views/layouts/_session_info.html.erb @@ -1,8 +1,8 @@