Module: BlogHelper

Included in:
ApplicationController, Blog::PostsController
Defined in:
app/helpers/blog_helper.rb

Overview

@Name: Blog helper @Use: defining helper methods to be used in controllers, models, views of blog posts @Created date: 08-06-2012 @Modified Date: 27-06-2012

@Company : Mindfire Solutions

Instance Method Summary collapse

Instance Method Details

#blog_archive_listObject

blog_archive_list



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/blog_helper.rb', line 11

def blog_archive_list
  posts = BlogPost.select('published_at').all_previous
  return nil if posts.blank?
  html = '<section id="blog_archive_list" class="module-archives module"><h2>'
  html << t('blog.shared.archives')
  html << '</h2><nav><ul>'
  links = []
  super_old_links = []

  posts.each do |e|
    if e.published_at >= Time.now.end_of_year.advance(:years => -3)
      links << e.published_at.strftime('%m/%Y')
    else
      super_old_links << e.published_at.strftime('01/%Y')
    end
  end
  links.uniq!
  super_old_links.uniq!
  links.each do |l|
    year = l.split('/')[1]
    month = l.split('/')[0]
    count = BlogPost.by_archive(Time.parse(l)).size
    text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
    html << "<li>"
    html << link_to(text, archive_blog_posts_path(:year => year, :month => month))
    html << "</li>"
  end
  super_old_links.each do |l|
    year = l.split('/')[1]
    count = BlogPost.by_year(Time.parse(l)).size
    text = "#{year} (#{count})"
    html << "<li>"
    html << link_to(text, archive_blog_posts_path(:year => year))
    html << "</li>"
  end
  html << '</ul></nav></section>'
  html.html_safe
end

#blog_post_teaser(post) ⇒ Object

blog post



56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/blog_helper.rb', line 56

def (post)
  if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
   post.custom_teaser.html_safe
  else
   truncate(post.body, {
     :length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
     :preserve_html_tags => true
    }).html_safe
  end
end

#next_or_previous?(post) ⇒ Boolean

next or previous posts

Returns:

  • (Boolean)


51
52
53
# File 'app/helpers/blog_helper.rb', line 51

def next_or_previous?(post)
  post.next.present? or post.prev.present?
end