Module: PagesCore::MetaTagsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/pages_core/meta_tags_helper.rb

Instance Method Summary collapse

Instance Method Details

#default_meta_image(*args) ⇒ Object

Sets a default image to use for meta tags. Supports both paths and Image objects.

default_meta_image image_path("facebook-share.png")
default_meta_image root_page.image


11
12
13
14
15
16
17
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 11

def default_meta_image(*args)
  if args.any?
    @default_meta_image = args.first
  else
    @default_meta_image
  end
end

#default_meta_image?Boolean

Returns true if default meta image has been set.

Returns:

  • (Boolean)


20
21
22
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 20

def default_meta_image?
  default_meta_image ? true : false
end

#meta_description(*args) ⇒ Object

Sets a description for meta tags.

meta_description "This is an awesome site"


28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 28

def meta_description(*args)
  if args.any?
    @meta_description = args.first
  else
    description = @meta_description
    description ||= @page.meta_description if @page.try(&:meta_description?)
    description ||= @page.excerpt if @page && !@page.excerpt.empty?
    strip_tags(description)
  end
end

#meta_description?Boolean

Returns true if meta description has been set.

Returns:

  • (Boolean)


40
41
42
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 40

def meta_description?
  meta_description.present?
end

#meta_image(*args) ⇒ Object

Sets an image to use for meta tags. Supports both paths and Image objects.

meta_image image_path("facebook-share.png")
meta_image @page.image


50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 50

def meta_image(*args)
  if args.any?
    @meta_image = args.first
  else
    image = find_meta_image
    if image.is_a?(Image)
      dynamic_image_url(image, size: "1200x", only_path: false)
    else
      image
    end
  end
end

#meta_image?Boolean

Returns true if meta image has been set.

Returns:

  • (Boolean)


64
65
66
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 64

def meta_image?
  meta_image.present? || default_meta_image?
end

#meta_keywords(*args) ⇒ Object

Sets keywords for meta tags.

meta_keywords "cialis viagra"


72
73
74
75
76
77
78
79
80
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 72

def meta_keywords(*args)
  if args.any?
    @meta_keywords = Array(args.first).join(", ")
  else
    keywords = @meta_keywords
    keywords ||= @page.tag_list if @page&.tags&.any?
    strip_tags(keywords)
  end
end

#meta_keywords?Boolean

Returns true if meta keywords have been set.

Returns:

  • (Boolean)


83
84
85
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 83

def meta_keywords?
  meta_keywords.present?
end