Module: Shinmun::Helpers
- Included in:
- Blog
- Defined in:
- lib/shinmun/helpers.rb
Instance Method Summary collapse
-
#archive_link(year, month) ⇒ Object
Render a link to an archive page.
- #archive_path(year, month) ⇒ Object
- #diff_line_class(line) ⇒ Object
- #html_escape(s) ⇒ Object
-
#human_date(time) ⇒ Object
Render a date or time in a nice human readable format.
-
#navi_link(text, path) ⇒ Object
Render a link for the navigation bar.
-
#post_link(post) ⇒ Object
Render a link to a post.
- #post_path(post) ⇒ Object
-
#rfc822(time) ⇒ Object
Render a date or time in rfc822 format.
Instance Method Details
#archive_link(year, month) ⇒ Object
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
54 55 56 57 58 59 |
# File 'lib/shinmun/helpers.rb', line 54 def diff_line_class(line) case line[0, 1] when '+' then 'added' when '-' then 'deleted' end end |
#html_escape(s) ⇒ Object
50 51 52 |
# File 'lib/shinmun/helpers.rb', line 50 def html_escape(s) s.to_s.gsub(/>/, '>').gsub(/</n, '<') 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 |
#navi_link(text, path) ⇒ Object
Render a link for the navigation bar.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shinmun/helpers.rb', line 36 def navi_link(text, path) active = request.path_info == path if path.match(/categories\/(.*)/) category = $1 if request.path.match(/(\d+)\/(\d+)\/(.*)/) post = posts_by_date[$1.to_i][$2.to_i][$3] active ||= category == urlify(post.category) if post end 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 |