How would you refactor this logic filled partial?
<%- for post in @posts -%>
<div class="post">
<%= link_to post.title, post %>
<%- if post.name.empty? -%>
<%- else -%>
<span class="name">
by
<%- if post.email.blank? -%>
<%= post.name %>
<%- else -%>
<a href="mailto:<%= post.email %>"><%= post.name %></a>
<%- end -%>
</span>
<%- end -%>
<span class="time">
active   <%= timeago(post.updated_at) %>
</span>
<%- if post.comments.empty? -%>
<span class="reply">
<%= link_to 'reply', :controller => 'posts', :action => 'show', :id => post %>
</span>
<% else %>
<span class="reply">
<%= link_to pluralize(post.comments.count, 'reply'), :controller => 'posts', :action => 'show', :id => post %>
</span>
<%- end -%>
<p><%= sanitize post.content,
:tags => %w(a embed img object p param),
:attributes => %w(allowfullscreen allowscriptaccess href name src type value) %></p>
<%- unless controller.controller_name == "tags" -%>
<%- unless post.tag_list.nil? || post.tag_list.empty? -%>
<%- post.tags.each do |t| -%>
<div class="tag"><%= link_to t.name.titleize, tag_path(t) %></div>
<%- end -%>
<%- end -%>
<%- end -%>
<%- unless post.comments.empty? -%>
<div class="comments">
<%= render :partial => post.firstcomments %>
<%- if post.comments.count >= 4 -%>
<%= link_to 'more...', :action => 'show', :id => message %>
<%- end -%>
</div>
<%- end -%>
</div>
<%- end -%>
Notes: post.firstcomments just returns the 3 latest posts. Using Rails 3 and Ruby 1.9.2. I haven't looked into the sanitize portion of the code, and I realize Rails 3 escapes everything by default, so it can safely be ignored for now unless someone knows how to convert it.
My models are clean and my controllers are decent but this partial is awful. It does what it needs to do but it takes up most of the rendering time when refreshing the page. Comments, suggestions and code are much appreciated. Thank you for reading my question.