Skip to content

Commit

Permalink
Extract methods for creating absolute urls from methods that use them
Browse files Browse the repository at this point in the history
So that we can reuse the part of the presenter that creates the absolute
urls without having to use the part that generates html using the
absolute urls.
  • Loading branch information
carols10cents committed Jul 7, 2012
1 parent ce573a7 commit 4a3187f
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions app/decorators/author_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,42 @@ class AuthorDecorator < ApplicationDecorator
def avatar
h.content_tag "div", :class => "avatar" do
h.link_to(
h.image_tag(avatar_src, :class => "photo user-image", :alt => "avatar"),
h.image_tag(
absolute_avatar_url,
:class => "photo user-image",
:alt => "avatar"
),
author.url
)
end
end

# Creates a link to the user's website for their profile and adds http://
# if it isn't there
def website_link
url = if model.website[0,7] == "http://" or model.website[0,8] == "https://"
model.website
else
"http://#{model.website}"
end

h.link_to(url, url, :rel => 'website', :class => 'url')
end

private

# Make sure we're using the asset path if the user's avatar is the default
# (local) avatar
def avatar_src
def absolute_avatar_url
if author.avatar_url.eql? Author::DEFAULT_AVATAR
h.asset_path(author.avatar_url)
else
author.avatar_url
end
end

# Creates a link to the user's website for their profile
def website_link
h.link_to(
absolute_website_url,
absolute_website_url,
:rel => 'website',
:class => 'url'
)
end

# adds http:// if it isn't there
def absolute_website_url
if author.website[0,7] == "http://" or author.website[0,8] == "https://"
author.website
else
"http://#{author.website}"
end
end
end

0 comments on commit 4a3187f

Please sign in to comment.