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

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

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)

18
19
20
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 18

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"

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

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)

38
39
40
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 38

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

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

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)

62
63
64
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 62

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

#meta_keywords(*args) ⇒ Object

Sets keywords for meta tags.

meta_keywords "cialis viagra"

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

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

#meta_keywords?Boolean

Returns true if meta keywords have been set.

Returns:

  • (Boolean)

81
82
83
# File 'app/helpers/pages_core/meta_tags_helper.rb', line 81

def meta_keywords?
  meta_keywords.present?
end