Skip to content

Commit

Permalink
Improves the author page
Browse files Browse the repository at this point in the history
* Displays the user avatar if it exists.
* Only load the 10 latest articles
* Paginate the other articles

Issue publify#231

TODO:

* Include the 10 latest notes (need to define how)
* Only display the complete bio on the first page.
* On the other page, display the first paragraph of the bio, the photo and the articles.
* Mix articles and contents like on the home page (make it optional?)
  • Loading branch information
Frédéric de Villamil committed Sep 11, 2013
1 parent 4898c5f commit 1fd27ea
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
10 changes: 8 additions & 2 deletions app/controllers/authors_controller.rb
Expand Up @@ -4,7 +4,14 @@ class AuthorsController < ContentController
def show
@author = User.find_by_login(params[:id])
raise ActiveRecord::RecordNotFound unless @author
@articles = @author.articles.published

respond_to do |format|
format.html { @limit = this_blog.limit_article_display }
format.rss { @limit = this_blog.limit_rss_display }
format.atom { @limit = this_blog.limit_rss_display }
end

@articles = @author.articles.published.page(params[:page]).per(@limit)
@page_title = this_blog.author_title_template.to_title(@author, this_blog, params)
@keywords = this_blog.meta_keywords
@description = this_blog.author_desc_template.to_title(@author, this_blog, params)
Expand All @@ -25,7 +32,6 @@ def show
end

private

def render_feed format
render "show_#{format}_feed", :layout => false
end
Expand Down
16 changes: 13 additions & 3 deletions app/helpers/application_helper.rb
Expand Up @@ -90,17 +90,27 @@ def author_link(article)
end
end

def display_user_avatar(user_id)
def display_user_avatar(user_id, size='avatar', klass='alignleft')
user = User.find(user_id)

if user.avatar.present?
avatar = user.avatar
avatar = case size
when 'thumb'
user.thumb_avatar
when 'medium'
user.medium_avatar
when 'large'
user.large_avatar
else
user.avatar
end

elsif user.twitter_profile_image.present?
avatar = user.twitter_profile_image.present?
end

return unless avatar
image_tag(File.join(this_blog.base_url, avatar))
image_tag(File.join(this_blog.base_url, avatar), :alt => user.nickname, :class => klass)
end

def author_picture(status)
Expand Down
14 changes: 8 additions & 6 deletions app/views/authors/show.html.erb
@@ -1,5 +1,9 @@
<div class="post">
<h2><%= @author.name %></h2>
<h2><%= @author.nickname %></h2>
<%= display_user_avatar(@author.id, 'thumb', 'alignright') %>
<%= @author.description%>

<h2><%= _("Contact information") %></h2>
<ul>
<%= display_profile_item @author.url, _("Web site:") %>
<%= display_profile_item @author.msn, _("MSN:") %>
Expand All @@ -8,9 +12,6 @@
<%= display_profile_item @author.aim, _("AIM:") %>
<%= display_profile_item @author.twitter, _("Twitter:") %>
</ul>

<h3><%= _("About %s", @author.name)%></h3>
<%= @author.description%>
</div>

<% if @articles.empty? -%>
Expand All @@ -33,5 +34,6 @@
<%= article.categories.collect {|c| link_to_permalink c,c.name }.join(", ") -%>
<% end -%>
</div>
<% end
end -%>
<% end %>
<%= paginate @articles, :next_label => "#{_("Next page")} &raquo;", :previous_label => "&laquo; #{_('Previous page')}" %>
<% end -%>
14 changes: 13 additions & 1 deletion spec/controllers/authors_controller_spec.rb
Expand Up @@ -34,6 +34,19 @@
it 'has a link to the atom feed' do
response.should have_selector("head>link[href=\"http://test.host/author/#{user.login}.atom\"]")
end

it 'includes an image to the user avatar when available' do
response.should have_selector("img[alt=\"James Bond\"]")
end

it 'completed profile items should show accurate information' do
response.should have_selector('li', :content => "Twitter: @getpublify")
end

it 'not completed profile items should show accurate information' do
response.should_not have_selector('li', :content => "Jabber: @getpublify")
end

end
end

Expand Down Expand Up @@ -93,5 +106,4 @@
get 'show', :id => 'alice'
response.should_not have_selector('head>meta[name="keywords"]')
end

end
7 changes: 6 additions & 1 deletion spec/factories.rb
Expand Up @@ -17,12 +17,17 @@
login { FactoryGirl.generate(:user) }
email { generate(:email) }
name 'Bond'
nickname "James Bond"
notify_via_email false
notify_on_new_articles false
notify_on_comments false
password 'top-secret'
settings({})
avatar 'avatar.jpg'
medium_avatar 'medium_avatar.jpg'
thumb_avatar 'thumb_avatar.jpg'
large_avatar 'large_avatar.jpg'
state 'active'
twitter '@getpublify'
profile
association :text_filter, factory: :textile
end
Expand Down

0 comments on commit 1fd27ea

Please sign in to comment.