From dbedb27c04441dc7f5b9174f5dd710d30a698d75 Mon Sep 17 00:00:00 2001 From: Jamie Winsor Date: Fri, 29 Jul 2011 15:15:06 -0700 Subject: Refactor blog_archive_list helper function into blog_archive_widget function (with alias for compatability) Fix archive view for rails-3-1 support --- app/helpers/refinery/blog_posts_helper.rb | 56 ++++++++++++------------------- 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/refinery/blog_posts_helper.rb b/app/helpers/refinery/blog_posts_helper.rb index 58b0a3a..bfc3f40 100644 --- a/app/helpers/refinery/blog_posts_helper.rb +++ b/app/helpers/refinery/blog_posts_helper.rb @@ -1,43 +1,12 @@ module Refinery module BlogPostsHelper - def blog_archive_list + def blog_archive_widget posts = Refinery::BlogPost.select('published_at').all_previous return nil if posts.blank? - html = '

' - html << t('archives', :scope => 'blog.shared') - html << '

' - html.html_safe + render :partial => "/refinery/blog/widgets/blog_archive", :locals => { :posts => posts } end + alias_method :blog_archive_list, :blog_archive_widget def next_or_previous?(post) post.next.present? or post.prev.present? @@ -57,5 +26,24 @@ module Refinery }).html_safe end end + + def archive_link(post) + if post.published_at >= Time.now.end_of_year.advance(:years => -3) + post_date = post.published_at.strftime('%m/%Y') + year = post_date.split('/')[1] + month = post_date.split('/')[0] + count = BlogPost.by_archive(Time.parse(post_date)).size + text = t("date.month_names")[month.to_i] + " #{year} (#{count})" + + link_to(text, main_app.archive_blog_posts_path(:year => year, :month => month)) + else + post_date = post.published_at.strftime('01/%Y') + year = post_date.split('/')[1] + count = Refinery::BlogPost.by_year(Time.parse(post_date)).size + text = "#{year} (#{count})" + + link_to(text, main_app.archive_blog_posts_path(:year => year)) + end + end end end -- cgit v1.2.3