Module: Shinmun::Helpers

Included in:
Blog
Defined in:
lib/shinmun/helpers.rb

Instance Method Summary collapse

Instance Method Details

Render a link to an archive page.



21
22
23
# File 'lib/shinmun/helpers.rb', line 21

def archive_link(year, month)
  link_to "#{Date::MONTHNAMES[month]} #{year}", archive_path(year, month)
end

#archive_path(year, month) ⇒ Object



11
12
13
# File 'lib/shinmun/helpers.rb', line 11

def archive_path(year, month)
  "/#{year}/#{month}"
end

#diff_line_class(line) ⇒ Object



51
52
53
54
55
56
# File 'lib/shinmun/helpers.rb', line 51

def diff_line_class(line)
  case line[0, 1]
  when '+' then 'added'
  when '-' then 'deleted'
  end
end

#html_escape(s) ⇒ Object



47
48
49
# File 'lib/shinmun/helpers.rb', line 47

def html_escape(s)
  s.to_s.gsub(/>/, '&gt;').gsub(/</n, '&lt;')
end

#human_date(time) ⇒ Object

Render a date or time in a nice human readable format.



26
27
28
# File 'lib/shinmun/helpers.rb', line 26

def human_date(time)
  "%s %d, %d" % [Date::MONTHNAMES[time.month], time.day, time.year]
end

Render a link for the navigation bar.



36
37
38
39
40
41
42
43
44
45
# File 'lib/shinmun/helpers.rb', line 36

def navi_link(text, path)
  if path.match(/categories\/(.*)/)        
    active = $1 == urlify(@category) if @category
    active = $1 == urlify(@post.category) if @post
  else
    active = request.path_info == path
  end
  
  link_to text, path, :class => active ? 'active' : nil
end

#post_link(post) ⇒ Object

Render a link to a post



16
17
18
# File 'lib/shinmun/helpers.rb', line 16

def post_link(post)
  link_to post.title, post_path(post)
end

#post_path(post) ⇒ Object



7
8
9
# File 'lib/shinmun/helpers.rb', line 7

def post_path(post)
  "/#{post.year}/#{post.month}/#{post.name}"
end

#rfc822(time) ⇒ Object

Render a date or time in rfc822 format.



31
32
33
# File 'lib/shinmun/helpers.rb', line 31

def rfc822(time)
  time.strftime("%a, %d %b %Y %H:%M:%S %z")
end