Class: Refinery::Blog::PostsHelper::ArchiveWidget

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/refinery/blog/posts_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dates, view_context, cutoff = 3.years.ago.end_of_year) ⇒ ArchiveWidget

Returns a new instance of ArchiveWidget.



40
41
42
43
44
45
# File 'app/helpers/refinery/blog/posts_helper.rb', line 40

def initialize(dates, view_context, cutoff=3.years.ago.end_of_year)
  @recent_dates, @old_dates = dates.sort_by {|date| -date.to_i }.
    partition {|date| date > cutoff }

  @view_context = view_context
end

Instance Attribute Details

#view_contextObject (readonly)

Returns the value of attribute view_context.



38
39
40
# File 'app/helpers/refinery/blog/posts_helper.rb', line 38

def view_context
  @view_context
end

Instance Method Details

#displayObject



70
71
72
73
# File 'app/helpers/refinery/blog/posts_helper.rb', line 70

def display
  return "" if links.empty?
  render "refinery/blog/widgets/blog_archive", :links => links
end


66
67
68
# File 'app/helpers/refinery/blog/posts_helper.rb', line 66

def links
  recent_links + old_links
end


62
63
64
# File 'app/helpers/refinery/blog/posts_helper.rb', line 62

def old_link(year, count)
  link_to "#{year} (#{count})", refinery.blog_archive_posts_path(:year => year)
end


57
58
59
60
# File 'app/helpers/refinery/blog/posts_helper.rb', line 57

def old_links
  @old_dates.group_by {|date| date.year }.
    map {|year, dates| old_link(year, dates.size) }
end


52
53
54
55
# File 'app/helpers/refinery/blog/posts_helper.rb', line 52

def recent_link(year, month, count)
  link_to "#{t("date.month_names")[month]} #{year} (#{count})",
    refinery.blog_archive_posts_path(:year => year, :month => month)
end


47
48
49
50
# File 'app/helpers/refinery/blog/posts_helper.rb', line 47

def recent_links
  @recent_dates.group_by {|date| [date.year, date.month] }.
    map {|(year, month), dates| recent_link(year, month, dates.count) }
end