Skip to content

Commit

Permalink
Merge pull request refinery#97 from julesce/master
Browse files Browse the repository at this point in the history
Fix for archive bug
  • Loading branch information
ugisozols committed May 3, 2012
2 parents 5f39412 + e0e983c commit daa8c2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
Gemfile.lock
spec/dummy
.idea
25 changes: 9 additions & 16 deletions app/helpers/refinery/news/items_helper.rb
Expand Up @@ -28,23 +28,16 @@ def news_item_teaser(item)
end
end

def news_item_archive_link(item)
if item.publish_date >= Time.now.end_of_year.advance(:years => -3)
post_date = item.publish_date.strftime('%m/%Y')
year = post_date.split('/')[1]
month = post_date.split('/')[0]
count = News::Item.by_archive(Time.parse(post_date)).size
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"

link_to(text, refinery.news_items_archive_path(:year => year, :month => month))
else
post_date = post.publish_date.strftime('01/%Y')
year = post_date.split('/')[1]
count = Refinery::News::Item.by_year(Time.parse(post_date)).size
text = "#{year} (#{count})"

link_to(text, refinery.news_items_archive_path(:year => year))
def news_item_archive_links
html = ''
@item_months = ::Refinery::News::Item.published.group_by {|i| i.publish_date.beginning_of_month}
@item_months.each do |month, items|
if items.present?
text = "#{t("date.month_names")[month.month]} #{month.year} (#{items.count})"
html += "<li>#{link_to(text, refinery.news_items_archive_path(:year => month.year, :month => month.month))}</li>"
end
end
content_tag('ul', raw(html))
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions app/views/refinery/news/items/widgets/_news_archive.html.erb
@@ -1,10 +1,6 @@
<section id="news_archive_widget">
<h2><%= t('archives', :scope => 'refinery.news.shared') %></h2>
<nav>
<ul>
<% items.each do |item| %>
<li><%= news_item_archive_link(item) %></li>
<% end %>
</ul>
<%= news_item_archive_links %>
</nav>
</section>

0 comments on commit daa8c2c

Please sign in to comment.