Module: Integral::BlogHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/integral/blog_helper.rb

Overview

Blog Helper which contains methods used through the blog

Instance Method Summary collapse

Instance Method Details

#display_most_read_posts_widget?Boolean

Whether or not to display most read widget

Returns:

  • (Boolean)


63
64
65
# File 'app/helpers/integral/blog_helper.rb', line 63

def display_most_read_posts_widget?
  Integral::Post.published.count > 10
end

#display_newsletter_signup_widget?Boolean

Whether or not to display newsletter signup widget

Returns:

  • (Boolean)


39
40
41
# File 'app/helpers/integral/blog_helper.rb', line 39

def 
  true
end

Whether or not to display recent posts sidebar widget

Returns:

  • (Boolean)


58
59
60
# File 'app/helpers/integral/blog_helper.rb', line 58

def display_popular_posts_widget?
  Integral::Post.published.count > 4
end

#display_recent_posts_widget?Boolean

Whether or not to display recent posts sidebar widget

Returns:

  • (Boolean)


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

def display_recent_posts_widget?
  return false if "#{controller_name}.#{action_name}" == 'posts.index'

  true
end

#display_share_widget?Boolean

Whether or not to display share widget

Returns:

  • (Boolean)


44
45
46
47
48
# File 'app/helpers/integral/blog_helper.rb', line 44

def display_share_widget?
  return true if "#{controller_name}.#{action_name}" == 'posts.show'

  false
end

Returns featured categories - currently all which have posts associated to them.

Returns:

  • (Relation)

    featured categories - currently all which have posts associated to them



5
6
7
# File 'app/helpers/integral/blog_helper.rb', line 5

def featured_categories
  @featured_categories ||= Integral::Category.where(id: Integral::Post.published.select(:category_id).uniq.map(&:category_id))
end

#most_read_postsObject

TODO: Change this to use GA API through a GoogleAnalyticsService



68
69
70
# File 'app/helpers/integral/blog_helper.rb', line 68

def most_read_posts
  @popular_posts.decorate
end

#render_post_as_json_ld(post) ⇒ String

Returns Javascript snippet containing JSON-LD of the provided post.

Parameters:

Returns:

  • (String)

    Javascript snippet containing JSON-LD of the provided post



12
13
14
15
16
# File 'app/helpers/integral/blog_helper.rb', line 12

def render_post_as_json_ld(post)
  render_json_ld do
    post.to_json_ld.merge("@context": 'http://schema.org')
  end
end

#render_posts_as_json_ld(posts, title: t('.title'), url: request.original_url, description: t('.description')) ⇒ String

Returns Javascript snippet containing JSON-LD of the provided posts.

Parameters:

  • posts (Integral::Post)

    collection of posts to convert to JSON-LD

Returns:

  • (String)

    Javascript snippet containing JSON-LD of the provided posts



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/integral/blog_helper.rb', line 21

def render_posts_as_json_ld(posts, title: t('.title'), url: request.original_url, description: t('.description'))
  render_json_ld do
    {
      "@context": 'http://schema.org',
      "@type": 'Blog',
      "name": title,
      "url": url,
      "description": description,
      "publisher": {
        "@type": 'Organization',
        "name": Integral::Settings.website_title
      },
      "blogPosts": posts.map(&:to_json_ld)
    }
  end
end