Module PostsHelper
In: app/helpers/posts_helper.rb

Methods

Public Instance methods

Build links to archived posts

[Source]

    # File app/helpers/posts_helper.rb, line 4
 4:   def archive_navigation(mailing_list, month, year)
 5:     if mailing_list.dates
 6:       nav = Builder::XmlMarkup.new(:indent=>2)
 7:       nav.div({:class => "top_margin archive_navigation centered last"}) { |nav|
 8:         nav.div {
 9:           for y in (mailing_list.dates.first.year)..(mailing_list.dates.last.year)
10:             if y != year
11:               nav.a(y, :href => url_for(
12:                 :controller => "posts", 
13:                 :mailing_list_name => @mailing_list.name, 
14:                 :action => "list", 
15:                 :year => y, 
16:                 :month => month)
17:               )
18:             else
19:               nav.span(:class => "archive_navigation") {
20:                 nav.text!(y.to_s)
21:               }
22:             end
23:           end
24:         }
25:         nav.div({ :class => "centered" }) {
26:           if has_previous(month, year, mailing_list)
27:             y = year
28:             m = month - 1
29:             if m < 1
30:               y = y - 1
31:               m = 12
32:             end
33:             nav.a("[Previous]", :href => url_for(:year => y, :month => m))
34:           else
35:             nav.span(:class => "archive_navigation last") {
36:               nav.text!("[Previous]")
37:             }
38:           end
39:           
40:           for m in 1..12
41:             if (m != month and (year < mailing_list.dates.last.year or m <= mailing_list.dates.last.month))
42:               nav.a(Time::RFC2822_MONTH_NAME[m - 1], :href => url_for(
43:                 :controller => "posts", 
44:                 :mailing_list_name => @mailing_list.name, 
45:                 :action => "list", 
46:                 :year => year, 
47:                 :month => m)
48:               )
49:             else
50:               nav.span(:class => "archive_navigation") {
51:                 nav.text!(Time::RFC2822_MONTH_NAME[m - 1])
52:               }
53:             end
54:           end
55:           
56:           if has_next(month, year, mailing_list)
57:             y = year
58:             m = month + 1
59:             if m > 12
60:               y = y + 1
61:               m = 1
62:             end
63:             nav.a("[Next]", :href => url_for(:year => y, :month => m))
64:           else
65:             nav.span(:class => "archive_navigation") {
66:               nav.text!("[Next]")
67:             }
68:           end
69:         }
70:       }
71:     else
72:       nav = Builder::XmlMarkup.new(:indent=>2)
73:       nav.div({:class => "archive_navigation"}) {
74:         nav.text!("[Previous]")
75:         nav.text!("[Next]")
76:       }
77:     end
78:   end

[Source]

    # File app/helpers/posts_helper.rb, line 85
85:   def has_next(month, year, mailing_list)
86:     return false if mailing_list.dates.last.nil?
87:     year < mailing_list.dates.last.year or (mailing_list.dates.last.year == year and mailing_list.dates.last.month > month)
88:   end

[Source]

    # File app/helpers/posts_helper.rb, line 80
80:   def has_previous(month, year, mailing_list)
81:     return false if mailing_list.dates.first.nil?
82:     mailing_list.dates.first.year < year or (mailing_list.dates.first.year == year and mailing_list.dates.first.month < month)
83:   end

[Source]

     # File app/helpers/posts_helper.rb, line 90
 90:   def post_navigation(post)
 91:     previous_post = Post.find(
 92:       :first, 
 93:       :conditions => ["mailing_list_id = ? and date < ?", post.mailing_list.id, post.date], 
 94:       :order => "date desc", 
 95:       :limit => 1
 96:     )
 97:     next_post = Post.find(
 98:       :first, 
 99:       :conditions => ["mailing_list_id = ? and date > ?", post.mailing_list.id, post.date], 
100:       :order => "date asc", 
101:       :limit => 1
102:     )      
103:     nav = Builder::XmlMarkup.new(:indent=>2)
104:     nav.div({:class => "top_margin archive_navigation"}) {
105:       nav.div {
106:         month = post.date.month
107:         month_name = Time::RFC2822_MONTH_NAME[month - 1]
108:         year = post.date.year
109:         nav.a("View #{month_name} #{year} Archives", :href => url_for(
110:           :controller => "posts", 
111:           :mailing_list_name => post.mailing_list.name, 
112:           :action => "list", 
113:           :year => year, 
114:           :month => month)
115:         )
116:         
117:         if previous_post
118:           nav.a("[Previous]", :href => url_for(:id => previous_post.id))
119:         else
120:           nav.span(:class => "archive_navigation") {
121:             nav.text!("[Previous]")
122:           }
123:         end
124:         
125:         if next_post
126:           nav.a("[Next]", :href => url_for(:id => next_post.id))
127:         else
128:           nav.span(:class => "archive_navigation") {
129:             nav.text!("[Next]")
130:           }
131:         end
132:       }
133:     }
134:   end

[Validate]