Class: Refinery::Blog::PostsHelper::ArchiveWidget
- Inherits:
-
Object
- Object
- Refinery::Blog::PostsHelper::ArchiveWidget
- Defined in:
- app/helpers/refinery/blog/posts_helper.rb
Instance Attribute Summary collapse
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(dates, view_context, cutoff = 3.years.ago.end_of_year) ⇒ ArchiveWidget
constructor
A new instance of ArchiveWidget.
- #links ⇒ Object
- #old_link(year, count) ⇒ Object
- #old_links ⇒ Object
- #recent_link(year, month, count) ⇒ Object
- #recent_links ⇒ Object
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_context ⇒ Object (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
#display ⇒ Object
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 |
#links ⇒ Object
66 67 68 |
# File 'app/helpers/refinery/blog/posts_helper.rb', line 66 def links recent_links + old_links end |
#old_link(year, count) ⇒ Object
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 |
#old_links ⇒ Object
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 |
#recent_link(year, month, count) ⇒ Object
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 |
#recent_links ⇒ Object
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 |