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)


73
74
75
# File 'app/helpers/integral/blog_helper.rb', line 73

def display_most_read_posts_widget?
  Integral::Post.published.where(locale: I18n.locale).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.where(locale: I18n.locale).count > 4
end

#display_post_categories_widget?Boolean

Whether or not to display post categories

Returns:

  • (Boolean)


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

def display_post_categories_widget?
  true
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

#display_similar_posts_widget?Boolean

Whether or not to display similar posts

Returns:

  • (Boolean)


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

def display_similar_posts_widget?
  true
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(locale: I18n.locale).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



78
79
80
# File 'app/helpers/integral/blog_helper.rb', line 78

def most_read_posts
  popular_blog_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