meta-tags 2.12.0 → 2.16.0

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.
@@ -8,29 +8,29 @@ module MetaTags
8
8
  # Normalize title value.
9
9
  #
10
10
  # @param [String] site_title site title.
11
- # @param [String, Array<String>] title title string.
11
+ # @param [Array<String>] title title string.
12
12
  # @param [String] separator a string to join title parts with.
13
13
  # @param [true,false] reverse whether title should be reversed.
14
- # @return [Array<String>] array of title parts with tags removed.
14
+ # @return [String] title with HTML tags removed.
15
15
  #
16
16
  def normalize_title(site_title, title, separator, reverse = false)
17
- title = cleanup_strings(title)
18
- title.reverse! if reverse
17
+ clean_title = cleanup_strings(title)
18
+ clean_title.reverse! if reverse
19
19
 
20
20
  site_title = cleanup_string(site_title)
21
21
  separator = cleanup_string(separator, strip: false)
22
22
 
23
23
  # Truncate title and site title
24
- site_title, title = truncate_title(site_title, title, separator)
24
+ site_title, clean_title = truncate_title(site_title, clean_title, separator)
25
25
 
26
26
  if site_title.present?
27
27
  if reverse
28
- title.push(site_title)
28
+ clean_title.push(site_title)
29
29
  else
30
- title.unshift(site_title)
30
+ clean_title.unshift(site_title)
31
31
  end
32
32
  end
33
- safe_join(title, separator)
33
+ safe_join(clean_title, separator)
34
34
  end
35
35
 
36
36
  # Normalize description value.
@@ -102,7 +102,7 @@ module MetaTags
102
102
 
103
103
  # Removes HTML tags and squashes down all the spaces.
104
104
  #
105
- # @param [String] string input string.
105
+ # @param [String, nil] string input string.
106
106
  # @return [String] input string with no HTML tags and consequent white
107
107
  # space characters squashed into a single space.
108
108
  #
@@ -110,15 +110,17 @@ module MetaTags
110
110
  return '' if string.nil?
111
111
  raise ArgumentError, 'Expected a string or an object that implements #to_str' unless string.respond_to?(:to_str)
112
112
 
113
- strip_tags(string.to_str).tap do |s|
114
- s.gsub!(/\s+/, ' ')
115
- s.strip! if strip
116
- end
113
+ s = strip_tags(string.to_str)
114
+ s = s.dup if s.frozen?
115
+ s.gsub!(/\s+/, ' ')
116
+ s.strip! if strip
117
+
118
+ s
117
119
  end
118
120
 
119
121
  # Cleans multiple strings up.
120
122
  #
121
- # @param [Array<String>] strings input strings.
123
+ # @param [String, Array<String>] strings input string(s).
122
124
  # @return [Array<String>] clean strings.
123
125
  # @see cleanup_string
124
126
  #
@@ -147,13 +149,13 @@ module MetaTags
147
149
  )
148
150
  end
149
151
 
150
- # Truncates a string to a specific limit.
152
+ # Truncates an array of strings to a specific limit.
151
153
  #
152
154
  # @param [Array<String>] string_array input strings.
153
155
  # @param [Integer,nil] limit characters number to truncate to.
154
156
  # @param [String] separator separator that will be used to join array later.
155
157
  # @param [String] natural_separator natural separator to truncate at.
156
- # @return [String] truncated string.
158
+ # @return [Array<String>] truncated array of strings.
157
159
  #
158
160
  def truncate_array(string_array, limit = nil, separator = '', natural_separator = ' ')
159
161
  return string_array if limit.nil? || limit <= 0
@@ -166,14 +168,14 @@ module MetaTags
166
168
 
167
169
  if string.length > limit_left
168
170
  result << truncate(string, limit_left, natural_separator)
169
- break
171
+ break string_array
170
172
  end
171
173
 
172
174
  length += (result.any? ? separator.length : 0) + string.length
173
175
  result << string
174
176
 
175
177
  # No more strings will fit
176
- break if length + separator.length >= limit
178
+ break string_array if length + separator.length >= limit
177
179
  end
178
180
 
179
181
  result
@@ -186,8 +188,11 @@ module MetaTags
186
188
  end
187
189
 
188
190
  def truncate_title(site_title, title, separator)
189
- if MetaTags.config.title_limit.to_i > 0 # rubocop:disable Lint/NumberConversion
190
- site_title_limited_length, title_limited_length = calculate_title_limits(site_title, title, separator)
191
+ global_limit = MetaTags.config.title_limit.to_i # rubocop:disable Lint/NumberConversion
192
+ if global_limit > 0
193
+ site_title_limited_length, title_limited_length = calculate_title_limits(
194
+ site_title, title, separator, global_limit,
195
+ )
191
196
 
192
197
  title = title_limited_length > 0 ? truncate_array(title, title_limited_length, separator) : []
193
198
  site_title = site_title_limited_length > 0 ? truncate(site_title, site_title_limited_length) : nil
@@ -196,14 +201,14 @@ module MetaTags
196
201
  [site_title, title]
197
202
  end
198
203
 
199
- def calculate_title_limits(site_title, title, separator)
204
+ def calculate_title_limits(site_title, title, separator, global_limit)
200
205
  # What should we truncate first: site title or page title?
201
206
  main_title = MetaTags.config.truncate_site_title_first ? title : [site_title]
202
207
 
203
208
  main_length = main_title.map(&:length).sum + (main_title.size - 1) * separator.length
204
- main_limited_length = MetaTags.config.title_limit
209
+ main_limited_length = global_limit
205
210
 
206
- secondary_limited_length = MetaTags.config.title_limit - (main_length > 0 ? main_length + separator.length : 0)
211
+ secondary_limited_length = global_limit - (main_length > 0 ? main_length + separator.length : 0)
207
212
  secondary_limited_length = [0, secondary_limited_length].max
208
213
 
209
214
  if MetaTags.config.truncate_site_title_first
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MetaTags
4
4
  # Gem version.
5
- VERSION = '2.12.0'
5
+ VERSION = '2.16.0'
6
6
  public_constant :VERSION
7
7
  end
@@ -97,8 +97,8 @@ module MetaTags
97
97
 
98
98
  # Set the noindex meta tag
99
99
  #
100
- # @param [Boolean, String] noindex a noindex value.
101
- # @return [Boolean, String] passed value.
100
+ # @param [Boolean, String, Array<String>] noindex a noindex value.
101
+ # @return [Boolean, String, Array<String>] passed value.
102
102
  #
103
103
  # @example
104
104
  # noindex true
@@ -113,8 +113,8 @@ module MetaTags
113
113
 
114
114
  # Set the nofollow meta tag
115
115
  #
116
- # @param [Boolean, String] nofollow a nofollow value.
117
- # @return [Boolean, String] passed value.
116
+ # @param [Boolean, String, Array<String>] nofollow a nofollow value.
117
+ # @return [Boolean, String, Array<String>] passed value.
118
118
  #
119
119
  # @example
120
120
  # nofollow true
@@ -205,7 +205,5 @@ module MetaTags
205
205
  def display_title(defaults = {})
206
206
  @meta_tags.full_title(defaults)
207
207
  end
208
-
209
- # safe_helper :display_meta_tags if defined?(:safe_helper)
210
208
  end
211
209
  end
data/lib/meta_tags.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'English'
4
- require 'action_controller'
5
- require 'action_view'
6
-
7
3
  # MetaTags gem namespace.
8
4
  module MetaTags
9
5
  # Returns MetaTags gem configuration.
@@ -36,5 +32,4 @@ require 'meta_tags/content_tag'
36
32
  require 'meta_tags/text_normalizer'
37
33
  require 'meta_tags/view_helper'
38
34
 
39
- ActionView::Base.include MetaTags::ViewHelper
40
- ActionController::Base.include MetaTags::ControllerHelper
35
+ require 'meta_tags/railtie' if defined?(Rails)
data/meta-tags.gemspec CHANGED
@@ -12,21 +12,31 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.summary = "Collection of SEO helpers for Ruby on Rails."
14
14
  spec.description = "Search Engine Optimization (SEO) plugin for Ruby on Rails applications."
15
- spec.homepage = "http://github.com/kpumuk/meta-tags"
15
+ spec.homepage = "https://github.com/kpumuk/meta-tags"
16
16
  spec.license = "MIT"
17
17
  spec.platform = Gem::Platform::RUBY
18
+ spec.required_ruby_version = '>= 2.5.0'
18
19
 
19
20
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(\.|(bin|test|spec|features)/)}) }
20
21
  spec.bindir = "exe"
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.add_dependency "actionpack", ">= 3.2.0", "< 6.1"
25
+ spec.add_dependency "actionpack", ">= 3.2.0", "< 7.1"
25
26
 
26
- spec.add_development_dependency "rake", "~> 12.0"
27
- spec.add_development_dependency "rspec", "~> 3.8.0"
27
+ spec.add_development_dependency "railties", ">= 3.2.0", "< 7.1"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
+ spec.add_development_dependency "rspec", "~> 3.10.0"
28
30
  spec.add_development_dependency "rspec-html-matchers", "~> 0.9.1"
29
31
 
30
32
  spec.cert_chain = ["certs/kpumuk.pem"]
31
33
  spec.signing_key = File.expand_path("~/.ssh/gem-kpumuk.pem") if $PROGRAM_NAME.end_with?('gem')
34
+
35
+ spec.metadata = {
36
+ "bug_tracker_uri" => "https://github.com/kpumuk/meta-tags/issues/",
37
+ "changelog_uri" => "https://github.com/kpumuk/meta-tags/blob/main/CHANGELOG.md",
38
+ "documentation_uri" => "https://rubydoc.info/github/kpumuk/meta-tags/",
39
+ "homepage_uri" => "https://github.com/kpumuk/meta-tags/",
40
+ "source_code_uri" => "https://github.com/kpumuk/meta-tags/",
41
+ }
32
42
  end
@@ -0,0 +1,26 @@
1
+ class ::Hash[unchecked out K, unchecked out V]
2
+ def with_indifferent_access: () -> instance
3
+ def deep_merge!: (instance other) -> self
4
+ end
5
+
6
+ class ::Object
7
+ def presence: () -> String?
8
+ def blank?: () -> bool
9
+ def present?: () -> bool
10
+ end
11
+
12
+ interface _ActionControllerBase
13
+ def render: (*untyped args) { () -> untyped } -> untyped
14
+ end
15
+
16
+ interface _ActionViewBase
17
+ def tag: (String name, ?Hash[String | Symbol, untyped] options, ?bool open) -> void
18
+
19
+ def content_tag: (String name, String content, ?Hash[String | Symbol, untyped] options, ?bool open) -> void
20
+
21
+ def safe_join: (Array[String], String) -> String
22
+
23
+ def truncate: (String text, ?Hash[Symbol, untyped] options) -> String
24
+
25
+ def strip_tags: (String html) -> String
26
+ end
@@ -0,0 +1,19 @@
1
+ module MetaTags
2
+ class Configuration
3
+ attr_accessor title_limit: Integer?
4
+ attr_accessor truncate_site_title_first: bool
5
+ attr_accessor description_limit: Integer
6
+ attr_accessor keywords_limit: Integer
7
+ attr_accessor keywords_separator: String
8
+ attr_accessor keywords_lowercase: bool
9
+ attr_accessor open_meta_tags: bool
10
+ attr_accessor minify_output: bool
11
+ attr_reader property_tags: Array[String | Symbol]
12
+ attr_accessor skip_canonical_links_on_noindex: bool
13
+
14
+ def initialize: () -> void
15
+ def default_property_tags: () -> Array[String | Symbol]
16
+ def open_meta_tags?: () -> bool
17
+ def reset_defaults!: () -> void
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module MetaTags
2
+ class ContentTag < Tag
3
+ def render: (_ActionViewBase view) -> untyped
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module MetaTags
2
+ module ControllerHelper : _ActionControllerBase
3
+ @page_title: String?
4
+ @page_description: String?
5
+ @page_keywords: String? | Array[String]
6
+
7
+ def render: (*untyped args) { () -> untyped } -> untyped
8
+
9
+ def set_meta_tags: (ViewHelper::meta_tags | (_MetaTagish & Object) meta_tags) -> void
10
+
11
+ def meta_tags: () -> MetaTagsCollection
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module MetaTags
2
+ class MetaTagsCollection
3
+ attr_reader meta_tags: Hash[String | Symbol, untyped]
4
+
5
+ def initialize: () -> void
6
+
7
+ def []: (String | Symbol name) -> untyped
8
+
9
+ def []=: (String | Symbol name, untyped value) -> untyped
10
+
11
+ def update: (?::Hash[String | Symbol, untyped] | (_MetaTagish & Object) object) -> Hash[String | Symbol, untyped]
12
+
13
+ def with_defaults: (?::Hash[String | Symbol, untyped] defaults) { () -> untyped } -> untyped
14
+
15
+ def full_title: (?::Hash[String | Symbol, untyped] defaults) -> String
16
+
17
+ def page_title: (?::Hash[String | Symbol, untyped] defaults) -> String
18
+
19
+ def extract: (String | Symbol name) -> untyped
20
+
21
+ def delete: (*String | Symbol names) -> void
22
+
23
+ def extract_full_title: () -> String
24
+
25
+ def extract_title: () -> Array[String | (_Stringish & Object)]
26
+
27
+ def extract_separator: () -> String
28
+
29
+ def extract_robots: () -> Hash[String, String]
30
+
31
+ def normalize_open_graph: (Hash[String | Symbol, untyped] meta_tags) -> Hash[String | Symbol, untyped]
32
+
33
+ def extract_separator_section: (String | Symbol name, String default) -> String
34
+
35
+ def extract_robots_attribute: (String | Symbol name) -> [String | Array[String | Symbol], String?]
36
+
37
+ def calculate_robots_attributes: (untyped result, untyped attributes) -> untyped
38
+
39
+ def apply_robots_value: (untyped result, untyped name, untyped value, untyped processed) -> (nil | untyped)
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ module MetaTags
2
+ class Renderer
3
+ type meta_key = String | Symbol
4
+ type meta_value = Hash[meta_key, meta_value] | Array[meta_value] | meta_content
5
+ type meta_content = String? | Symbol | Integer | bool | (_Timish & Object) | (_Stringish & Object)
6
+
7
+ attr_reader meta_tags: MetaTagsCollection
8
+ attr_reader normalized_meta_tags: Hash[Symbol, meta_value]
9
+
10
+ def initialize: (MetaTagsCollection meta_tags) -> void
11
+
12
+ def render: (_ActionViewBase view) -> String
13
+
14
+ def render_charset: (Array[Tag] tags) -> void
15
+
16
+ def render_title: (Array[Tag] tags) -> void
17
+
18
+ def render_icon: (Array[Tag] tags) -> void
19
+
20
+ def render_with_normalization: (Array[Tag] tags, Symbol name) -> void
21
+
22
+ def render_noindex: (Array[Tag] tags) -> void
23
+
24
+ def render_refresh: (Array[Tag] tags) -> void
25
+
26
+ def render_alternate: (Array[Tag] tags) -> void
27
+
28
+ def render_open_search: (Array[Tag] tags) -> void
29
+
30
+ def render_links: (Array[Tag] tags) -> void
31
+
32
+ def render_canonical_link: (Array[Tag] tags) -> void
33
+
34
+ def render_hashes: (Array[Tag] tags, **untyped opts) -> void
35
+
36
+ def render_hash: (Array[Tag] tags, untyped key, **untyped opts) -> void
37
+
38
+ def render_custom: (Array[Tag] tags) -> void
39
+
40
+ def process_tree: (Array[Tag] tags, meta_key property, meta_value content, ?itemprop: meta_key? itemprop, **untyped opts) -> void
41
+
42
+ def process_hash: (Array[Tag] tags, meta_key property, Hash[meta_key, meta_value] content, **untyped opts) -> void
43
+
44
+ def process_array: (Array[Tag] tags, meta_key property, Array[meta_value] content, **untyped opts) -> void
45
+
46
+ def render_tag: (Array[Tag] tags, meta_key name, meta_content value, ?itemprop: meta_key? itemprop) -> void
47
+
48
+ def configured_name_key: (meta_key name) -> Symbol
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ module MetaTags
2
+ class Tag
3
+ attr_reader name: String
4
+ attr_reader attributes: Hash[String | Symbol, untyped]
5
+
6
+ def initialize: (String | Symbol name, ?Hash[String | Symbol, untyped] attributes) -> void
7
+
8
+ def render: (_ActionViewBase view) -> void
9
+
10
+ def prepare_attributes: (Hash[String | Symbol, untyped] attributes) -> Hash[String | Symbol, untyped]
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ module MetaTags
2
+ module TextNormalizer
3
+ extend ::MetaTags::TextNormalizer
4
+
5
+ type keyword = String? | (_Stringish & Object)
6
+ type keywords = keyword | Array[keywords]
7
+
8
+ def normalize_title: (String? site_title, keywords title, String separator, ?bool reverse) -> String
9
+
10
+ def normalize_description: (keyword description) -> String
11
+
12
+ def normalize_keywords: (keywords keywords) -> String
13
+
14
+ def helpers: () -> _ActionViewBase
15
+
16
+ def strip_tags: (String string) -> String
17
+
18
+ def safe_join: (Array[String] array, ?String sep) -> String
19
+
20
+ def cleanup_string: (keyword string, ?strip: bool strip) -> String
21
+
22
+ def cleanup_strings: (keywords? strings, ?strip: bool strip) -> Array[String]
23
+
24
+ def truncate: (String string, ?Integer limit, ?String natural_separator) -> String
25
+
26
+ def truncate_array: (Array[String] string_array, ?Integer? limit, ?String separator, ?String natural_separator) -> Array[String]
27
+
28
+ private
29
+
30
+ def calculate_limit_left: (Integer limit, Integer length, Array[String] result, String separator) -> untyped
31
+
32
+ def truncate_title: (String site_title, Array[String] title, String separator) -> ::Array[untyped]
33
+
34
+ def calculate_title_limits: (String site_title, Array[String] title, String separator, Integer global_limit) -> untyped
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ module MetaTags
2
+ # Gem version.
3
+ VERSION: ::String
4
+ end
@@ -0,0 +1,55 @@
1
+ module MetaTags
2
+ module ViewHelper : Module, _ActionViewBase
3
+ # type meta_tags = {
4
+ # site: String?,
5
+ # title: Array[String] | String?,
6
+ # description: String?,
7
+ # keywords: Array[String] | String?,
8
+ # charset: String,
9
+ # prefix: String,
10
+ # separator: String,
11
+ # suffix: String,
12
+ # lowercase: bool,
13
+ # reverse: bool,
14
+ # noindex: bool | String | Array[String],
15
+ # index: bool | String | Array[String],
16
+ # nofollow: bool | String | Array[String],
17
+ # follow: bool | String | Array[String],
18
+ # noarchive: bool | String | Array[String],
19
+ # canonical: String,
20
+ # prev: String,
21
+ # next: String,
22
+ # image_src: String,
23
+ # alternate: String,
24
+ # amphtml: String,
25
+ # manifest: String,
26
+ # og: Hash[Renderer::meta_key, Renderer::meta_value],
27
+ # twitter: Hash[Renderer::meta_key, Renderer::meta_value],
28
+ # open_search: Hash[Renderer::meta_key, Renderer::meta_value],
29
+ # article: Hash[Renderer::meta_key, Renderer::meta_value],
30
+ # al: Hash[Renderer::meta_key, Renderer::meta_value],
31
+ # refresh: Integer | String | nil,
32
+ # } & Hash[Renderer::meta_key, Renderer::meta_value]
33
+ type meta_tags = Hash[Renderer::meta_key, Renderer::meta_value]
34
+
35
+ def meta_tags: () -> MetaTagsCollection
36
+
37
+ def set_meta_tags: (?meta_tags | (_MetaTagish&Object) meta_tags) -> void
38
+
39
+ def title: (?String? title, ?::String? headline) -> String
40
+
41
+ def keywords: (Array[String] | String? keywords) -> (Array[String] | String?)
42
+
43
+ def description: (String? description) -> String?
44
+
45
+ def noindex: (?String | Array[String] | bool noindex) -> (String | bool | Array[String])
46
+
47
+ def nofollow: (?String | Array[String] | bool nofollow) -> (String | bool | Array[String])
48
+
49
+ def refresh: (String? | Integer? refresh) -> (String? | Integer?)
50
+
51
+ def display_meta_tags: (?meta_tags defaults) -> String
52
+
53
+ def display_title: (?meta_tags defaults) -> String
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ module MetaTags
2
+ def self.config: () -> Configuration
3
+ def self.configure: () { (Configuration) -> void } -> void
4
+
5
+ interface _Stringish
6
+ def to_str: () -> String
7
+ end
8
+
9
+ interface _Timish
10
+ def iso8601: () -> String
11
+ end
12
+
13
+ interface _MetaTagish
14
+ def to_meta_tags: () -> Hash[String | Symbol, untyped]
15
+ end
16
+ end
data.tar.gz.sig CHANGED
Binary file