meta-tags 2.14.0 → 2.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/certs/kpumuk.pem CHANGED
@@ -1,20 +1,21 @@
1
1
  -----BEGIN CERTIFICATE-----
2
- MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhrcHVt
3
- dWsvREM9a3B1bXVrL0RDPWluZm8wHhcNMjAxMjEwMjA1MTE5WhcNMjExMjEwMjA1
4
- MTE5WjAjMSEwHwYDVQQDDBhrcHVtdWsvREM9a3B1bXVrL0RDPWluZm8wggEiMA0G
5
- CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8NmK6GXPiE/q7PDbj7nNdw3pa8a6Q
6
- IDxLtc7kW95e1mh0TVgOE8kvGegGtRtjvhXVGTTFtZ+yMD/0DCfTM2oUQYk5oYpO
7
- ZGrCfbNIdZauf4WYsnJtKOTrRoqFMwpL5PlBDKczB2y5lUmQs2HIsjQ0Q21wdKyy
8
- 7tXiZPoCoJ+kH+b4/d4dcNvAXVnWgO2HoLW5oqWfqY5swkAHzwHLU+rlxxuHUqOy
9
- 8/Y4hUSOXVIsxWxl3EapENm+QAfBRZn3L26hEb80CgSAp8m47Cj9DaSd7xoDtrIe
10
- RryRTj5NVZbq9p1/WRc5zxD9QhAEPjRa5ikbd+eWebIDpAKI0hpyC/9bAgMBAAGj
11
- dzB1MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBT2uFRXNWDpVdbv
12
- +xBk8DAgJPGBPTAdBgNVHREEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wHQYDVR0S
13
- BBYwFIESa3B1bXVrQGtwdW11ay5pbmZvMA0GCSqGSIb3DQEBCwUAA4IBAQBdcrpl
14
- 32OlNaf68v38yzqYkviLELtbzRvEpRuQWZZyxOwU1OWSFAWkkALuseLWHDLYRDE8
15
- lOzQHewKodqaSPEo63vMZ28UQ3kDP1YE+cXR12fOg4YbCH8VETrTJa3X0AOOAbgA
16
- ZLMcZD6wu9Zu2rPhxLxs6Q/PaGGEc8bonOirCZrwVDzHFA1cPjcSoApdsyGdRiyj
17
- 1f+XHXjCE5A1A6b8o4ffpAI6gkuaQOIrgGCyLS9oos6DSuofkvXI9g62G+2ZOmKJ
18
- U97JEQmXCpruLEeSVT2UqR+iJAWEAxPzqzDbTzZBTSPKn+nXeuF6h81e4hsJtkeJ
19
- HkYAoatF9iZrxT4E
2
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MQ8wDQYDVQQDDAZrcHVt
3
+ dWsxFjAUBgoJkiaJk/IsZAEZFgZrcHVtdWsxFDASBgoJkiaJk/IsZAEZFgRpbmZv
4
+ MB4XDTI0MDcxNTIxMzIyNFoXDTI1MDcxNTIxMzIyNFowPzEPMA0GA1UEAwwGa3B1
5
+ bXVrMRYwFAYKCZImiZPyLGQBGRYGa3B1bXVrMRQwEgYKCZImiZPyLGQBGRYEaW5m
6
+ bzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALw2YroZc+IT+rs8NuPu
7
+ c13DelrxrpAgPEu1zuRb3l7WaHRNWA4TyS8Z6Aa1G2O+FdUZNMW1n7IwP/QMJ9Mz
8
+ ahRBiTmhik5kasJ9s0h1lq5/hZiycm0o5OtGioUzCkvk+UEMpzMHbLmVSZCzYciy
9
+ NDRDbXB0rLLu1eJk+gKgn6Qf5vj93h1w28BdWdaA7YegtbmipZ+pjmzCQAfPActT
10
+ 6uXHG4dSo7Lz9jiFRI5dUizFbGXcRqkQ2b5AB8FFmfcvbqERvzQKBICnybjsKP0N
11
+ pJ3vGgO2sh5GvJFOPk1Vlur2nX9ZFznPEP1CEAQ+NFrmKRt355Z5sgOkAojSGnIL
12
+ /1sCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFPa4
13
+ VFc1YOlV1u/7EGTwMCAk8YE9MB0GA1UdEQQWMBSBEmtwdW11a0BrcHVtdWsuaW5m
14
+ bzAdBgNVHRIEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wDQYJKoZIhvcNAQELBQAD
15
+ ggEBADXj54X1y7Pw0Wp5wdniZE13a8EwWC41BEIsSoBLkGQhZ2OOR+5tVUM9kCwG
16
+ kX6YdliORLuLevYXKiXFluiETwKTeAd6zUURy7eLlwQ1GvhE8wmGk0TQY11v8FMj
17
+ 7AupDtulpP01gLDZwbysovu/3btfhrLVncJ2zIpB5sx68fDCOmOGSUbdgOCV+S+O
18
+ CyTFctYlJNXZgv2kl76TII7jbZikT/7hVOhCO48OdMQ/s26zabbJrcV2pJOLKKkP
19
+ BKX4xDo6SbsGmqjFkknT6WiiE94rQxGCb9JNiSyl3SncEw+Ysx6yVKYB5WAEy8s1
20
+ M0VQvDzd77bxj3lx/P6ifll3yUs=
20
21
  -----END CERTIFICATE-----
@@ -4,7 +4,7 @@ module MetaTags
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  desc "Copy MetaTags default files"
7
- source_root File.expand_path('templates', __dir__)
7
+ source_root File.expand_path("templates", __dir__)
8
8
 
9
9
  def copy_config
10
10
  template "config/initializers/meta_tags.rb"
@@ -9,6 +9,15 @@ MetaTags.configure do |config|
9
9
  # When true, site title will be truncated instead of title. Default is false.
10
10
  # config.truncate_site_title_first = false
11
11
 
12
+ # Add HTML attributes to the <title> HTML tag. Default is {}.
13
+ # config.title_tag_attributes = {}
14
+
15
+ # Natural separator when truncating. Default is " " (space character).
16
+ # Set to nil to disable natural separator.
17
+ # This also allows you to use a whitespace regular expression (/\s/) or
18
+ # a Unicode space (/\p{Space}/).
19
+ # config.truncate_on_natural_separator = " "
20
+
12
21
  # Maximum length of the page description. Default is 300.
13
22
  # Set to nil or 0 to remove limits.
14
23
  # config.description_limit = 300
data/lib/meta-tags.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'meta_tags'
3
+ require "meta_tags"
@@ -6,9 +6,15 @@ module MetaTags
6
6
  # How many characters to truncate title to.
7
7
  attr_accessor :title_limit
8
8
 
9
+ # HTML attributes for the title tag.
10
+ attr_accessor :title_tag_attributes
11
+
9
12
  # Truncate site_title instead of title.
10
13
  attr_accessor :truncate_site_title_first
11
14
 
15
+ # A string or regexp separator to truncate text at a natural break.
16
+ attr_accessor :truncate_on_natural_separator
17
+
12
18
  # How many characters to truncate description to.
13
19
  attr_accessor :description_limit
14
20
 
@@ -33,6 +39,12 @@ module MetaTags
33
39
  # - an array of strings or symbols representing their names or name-prefixes.
34
40
  attr_reader :property_tags
35
41
 
42
+ # Configure whenever Meta-Tags should skip canonicals on pages with noindex: true
43
+ # "shouldn't mix noindex & rel=canonical comes from: they're very contradictory pieces of information for us."
44
+ # - John Mueller (Webmaster Trends Analyst at Google)
45
+ # https://www.reddit.com/r/TechSEO/comments/8yahdr/2_questions_about_the_canonical_tag/e2dey9i/
46
+ attr_accessor :skip_canonical_links_on_noindex
47
+
36
48
  # Initializes a new instance of Configuration class.
37
49
  def initialize
38
50
  reset_defaults!
@@ -41,25 +53,25 @@ module MetaTags
41
53
  def default_property_tags
42
54
  [
43
55
  # App Link metadata https://developers.facebook.com/docs/applinks/metadata-reference
44
- 'al',
56
+ "al",
45
57
  # Open Graph Markup https://developers.facebook.com/docs/sharing/webmasters#markup
46
- 'fb',
47
- 'og',
58
+ "fb",
59
+ "og",
48
60
  # Facebook OpenGraph Object Types https://developers.facebook.com/docs/reference/opengraph
49
61
  # Note that these tags are used in a regex, so including e.g. 'restaurant' will affect
50
62
  # 'restaurant:category', 'restaurant:price_rating', and anything else under that namespace.
51
- 'article',
52
- 'book',
53
- 'books',
54
- 'business',
55
- 'fitness',
56
- 'game',
57
- 'music',
58
- 'place',
59
- 'product',
60
- 'profile',
61
- 'restaurant',
62
- 'video',
63
+ "article",
64
+ "book",
65
+ "books",
66
+ "business",
67
+ "fitness",
68
+ "game",
69
+ "music",
70
+ "place",
71
+ "product",
72
+ "profile",
73
+ "restaurant",
74
+ "video"
63
75
  ].freeze
64
76
  end
65
77
 
@@ -70,13 +82,16 @@ module MetaTags
70
82
  def reset_defaults!
71
83
  @title_limit = 70
72
84
  @truncate_site_title_first = false
85
+ @truncate_on_natural_separator = " "
86
+ @title_tag_attributes = {}
73
87
  @description_limit = 300
74
88
  @keywords_limit = 255
75
- @keywords_separator = ', '
89
+ @keywords_separator = ", "
76
90
  @keywords_lowercase = true
77
91
  @property_tags = default_property_tags.dup
78
92
  @open_meta_tags = true
79
93
  @minify_output = false
94
+ @skip_canonical_links_on_noindex = false
80
95
  end
81
96
  end
82
97
  end
@@ -15,9 +15,9 @@ module MetaTags
15
15
  # Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
16
16
  # <tt>@page_description</tt> instance variables and calls +render+.
17
17
  def render(*args, &block)
18
- meta_tags[:title] = @page_title if @page_title
19
- meta_tags[:keywords] = @page_keywords if @page_keywords
20
- meta_tags[:description] = @page_description if @page_description
18
+ meta_tags[:title] = @page_title if defined?(@page_title) && @page_title
19
+ meta_tags[:keywords] = @page_keywords if defined?(@page_keywords) && @page_keywords
20
+ meta_tags[:description] = @page_description if defined?(@page_description) && @page_description
21
21
 
22
22
  super
23
23
  end
@@ -25,7 +25,7 @@ module MetaTags
25
25
  # Set meta tags for the page.
26
26
  #
27
27
  # See <tt>MetaTags::ViewHelper#set_meta_tags</tt> for details.
28
- def set_meta_tags(meta_tags) # rubocop:disable Naming/AccessorMethodName
28
+ def set_meta_tags(meta_tags)
29
29
  self.meta_tags.update(meta_tags)
30
30
  end
31
31
  protected :set_meta_tags
@@ -9,7 +9,7 @@ module MetaTags
9
9
  # Initializes a new instance of MetaTagsCollection.
10
10
  #
11
11
  def initialize
12
- @meta_tags = HashWithIndifferentAccess.new
12
+ @meta_tags = ActiveSupport::HashWithIndifferentAccess.new
13
13
  end
14
14
 
15
15
  # Returns meta tag value by name.
@@ -38,7 +38,13 @@ module MetaTags
38
38
  # @return [Hash] result of the merge.
39
39
  #
40
40
  def update(object = {})
41
- meta_tags = object.respond_to?(:to_meta_tags) ? object.to_meta_tags : object
41
+ meta_tags = if object.respond_to?(:to_meta_tags)
42
+ # @type var object: _MetaTagish & Object
43
+ object.to_meta_tags
44
+ else
45
+ # @type var object: Hash[String | Symbol, untyped]
46
+ object
47
+ end
42
48
  @meta_tags.deep_merge! normalize_open_graph(meta_tags)
43
49
  end
44
50
 
@@ -64,14 +70,16 @@ module MetaTags
64
70
  with_defaults(defaults) { extract_full_title }
65
71
  end
66
72
 
67
- # Constructs the title without site title (for normalized parameters).
73
+ # Constructs the title without site title (for normalized parameters). When title is empty,
74
+ # use the site title instead.
68
75
  #
69
76
  # @return [String] page title.
70
77
  #
71
78
  def page_title(defaults = {})
72
79
  old_site = @meta_tags[:site]
73
80
  @meta_tags[:site] = nil
74
- with_defaults(defaults) { extract_full_title }
81
+ full_title = with_defaults(defaults) { extract_full_title }
82
+ full_title.presence || old_site || ""
75
83
  ensure
76
84
  @meta_tags[:site] = old_site
77
85
  end
@@ -98,10 +106,10 @@ module MetaTags
98
106
  # @return [String] page title.
99
107
  #
100
108
  def extract_full_title
101
- site_title = extract(:site) || ''
102
- title = extract_title || []
103
- separator = extract_separator
104
- reverse = extract(:reverse) == true
109
+ site_title = extract(:site) || ""
110
+ title = extract_title
111
+ separator = extract_separator
112
+ reverse = extract(:reverse) == true
105
113
 
106
114
  TextNormalizer.normalize_title(site_title, title, separator, reverse)
107
115
  end
@@ -112,8 +120,9 @@ module MetaTags
112
120
  #
113
121
  def extract_title
114
122
  title = extract(:title).presence
115
- return unless title
123
+ return [] unless title
116
124
 
125
+ # @type var title: Array[String]
117
126
  title = Array(title)
118
127
  return title.map(&:downcase) if extract(:lowercase) == true
119
128
 
@@ -127,15 +136,15 @@ module MetaTags
127
136
  def extract_separator
128
137
  if meta_tags[:separator] == false
129
138
  # Special case: if separator is hidden, do not display suffix/prefix
130
- prefix = separator = suffix = ''
139
+ prefix = separator = suffix = ""
131
140
  else
132
- prefix = extract_separator_section(:prefix, ' ')
133
- separator = extract_separator_section(:separator, '|')
134
- suffix = extract_separator_section(:suffix, ' ')
141
+ prefix = extract_separator_section(:prefix, " ")
142
+ separator = extract_separator_section(:separator, "|")
143
+ suffix = extract_separator_section(:suffix, " ")
135
144
  end
136
145
  delete(:separator, :prefix, :suffix)
137
146
 
138
- TextNormalizer.safe_join([prefix, separator, suffix], '')
147
+ TextNormalizer.safe_join([prefix, separator, suffix], "")
139
148
  end
140
149
 
141
150
  # Extracts noindex settings as a Hash mapping noindex tag name to value.
@@ -150,12 +159,12 @@ module MetaTags
150
159
  [:noindex, :index],
151
160
  # follow has higher priority than nofollow
152
161
  [:follow, :nofollow],
153
- :noarchive,
162
+ :noarchive
154
163
  ].each do |attributes|
155
164
  calculate_robots_attributes(result, attributes)
156
165
  end
157
166
 
158
- result.transform_values { |v| v.join(', ') }
167
+ result.transform_values { |v| v.join(", ") }
159
168
  end
160
169
 
161
170
  protected
@@ -163,10 +172,10 @@ module MetaTags
163
172
  # Converts input hash to HashWithIndifferentAccess and renames :open_graph to :og.
164
173
  #
165
174
  # @param [Hash] meta_tags list of meta tags.
166
- # @return [HashWithIndifferentAccess] normalized meta tags list.
175
+ # @return [ActiveSupport::HashWithIndifferentAccess] normalized meta tags list.
167
176
  #
168
177
  def normalize_open_graph(meta_tags)
169
- meta_tags = meta_tags.kind_of?(HashWithIndifferentAccess) ? meta_tags.dup : meta_tags.with_indifferent_access
178
+ meta_tags = meta_tags.with_indifferent_access
170
179
  meta_tags[:og] = meta_tags.delete(:open_graph) if meta_tags.key?(:open_graph)
171
180
  meta_tags
172
181
  end
@@ -179,7 +188,7 @@ module MetaTags
179
188
  # @return [String] separator segment value.
180
189
  #
181
190
  def extract_separator_section(name, default)
182
- meta_tags[name] == false ? '' : (meta_tags[name] || default)
191
+ (meta_tags[name] == false) ? "" : (meta_tags[name] || default)
183
192
  end
184
193
 
185
194
  # Extracts robots attribute (noindex, nofollow, etc) name and value.
@@ -188,11 +197,11 @@ module MetaTags
188
197
  # @return [Array<String>] pair of noindex attribute name and value.
189
198
  #
190
199
  def extract_robots_attribute(name)
191
- noindex = extract(name)
192
- noindex_name = noindex.kind_of?(String) || noindex.kind_of?(Array) ? noindex : 'robots'
200
+ noindex = extract(name)
201
+ noindex_name = (noindex.is_a?(String) || noindex.is_a?(Array)) ? noindex : "robots"
193
202
  noindex_value = noindex ? name.to_s : nil
194
203
 
195
- [ noindex_name, noindex_value ]
204
+ [noindex_name, noindex_value]
196
205
  end
197
206
 
198
207
  def calculate_robots_attributes(result, attributes)
@@ -2,15 +2,15 @@
2
2
 
3
3
  module MetaTags
4
4
  class Railtie < Rails::Railtie
5
- initializer 'meta_tags.setup_action_controller' do
5
+ initializer "meta_tags.setup_action_controller" do
6
6
  ActiveSupport.on_load :action_controller do
7
- ActionController::Base.include MetaTags::ControllerHelper
7
+ include MetaTags::ControllerHelper
8
8
  end
9
9
  end
10
10
 
11
- initializer 'meta_tags.setup_action_view' do
11
+ initializer "meta_tags.setup_action_view" do
12
12
  ActiveSupport.on_load :action_view do
13
- ActionView::Base.include MetaTags::ViewHelper
13
+ include MetaTags::ViewHelper
14
14
  end
15
15
  end
16
16
  end
@@ -26,6 +26,7 @@ module MetaTags
26
26
  render_with_normalization(tags, :description)
27
27
  render_with_normalization(tags, :keywords)
28
28
  render_refresh(tags)
29
+ render_canonical_link(tags)
29
30
  render_noindex(tags)
30
31
  render_alternate(tags)
31
32
  render_open_search(tags)
@@ -58,7 +59,11 @@ module MetaTags
58
59
  normalized_meta_tags[:site] = meta_tags[:site]
59
60
  title = meta_tags.extract_full_title
60
61
  normalized_meta_tags[:full_title] = title
61
- tags << ContentTag.new(:title, content: title) if title.present?
62
+ default_attributes = MetaTags.config.title_tag_attributes || {}
63
+
64
+ if title.present?
65
+ tags << ContentTag.new(:title, {content: title}.with_defaults(default_attributes))
66
+ end
62
67
  end
63
68
 
64
69
  # Renders icon(s) tag.
@@ -70,12 +75,12 @@ module MetaTags
70
75
  return unless icon
71
76
 
72
77
  # String? Value is an href
73
- icon = [{ href: icon }] if icon.kind_of?(String)
78
+ icon = [{href: icon}] if icon.is_a?(String)
74
79
  # Hash? Single icon instead of a list of icons
75
- icon = [icon] if icon.kind_of?(Hash)
80
+ icon = [icon] if icon.is_a?(Hash)
76
81
 
77
82
  icon.each do |icon_params|
78
- icon_params = { rel: 'icon', type: 'image/x-icon' }.with_indifferent_access.merge(icon_params)
83
+ icon_params = {rel: "icon", type: "image/x-icon"}.with_indifferent_access.merge(icon_params)
79
84
  tags << Tag.new(:link, icon_params)
80
85
  end
81
86
  end
@@ -87,7 +92,7 @@ module MetaTags
87
92
  # @see TextNormalizer
88
93
  #
89
94
  def render_with_normalization(tags, name)
90
- value = TextNormalizer.public_send("normalize_#{name}", meta_tags.extract(name))
95
+ value = TextNormalizer.public_send(:"normalize_#{name}", meta_tags.extract(name))
91
96
  normalized_meta_tags[name] = value
92
97
  tags << Tag.new(:meta, name: name, content: value) if value.present?
93
98
  end
@@ -108,7 +113,7 @@ module MetaTags
108
113
  #
109
114
  def render_refresh(tags)
110
115
  refresh = meta_tags.extract(:refresh)
111
- tags << Tag.new(:meta, 'http-equiv' => 'refresh', content: refresh.to_s) if refresh.present?
116
+ tags << Tag.new(:meta, "http-equiv" => "refresh", :content => refresh.to_s) if refresh.present?
112
117
  end
113
118
 
114
119
  # Renders alternate link tags.
@@ -119,13 +124,13 @@ module MetaTags
119
124
  alternate = meta_tags.extract(:alternate)
120
125
  return unless alternate
121
126
 
122
- if alternate.kind_of?(Hash)
127
+ if alternate.is_a?(Hash)
123
128
  alternate.each do |hreflang, href|
124
- tags << Tag.new(:link, rel: 'alternate', href: href, hreflang: hreflang) if href.present?
129
+ tags << Tag.new(:link, rel: "alternate", href: href, hreflang: hreflang) if href.present?
125
130
  end
126
- elsif alternate.kind_of?(Array)
131
+ elsif alternate.is_a?(Array)
127
132
  alternate.each do |link_params|
128
- tags << Tag.new(:link, { rel: 'alternate' }.with_indifferent_access.merge(link_params))
133
+ tags << Tag.new(:link, {rel: "alternate"}.with_indifferent_access.merge(link_params))
129
134
  end
130
135
  end
131
136
  end
@@ -142,7 +147,7 @@ module MetaTags
142
147
  title = open_search[:title]
143
148
 
144
149
  type = "application/opensearchdescription+xml"
145
- tags << Tag.new(:link, rel: 'search', type: type, href: href, title: title) if href.present?
150
+ tags << Tag.new(:link, rel: "search", type: type, href: href, title: title) if href.present?
146
151
  end
147
152
 
148
153
  # Renders links.
@@ -150,7 +155,7 @@ module MetaTags
150
155
  # @param [Array<Tag>] tags a buffer object to store tag in.
151
156
  #
152
157
  def render_links(tags)
153
- [ :amphtml, :canonical, :prev, :next, :image_src, :manifest ].each do |tag_name|
158
+ [:amphtml, :prev, :next, :image_src, :manifest].each do |tag_name|
154
159
  href = meta_tags.extract(tag_name)
155
160
  if href.present?
156
161
  @normalized_meta_tags[tag_name] = href
@@ -159,6 +164,19 @@ module MetaTags
159
164
  end
160
165
  end
161
166
 
167
+ # Renders canonical link
168
+ #
169
+ # @param [Array<Tag>] tags a buffer object to store tag in.
170
+ #
171
+ def render_canonical_link(tags)
172
+ href = meta_tags.extract(:canonical) # extract, so its not used anywhere else
173
+ return if MetaTags.config.skip_canonical_links_on_noindex && meta_tags[:noindex]
174
+ return if href.blank?
175
+
176
+ @normalized_meta_tags[:canonical] = href
177
+ tags << Tag.new(:link, rel: :canonical, href: href)
178
+ end
179
+
162
180
  # Renders complex hash objects.
163
181
  #
164
182
  # @param [Array<Tag>] tags a buffer object to store tag in.
@@ -175,7 +193,7 @@ module MetaTags
175
193
  #
176
194
  def render_hash(tags, key, **opts)
177
195
  data = meta_tags.meta_tags[key]
178
- return unless data.kind_of?(Hash)
196
+ return unless data.is_a?(Hash)
179
197
 
180
198
  process_hash(tags, key, data, **opts)
181
199
  meta_tags.extract(key)
@@ -188,7 +206,7 @@ module MetaTags
188
206
  def render_custom(tags)
189
207
  meta_tags.meta_tags.each do |name, data|
190
208
  Array(data).each do |val|
191
- tags << Tag.new(:meta, configured_name_key(name) => name, content: val)
209
+ tags << Tag.new(:meta, configured_name_key(name) => name, :content => val)
192
210
  end
193
211
  meta_tags.extract(name)
194
212
  end
@@ -201,16 +219,17 @@ module MetaTags
201
219
  # @param [Hash, Array, String, Symbol] content text content or a symbol reference to
202
220
  # top-level meta tag.
203
221
  #
204
- def process_tree(tags, property, content, **opts)
222
+ def process_tree(tags, property, content, itemprop: nil, **opts)
205
223
  method = case content
206
- when Hash
207
- :process_hash
208
- when Array
209
- :process_array
210
- else
211
- :render_tag
212
- end
213
- __send__(method, tags, property, content, **opts)
224
+ when Hash
225
+ :process_hash
226
+ when Array
227
+ :process_array
228
+ else
229
+ iprop = itemprop
230
+ :render_tag
231
+ end
232
+ __send__(method, tags, property, content, itemprop: iprop, **opts)
214
233
  end
215
234
 
216
235
  # Recursive method to process a hash with meta tags
@@ -220,10 +239,21 @@ module MetaTags
220
239
  # @param [Hash] content nested meta tag attributes.
221
240
  #
222
241
  def process_hash(tags, property, content, **opts)
242
+ itemprop = content.delete(:itemprop)
223
243
  content.each do |key, value|
224
- key = key.to_s == '_' ? property : "#{property}:#{key}"
225
- value = normalized_meta_tags[value] if value.kind_of?(Symbol)
226
- process_tree(tags, key, value, **opts)
244
+ if key.to_s == "_"
245
+ iprop = itemprop
246
+ key = property
247
+ else
248
+ key = "#{property}:#{key}"
249
+ end
250
+
251
+ normalized_value = if value.is_a?(Symbol)
252
+ normalized_meta_tags[value]
253
+ else
254
+ value
255
+ end
256
+ process_tree(tags, key, normalized_value, **opts.merge(itemprop: iprop))
227
257
  end
228
258
  end
229
259
 
@@ -243,17 +273,18 @@ module MetaTags
243
273
  # @param [String, Symbol] name a Hash or a String to render as meta tag.
244
274
  # @param [String, Symbol] value text content or a symbol reference to
245
275
  # top-level meta tag.
276
+ # @param [String, Symbol] itemprop value of the itemprop attribute.
246
277
  #
247
- def render_tag(tags, name, value, name_key: nil, value_key: :content)
278
+ def render_tag(tags, name, value, itemprop: nil)
248
279
  name_key ||= configured_name_key(name)
249
- tags << Tag.new(:meta, name_key => name.to_s, value_key => value) if value.present?
280
+ tags << Tag.new(:meta, name_key => name.to_s, :content => value, :itemprop => itemprop) if value.present?
250
281
  end
251
282
 
252
283
  # Returns meta tag property name for a give meta tag based on the
253
284
  # configured list of property tags in MetaTags::Configuration#property_tags.
254
285
  #
255
- # @param [String, Symbol] meta tag key.
256
- # @return [String] meta tag attribute name ("property" or "name").
286
+ # @param [String, Symbol] name tag key.
287
+ # @return [Symbol] meta tag attribute name (:property or :name).
257
288
  #
258
289
  def configured_name_key(name)
259
290
  is_property_tag = MetaTags.config.property_tags.any? do |tag_name|
data/lib/meta_tags/tag.rb CHANGED
@@ -11,7 +11,7 @@ module MetaTags
11
11
  # @param [Hash] attributes list of HTML tag attributes
12
12
  #
13
13
  def initialize(name, attributes = {})
14
- @name = name
14
+ @name = name.to_s
15
15
  @attributes = attributes
16
16
  end
17
17