meta-tags 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -1
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +11 -1
- data/Rakefile +10 -0
- data/certs/kpumuk.pem +18 -19
- data/lib/generators/meta_tags/install_generator.rb +3 -1
- data/lib/generators/meta_tags/templates/config/initializers/meta_tags.rb +6 -0
- data/lib/meta-tags.rb +2 -0
- data/lib/meta_tags.rb +5 -3
- data/lib/meta_tags/configuration.rb +7 -0
- data/lib/meta_tags/content_tag.rb +2 -0
- data/lib/meta_tags/controller_helper.rb +6 -4
- data/lib/meta_tags/meta_tags_collection.rb +16 -5
- data/lib/meta_tags/renderer.rb +26 -24
- data/lib/meta_tags/tag.rb +2 -0
- data/lib/meta_tags/text_normalizer.rb +38 -17
- data/lib/meta_tags/version.rb +3 -1
- data/lib/meta_tags/view_helper.rb +17 -9
- data/meta-tags.gemspec +4 -2
- metadata +22 -23
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 827318e8c08dab5cef3d26fb5b3be72c2c181c503d7d3c784c0175b6d0a4d8dd
|
4
|
+
data.tar.gz: 57aba518f8fae0222b7a7f88610de04504f9b8c09e617106b7f83856f33bca36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1ce5878ae54cf7b99c2815623a896fe34a03aba1c72f8914a7a617a508baee705cdeb64b8c3d325c5408029681db1c0015b17baf96c081da18161a93658b57
|
7
|
+
data.tar.gz: eb609dcf0374e880ff75eb664467f04f80367d605ef7bd84fc4446b3df579bbf6fd5ed5925485b5f39ce400e8328a6ccebf056a047a5bc7f11614694e0dfd9c5
|
checksums.yaml.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
g��H���0�Ξ��i�"x�i��܄Q��j��/�u���q�j)�����,~�8uK7��6��e��0�/͞c�ě��P���jc��g�ՠT7͜�;&����~��rY+�0�}V���͟?Ꙑ}��i�M�sf��`BA3&P��QҠ���3�R�1�5�wAz5�זW����)�$R�6���M���4J�d$�\��Z�EvR��u�2���U#��>���C�<��0fi].�f[��n��
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 2.11.0 (November 16, 2018) [☰](https://github.com/kpumuk/meta-tags/compare/v2.10.0...v2.11.0)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
- Added a configuration option `minify_output` to remove new line characters between meta tags ([182](https://github.com/kpumuk/meta-tags/pull/182))
|
5
|
+
– Title, description, and keywords can be an object responding to `#to_str` ([183](https://github.com/kpumuk/meta-tags/pull/183))
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
- Truncate title before escaping HTML characters ([180](https://github.com/kpumuk/meta-tags/pull/180))
|
9
|
+
|
1
10
|
## 2.10.0 (June 8, 2018) [☰](https://github.com/kpumuk/meta-tags/compare/v2.9.0...v2.10.0)
|
2
11
|
|
3
12
|
Features:
|
data/Gemfile
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'http://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in meta-tags.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
|
8
|
+
if ENV['RAILS_VERSION']
|
9
|
+
# Install specified version of actionpack if requested
|
10
|
+
gem 'actionpack', "~> #{ENV['RAILS_VERSION']}"
|
11
|
+
end
|
7
12
|
|
8
13
|
group :test do
|
14
|
+
# Lock rubocop to a specific version we use on CI. If you update this,
|
15
|
+
# don't forget to switch rubocop channel in the .codeclimate.yml
|
16
|
+
gem 'rubocop', '0.60.0'
|
17
|
+
# We use this gem on CI to calculate code coverage.
|
9
18
|
gem 'simplecov'
|
19
|
+
# Format RSpec output for CircleCI
|
10
20
|
gem 'rspec_junit_formatter'
|
11
21
|
end
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
@@ -6,3 +8,11 @@ RSpec::Core::RakeTask.new(:spec)
|
|
6
8
|
|
7
9
|
task test: :spec
|
8
10
|
task default: :spec
|
11
|
+
|
12
|
+
desc 'Rebuild Circle CI configuration based on the build matrix template .circleci/config.yml.erb'
|
13
|
+
task :circleci do
|
14
|
+
require 'erb'
|
15
|
+
template_path = File.expand_path('.circleci/config.yml.erb', __dir__)
|
16
|
+
config_path = File.expand_path('.circleci/config.yml', __dir__)
|
17
|
+
File.write config_path, ERB.new(File.read(template_path)).result
|
18
|
+
end
|
data/certs/kpumuk.pem
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
C9c9eUxgNTnHhsR3sK0QCIMwtUI=
|
2
|
+
MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhrcHVt
|
3
|
+
dWsvREM9a3B1bXVrL0RDPWluZm8wHhcNMTgxMTE2MTgxOTIzWhcNMTkxMTE2MTgx
|
4
|
+
OTIzWjAjMSEwHwYDVQQDDBhrcHVtdWsvREM9a3B1bXVrL0RDPWluZm8wggEiMA0G
|
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
|
+
BBYwFIESa3B1bXVrQGtwdW11ay5pbmZvMA0GCSqGSIb3DQEBCwUAA4IBAQB9bd46
|
14
|
+
p2C6r49hmuxMrIFRi05MS0Nze6GvlYvF5mb2+KS9YCLWLFb1G+0zttX51qVdO3nc
|
15
|
+
uw1O5ku+Up47jv5ClyguHinCntFCA5hupyYkbpnFuURZE3QIY6UZQyJ2xuIPFfnR
|
16
|
+
Q8sXb5/btWSNhKXx29TL35SkEH5fzPA90DljUPGp3lLEK0+7FQk0OkRVumdyanEE
|
17
|
+
LUchqnAWHnNCdQhEhsnbYhSvG0NE2uzMWeUd6uDONYsRFNRXaRwj8tykWgKZvIod
|
18
|
+
j0ZkOZOMk6hzny9+AnYZ7eiUqp/XX7Hn+hqtl/AebKhbFapnTu0n7KcfM0oDaLUr
|
19
|
+
Fc+FAHErSClMb7YN
|
21
20
|
-----END CERTIFICATE-----
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
4
6
|
desc "Copy MetaTags default files"
|
5
|
-
source_root File.expand_path('
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
6
8
|
|
7
9
|
def copy_config
|
8
10
|
template "config/initializers/meta_tags.rb"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Use this setup block to configure all options available in MetaTags.
|
2
4
|
MetaTags.configure do |config|
|
3
5
|
# How many characters should the title meta tag have at most. Default is 70.
|
@@ -22,6 +24,10 @@ MetaTags.configure do |config|
|
|
22
24
|
# appear on the page as is. Default is true.
|
23
25
|
# config.keywords_lowercase = true
|
24
26
|
|
27
|
+
# When true, the output will not include new line characters between meta tags.
|
28
|
+
# Default is false.
|
29
|
+
# config.minify_output = false
|
30
|
+
|
25
31
|
# When false, generated meta tags will be self-closing (<meta ... />) instead
|
26
32
|
# of open (`<meta ...>`). Default is true.
|
27
33
|
# config.open_meta_tags = true
|
data/lib/meta-tags.rb
CHANGED
data/lib/meta_tags.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'English'
|
2
4
|
require 'action_controller'
|
3
5
|
require 'action_view'
|
@@ -7,7 +9,7 @@ module MetaTags
|
|
7
9
|
# Returns MetaTags gem configuration.
|
8
10
|
#
|
9
11
|
def self.config
|
10
|
-
|
12
|
+
@config ||= Configuration.new
|
11
13
|
end
|
12
14
|
|
13
15
|
# Configures MetaTags gem.
|
@@ -34,5 +36,5 @@ require 'meta_tags/content_tag'
|
|
34
36
|
require 'meta_tags/text_normalizer'
|
35
37
|
require 'meta_tags/view_helper'
|
36
38
|
|
37
|
-
ActionView::Base.
|
38
|
-
ActionController::Base.
|
39
|
+
ActionView::Base.include MetaTags::ViewHelper
|
40
|
+
ActionController::Base.include MetaTags::ControllerHelper
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
# MetaTags configuration.
|
3
5
|
class Configuration
|
@@ -23,6 +25,10 @@ module MetaTags
|
|
23
25
|
# Default is true, which means "open".
|
24
26
|
attr_accessor :open_meta_tags
|
25
27
|
|
28
|
+
# When true, the output will not include new line characters between meta tags.
|
29
|
+
# Default is false.
|
30
|
+
attr_accessor :minify_output
|
31
|
+
|
26
32
|
# Custom meta tags that should use `property` attribute instead of `name`
|
27
33
|
# - an array of strings or symbols representing their names or name-prefixes.
|
28
34
|
attr_reader :property_tags
|
@@ -70,6 +76,7 @@ module MetaTags
|
|
70
76
|
@keywords_lowercase = true
|
71
77
|
@property_tags = default_property_tags.dup
|
72
78
|
@open_meta_tags = true
|
79
|
+
@minify_output = false
|
73
80
|
end
|
74
81
|
end
|
75
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
# Contains methods to use in controllers.
|
3
5
|
#
|
@@ -13,9 +15,9 @@ module MetaTags
|
|
13
15
|
# Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
|
14
16
|
# <tt>@page_description</tt> instance variables and calls +render+.
|
15
17
|
def render(*args, &block)
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
19
21
|
|
20
22
|
super
|
21
23
|
end
|
@@ -23,7 +25,7 @@ module MetaTags
|
|
23
25
|
# Set meta tags for the page.
|
24
26
|
#
|
25
27
|
# See <tt>MetaTags::ViewHelper#set_meta_tags</tt> for details.
|
26
|
-
def set_meta_tags(meta_tags)
|
28
|
+
def set_meta_tags(meta_tags) # rubocop:disable Naming/AccessorMethodName
|
27
29
|
self.meta_tags.update(meta_tags)
|
28
30
|
end
|
29
31
|
protected :set_meta_tags
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
# Class represents a collection of meta tags. Basically a wrapper around
|
3
5
|
# HashWithIndifferentAccess, with some additional helper methods.
|
@@ -47,7 +49,7 @@ module MetaTags
|
|
47
49
|
#
|
48
50
|
def with_defaults(defaults = {})
|
49
51
|
old_meta_tags = @meta_tags
|
50
|
-
@meta_tags = normalize_open_graph(defaults).deep_merge!(
|
52
|
+
@meta_tags = normalize_open_graph(defaults).deep_merge!(@meta_tags)
|
51
53
|
yield
|
52
54
|
ensure
|
53
55
|
@meta_tags = old_meta_tags
|
@@ -113,7 +115,8 @@ module MetaTags
|
|
113
115
|
return unless title
|
114
116
|
|
115
117
|
title = Array(title)
|
116
|
-
title.
|
118
|
+
return title.map(&:downcase) if extract(:lowercase) == true
|
119
|
+
|
117
120
|
title
|
118
121
|
end
|
119
122
|
|
@@ -148,9 +151,17 @@ module MetaTags
|
|
148
151
|
|
149
152
|
noindex_attributes = if noindex_name == follow_name && (noindex_value || follow_value)
|
150
153
|
# noindex has higher priority than index and follow has higher priority than nofollow
|
151
|
-
[
|
154
|
+
[
|
155
|
+
[noindex_name, noindex_value || index_value],
|
156
|
+
[follow_name, follow_value || nofollow_value],
|
157
|
+
]
|
152
158
|
else
|
153
|
-
[
|
159
|
+
[
|
160
|
+
[index_name, index_value],
|
161
|
+
[follow_name, follow_value],
|
162
|
+
[noindex_name, noindex_value],
|
163
|
+
[nofollow_name, nofollow_value],
|
164
|
+
]
|
154
165
|
end
|
155
166
|
append_noarchive_attribute group_attributes_by_key noindex_attributes
|
156
167
|
end
|
@@ -215,7 +226,7 @@ module MetaTags
|
|
215
226
|
# @return [Hash<String, String>] hash of grouped noindex keys and values
|
216
227
|
#
|
217
228
|
def group_attributes_by_key(attributes)
|
218
|
-
Hash[attributes.group_by(&:first).map { |k, v| [k, v.map(&:last).compact.join(', ')] }]
|
229
|
+
Hash[attributes.group_by(&:first).map { |k, v| [k, v.map(&:last).tap(&:compact!).join(', ')] }]
|
219
230
|
end
|
220
231
|
end
|
221
232
|
end
|
data/lib/meta_tags/renderer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
# This class is used by MetaTags gems to render HTML meta tags into page.
|
3
5
|
class Renderer
|
@@ -32,7 +34,8 @@ module MetaTags
|
|
32
34
|
render_hashes(tags)
|
33
35
|
render_custom(tags)
|
34
36
|
|
35
|
-
tags.compact.map { |tag| tag.render(view) }
|
37
|
+
tags.tap(&:compact!).map! { |tag| tag.render(view) }
|
38
|
+
view.safe_join tags, MetaTags.config.minify_output ? "" : "\n"
|
36
39
|
end
|
37
40
|
|
38
41
|
protected
|
@@ -66,14 +69,14 @@ module MetaTags
|
|
66
69
|
icon = meta_tags.extract(:icon)
|
67
70
|
return unless icon
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
# String? Value is an href
|
73
|
+
icon = [{ href: icon }] if icon.kind_of?(String)
|
74
|
+
# Hash? Single icon instead of a list of icons
|
75
|
+
icon = [icon] if icon.kind_of?(Hash)
|
76
|
+
|
77
|
+
icon.each do |icon_params|
|
78
|
+
icon_params = { rel: 'icon', type: 'image/x-icon' }.with_indifferent_access.merge(icon_params)
|
79
|
+
tags << Tag.new(:link, icon_params)
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
@@ -160,9 +163,9 @@ module MetaTags
|
|
160
163
|
#
|
161
164
|
# @param [Array<Tag>] tags a buffer object to store tag in.
|
162
165
|
#
|
163
|
-
def render_hashes(tags,
|
164
|
-
meta_tags.meta_tags.
|
165
|
-
render_hash(tags, property,
|
166
|
+
def render_hashes(tags, **opts)
|
167
|
+
meta_tags.meta_tags.each_key do |property|
|
168
|
+
render_hash(tags, property, **opts)
|
166
169
|
end
|
167
170
|
end
|
168
171
|
|
@@ -170,11 +173,11 @@ module MetaTags
|
|
170
173
|
#
|
171
174
|
# @param [Array<Tag>] tags a buffer object to store tag in.
|
172
175
|
#
|
173
|
-
def render_hash(tags, key,
|
176
|
+
def render_hash(tags, key, **opts)
|
174
177
|
data = meta_tags.meta_tags[key]
|
175
178
|
return unless data.kind_of?(Hash)
|
176
179
|
|
177
|
-
process_hash(tags, key, data,
|
180
|
+
process_hash(tags, key, data, **opts)
|
178
181
|
meta_tags.extract(key)
|
179
182
|
end
|
180
183
|
|
@@ -198,7 +201,7 @@ module MetaTags
|
|
198
201
|
# @param [Hash, Array, String, Symbol] content text content or a symbol reference to
|
199
202
|
# top-level meta tag.
|
200
203
|
#
|
201
|
-
def process_tree(tags, property, content,
|
204
|
+
def process_tree(tags, property, content, **opts)
|
202
205
|
method = case content
|
203
206
|
when Hash
|
204
207
|
:process_hash
|
@@ -207,7 +210,7 @@ module MetaTags
|
|
207
210
|
else
|
208
211
|
:render_tag
|
209
212
|
end
|
210
|
-
|
213
|
+
__send__(method, tags, property, content, **opts)
|
211
214
|
end
|
212
215
|
|
213
216
|
# Recursive method to process a hash with meta tags
|
@@ -216,11 +219,11 @@ module MetaTags
|
|
216
219
|
# @param [String, Symbol] property a Hash or a String to render as meta tag.
|
217
220
|
# @param [Hash] content nested meta tag attributes.
|
218
221
|
#
|
219
|
-
def process_hash(tags, property, content,
|
222
|
+
def process_hash(tags, property, content, **opts)
|
220
223
|
content.each do |key, value|
|
221
224
|
key = key.to_s == '_' ? property : "#{property}:#{key}"
|
222
225
|
value = normalized_meta_tags[value] if value.kind_of?(Symbol)
|
223
|
-
process_tree(tags, key, value,
|
226
|
+
process_tree(tags, key, value, **opts)
|
224
227
|
end
|
225
228
|
end
|
226
229
|
|
@@ -230,8 +233,8 @@ module MetaTags
|
|
230
233
|
# @param [String, Symbol] property a Hash or a String to render as meta tag.
|
231
234
|
# @param [Array] content array of nested meta tag attributes or values.
|
232
235
|
#
|
233
|
-
def process_array(tags, property, content,
|
234
|
-
content.each { |v| process_tree(tags, property, v,
|
236
|
+
def process_array(tags, property, content, **opts)
|
237
|
+
content.each { |v| process_tree(tags, property, v, **opts) }
|
235
238
|
end
|
236
239
|
|
237
240
|
# Recursive method to process a hash with meta tags
|
@@ -241,10 +244,9 @@ module MetaTags
|
|
241
244
|
# @param [String, Symbol] value text content or a symbol reference to
|
242
245
|
# top-level meta tag.
|
243
246
|
#
|
244
|
-
def render_tag(tags, name, value,
|
245
|
-
name_key
|
246
|
-
|
247
|
-
tags << Tag.new(:meta, name_key => name.to_s, value_key => value) unless value.blank?
|
247
|
+
def render_tag(tags, name, value, name_key: nil, value_key: :content)
|
248
|
+
name_key ||= configured_name_key(name)
|
249
|
+
tags << Tag.new(:meta, name_key => name.to_s, value_key => value) if value.present?
|
248
250
|
end
|
249
251
|
|
250
252
|
# Returns meta tag property name for a give meta tag based on the
|
data/lib/meta_tags/tag.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
# Module contains helpers that normalize text meta tag values.
|
3
5
|
module TextNormalizer
|
4
|
-
extend self
|
6
|
+
extend self # rubocop:disable Style/ModuleFunction
|
5
7
|
|
6
8
|
# Normalize title value.
|
7
9
|
#
|
@@ -12,11 +14,11 @@ module MetaTags
|
|
12
14
|
# @return [Array<String>] array of title parts with tags removed.
|
13
15
|
#
|
14
16
|
def normalize_title(site_title, title, separator, reverse = false)
|
15
|
-
title =
|
17
|
+
title = cleanup_strings(title)
|
16
18
|
title.reverse! if reverse
|
17
19
|
|
18
|
-
site_title =
|
19
|
-
separator =
|
20
|
+
site_title = cleanup_string(site_title)
|
21
|
+
separator = cleanup_string(separator, strip: false)
|
20
22
|
|
21
23
|
# Truncate title and site title
|
22
24
|
site_title, title = truncate_title(site_title, title, separator)
|
@@ -38,8 +40,12 @@ module MetaTags
|
|
38
40
|
# to 200 characters.
|
39
41
|
#
|
40
42
|
def normalize_description(description)
|
41
|
-
|
43
|
+
# description could be another object not a string, but since it probably
|
44
|
+
# serves the same purpose we could just as it to convert itself to str
|
45
|
+
# and continue from there
|
42
46
|
description = cleanup_string(description)
|
47
|
+
return '' if description.blank?
|
48
|
+
|
43
49
|
truncate(description, MetaTags.config.description_limit)
|
44
50
|
end
|
45
51
|
|
@@ -49,10 +55,11 @@ module MetaTags
|
|
49
55
|
# @return [String] list of keywords joined with comma, with tags removed.
|
50
56
|
#
|
51
57
|
def normalize_keywords(keywords)
|
52
|
-
return '' if keywords.blank?
|
53
58
|
keywords = cleanup_strings(keywords)
|
59
|
+
return '' if keywords.blank?
|
60
|
+
|
54
61
|
keywords.each(&:downcase!) if MetaTags.config.keywords_lowercase
|
55
|
-
separator =
|
62
|
+
separator = cleanup_string MetaTags.config.keywords_separator, strip: false
|
56
63
|
|
57
64
|
keywords = truncate_array(keywords, MetaTags.config.keywords_limit, separator)
|
58
65
|
safe_join(keywords, separator)
|
@@ -74,10 +81,9 @@ module MetaTags
|
|
74
81
|
def strip_tags(string)
|
75
82
|
if defined?(Loofah)
|
76
83
|
# Instead of strip_tags we will use Loofah to strip tags from now on
|
77
|
-
|
78
|
-
ERB::Util.html_escape stripped_unescaped
|
84
|
+
Loofah.fragment(string).text(encode_special_chars: false)
|
79
85
|
else
|
80
|
-
|
86
|
+
helpers.strip_tags(string)
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
@@ -100,8 +106,14 @@ module MetaTags
|
|
100
106
|
# @return [String] input string with no HTML tags and consequent white
|
101
107
|
# space characters squashed into a single space.
|
102
108
|
#
|
103
|
-
def cleanup_string(string)
|
104
|
-
|
109
|
+
def cleanup_string(string, strip: true)
|
110
|
+
return '' if string.nil?
|
111
|
+
raise ArgumentError, 'Expected a string or an object that implements #to_str' unless string.respond_to?(:to_str)
|
112
|
+
|
113
|
+
strip_tags(string.to_str).tap do |s|
|
114
|
+
s.gsub!(/\s+/, ' ')
|
115
|
+
s.strip! if strip
|
116
|
+
end
|
105
117
|
end
|
106
118
|
|
107
119
|
# Cleans multiple strings up.
|
@@ -110,8 +122,10 @@ module MetaTags
|
|
110
122
|
# @return [Array<String>] clean strings.
|
111
123
|
# @see cleanup_string
|
112
124
|
#
|
113
|
-
def cleanup_strings(strings)
|
114
|
-
Array(strings).flatten.map(
|
125
|
+
def cleanup_strings(strings, strip: true)
|
126
|
+
strings = Array(strings).flatten.map! { |s| cleanup_string(s, strip: strip) }
|
127
|
+
strings.reject!(&:blank?)
|
128
|
+
strings
|
115
129
|
end
|
116
130
|
|
117
131
|
# Truncates a string to a specific limit. Return string without truncation when limit 0 or nil
|
@@ -122,8 +136,15 @@ module MetaTags
|
|
122
136
|
# @return [String] truncated string.
|
123
137
|
#
|
124
138
|
def truncate(string, limit = nil, natural_separator = ' ')
|
125
|
-
return string if limit.to_i == 0
|
126
|
-
|
139
|
+
return string if limit.to_i == 0 # rubocop:disable Lint/NumberConversion
|
140
|
+
|
141
|
+
helpers.truncate(
|
142
|
+
string,
|
143
|
+
length: limit,
|
144
|
+
separator: natural_separator,
|
145
|
+
omission: '',
|
146
|
+
escape: true,
|
147
|
+
)
|
127
148
|
end
|
128
149
|
|
129
150
|
# Truncates a string to a specific limit.
|
@@ -165,7 +186,7 @@ module MetaTags
|
|
165
186
|
end
|
166
187
|
|
167
188
|
def truncate_title(site_title, title, separator)
|
168
|
-
if MetaTags.config.title_limit.to_i > 0
|
189
|
+
if MetaTags.config.title_limit.to_i > 0 # rubocop:disable Lint/NumberConversion
|
169
190
|
site_title_limited_length, title_limited_length = calculate_title_limits(site_title, title, separator)
|
170
191
|
|
171
192
|
title = title_limited_length > 0 ? truncate_array(title, title_limited_length, separator) : []
|
data/lib/meta_tags/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MetaTags
|
2
4
|
# Contains methods to use in views and helpers.
|
3
5
|
#
|
@@ -25,7 +27,7 @@ module MetaTags
|
|
25
27
|
#
|
26
28
|
# @see #display_meta_tags
|
27
29
|
#
|
28
|
-
def set_meta_tags(meta_tags = {})
|
30
|
+
def set_meta_tags(meta_tags = {}) # rubocop:disable Naming/AccessorMethodName
|
29
31
|
self.meta_tags.update(meta_tags)
|
30
32
|
end
|
31
33
|
|
@@ -55,7 +57,7 @@ module MetaTags
|
|
55
57
|
#
|
56
58
|
def title(title = nil, headline = '')
|
57
59
|
set_meta_tags(title: title) unless title.nil?
|
58
|
-
headline.
|
60
|
+
headline.presence || meta_tags[:title]
|
59
61
|
end
|
60
62
|
|
61
63
|
# Set the page keywords.
|
@@ -149,13 +151,17 @@ module MetaTags
|
|
149
151
|
# @option default [String] :title ("") page title;
|
150
152
|
# @option default [String] :description (nil) page description;
|
151
153
|
# @option default [String] :keywords (nil) page keywords;
|
152
|
-
# @option default [String, Boolean] :prefix (" ") text between site name and separator;
|
154
|
+
# @option default [String, Boolean] :prefix (" ") text between site name and separator;
|
155
|
+
# when +false+, no prefix will be rendered;
|
153
156
|
# @option default [String] :separator ("|") text used to separate website name from page title;
|
154
|
-
# @option default [String, Boolean] :suffix (" ") text between separator and page title;
|
157
|
+
# @option default [String, Boolean] :suffix (" ") text between separator and page title;
|
158
|
+
# when +false+, no suffix will be rendered;
|
155
159
|
# @option default [Boolean] :lowercase (false) when true, the page title will be lowercase;
|
156
160
|
# @option default [Boolean] :reverse (false) when true, the page and site names will be reversed;
|
157
|
-
# @option default [Boolean, String] :noindex (false) add noindex meta tag; when true, 'robots' will be used,
|
158
|
-
#
|
161
|
+
# @option default [Boolean, String] :noindex (false) add noindex meta tag; when true, 'robots' will be used,
|
162
|
+
# otherwise the string will be used;
|
163
|
+
# @option default [Boolean, String] :nofollow (false) add nofollow meta tag; when true, 'robots' will be used,
|
164
|
+
# otherwise the string will be used;
|
159
165
|
# @option default [String] :canonical (nil) add canonical link tag.
|
160
166
|
# @option default [Hash] :alternate ({}) add alternate link tag.
|
161
167
|
# @option default [String] :prev (nil) add prev link tag;
|
@@ -172,7 +178,7 @@ module MetaTags
|
|
172
178
|
# </head>
|
173
179
|
#
|
174
180
|
def display_meta_tags(defaults = {})
|
175
|
-
|
181
|
+
meta_tags.with_defaults(defaults) { Renderer.new(meta_tags).render(self) }
|
176
182
|
end
|
177
183
|
|
178
184
|
# Returns full page title as a string without surrounding <title> tag.
|
@@ -185,9 +191,11 @@ module MetaTags
|
|
185
191
|
# @param [Hash] defaults list of meta tags.
|
186
192
|
# @option default [String] :site (nil) site title;
|
187
193
|
# @option default [String] :title ("") page title;
|
188
|
-
# @option default [String, Boolean] :prefix (" ") text between site name and separator; when +false+,
|
194
|
+
# @option default [String, Boolean] :prefix (" ") text between site name and separator; when +false+,
|
195
|
+
# no prefix will be rendered;
|
189
196
|
# @option default [String] :separator ("|") text used to separate website name from page title;
|
190
|
-
# @option default [String, Boolean] :suffix (" ") text between separator and page title; when +false+,
|
197
|
+
# @option default [String, Boolean] :suffix (" ") text between separator and page title; when +false+,
|
198
|
+
# no suffix will be rendered;
|
191
199
|
# @option default [Boolean] :lowercase (false) when true, the page name will be lowercase;
|
192
200
|
# @option default [Boolean] :reverse (false) when true, the page and site names will be reversed;
|
193
201
|
#
|
data/meta-tags.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'meta_tags/version'
|
4
6
|
|
@@ -22,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
22
24
|
spec.add_dependency "actionpack", ">= 3.2.0", "< 5.3"
|
23
25
|
|
24
26
|
spec.add_development_dependency "rake", "~> 12.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.8.0"
|
26
28
|
spec.add_development_dependency "rspec-html-matchers", "~> 0.9.1"
|
27
29
|
|
28
30
|
spec.cert_chain = ["certs/kpumuk.pem"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta-tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Shteflyuk
|
@@ -10,27 +10,26 @@ bindir: exe
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
C9c9eUxgNTnHhsR3sK0QCIMwtUI=
|
13
|
+
MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhrcHVt
|
14
|
+
dWsvREM9a3B1bXVrL0RDPWluZm8wHhcNMTgxMTE2MTgxOTIzWhcNMTkxMTE2MTgx
|
15
|
+
OTIzWjAjMSEwHwYDVQQDDBhrcHVtdWsvREM9a3B1bXVrL0RDPWluZm8wggEiMA0G
|
16
|
+
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8NmK6GXPiE/q7PDbj7nNdw3pa8a6Q
|
17
|
+
IDxLtc7kW95e1mh0TVgOE8kvGegGtRtjvhXVGTTFtZ+yMD/0DCfTM2oUQYk5oYpO
|
18
|
+
ZGrCfbNIdZauf4WYsnJtKOTrRoqFMwpL5PlBDKczB2y5lUmQs2HIsjQ0Q21wdKyy
|
19
|
+
7tXiZPoCoJ+kH+b4/d4dcNvAXVnWgO2HoLW5oqWfqY5swkAHzwHLU+rlxxuHUqOy
|
20
|
+
8/Y4hUSOXVIsxWxl3EapENm+QAfBRZn3L26hEb80CgSAp8m47Cj9DaSd7xoDtrIe
|
21
|
+
RryRTj5NVZbq9p1/WRc5zxD9QhAEPjRa5ikbd+eWebIDpAKI0hpyC/9bAgMBAAGj
|
22
|
+
dzB1MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBT2uFRXNWDpVdbv
|
23
|
+
+xBk8DAgJPGBPTAdBgNVHREEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wHQYDVR0S
|
24
|
+
BBYwFIESa3B1bXVrQGtwdW11ay5pbmZvMA0GCSqGSIb3DQEBCwUAA4IBAQB9bd46
|
25
|
+
p2C6r49hmuxMrIFRi05MS0Nze6GvlYvF5mb2+KS9YCLWLFb1G+0zttX51qVdO3nc
|
26
|
+
uw1O5ku+Up47jv5ClyguHinCntFCA5hupyYkbpnFuURZE3QIY6UZQyJ2xuIPFfnR
|
27
|
+
Q8sXb5/btWSNhKXx29TL35SkEH5fzPA90DljUPGp3lLEK0+7FQk0OkRVumdyanEE
|
28
|
+
LUchqnAWHnNCdQhEhsnbYhSvG0NE2uzMWeUd6uDONYsRFNRXaRwj8tykWgKZvIod
|
29
|
+
j0ZkOZOMk6hzny9+AnYZ7eiUqp/XX7Hn+hqtl/AebKhbFapnTu0n7KcfM0oDaLUr
|
30
|
+
Fc+FAHErSClMb7YN
|
32
31
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-
|
32
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
34
33
|
dependencies:
|
35
34
|
- !ruby/object:Gem::Dependency
|
36
35
|
name: actionpack
|
@@ -72,14 +71,14 @@ dependencies:
|
|
72
71
|
requirements:
|
73
72
|
- - "~>"
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
74
|
+
version: 3.8.0
|
76
75
|
type: :development
|
77
76
|
prerelease: false
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
79
78
|
requirements:
|
80
79
|
- - "~>"
|
81
80
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
81
|
+
version: 3.8.0
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
83
|
name: rspec-html-matchers
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|