page_meta 1.3.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 732b10b45a16c54c1d95e8f20440bc52cbac065e378e1eed2284c6d99c2f9d47
4
- data.tar.gz: 0266ece7ba5fbd03f8e0c9f4b77ff3097192ef8999292342680149b77cd8577c
3
+ metadata.gz: f948175f35af9b5f92902225e895d0e7c7fe664afd54f3ca8d6d82fc77c9b2c5
4
+ data.tar.gz: 6034bbcff7b2079c8f234e447ffc8804bfda09989874a66952bc467765cc7b1c
5
5
  SHA512:
6
- metadata.gz: a9eef3c915a3d762e53aef9d75ab95c11ccd76d5a2385d07f7159c69cae9e48488295100d36e349369c65cb4e8e255a7d8078c058cd40cbdc5bc0c704de07c05
7
- data.tar.gz: a4e04ac623c1e2963b23c747008d7d2e84fac6d4bfda74bf7b516258a2b71e5032e215fce03c89d57f68532e1e336e5239dae9f432b233e4f800ed05ddd1bffe
6
+ metadata.gz: '06529e97cbaf313bd71be194e578cc8ce3f3c1f8d3b646fa1b71adf10bb81f7c3f31584683f29c64f158dd7ee6e4e196ac5a5e6cb548372911cc278e8a9d1d2a'
7
+ data.tar.gz: e9d86f55d916c7b2d4b4cd2bd9d8161caf089733df76811a3e735cee1b5f1a0c777406fde3599879e0a04774b88274853ee5c598200481a2782f3e7fbda07b50
@@ -19,12 +19,11 @@ jobs:
19
19
  strategy:
20
20
  fail-fast: false
21
21
  matrix:
22
- ruby: ["3.1", "3.2", "3.3"]
22
+ ruby: ["3.2", "3.3", "3.4"]
23
23
  gemfile:
24
24
  - Gemfile
25
+ - gemfiles/7_2.gemfile
25
26
  - gemfiles/7_1.gemfile
26
- - gemfiles/7_0.gemfile
27
- - gemfiles/6_1.gemfile
28
27
 
29
28
  steps:
30
29
  - uses: actions/checkout@v4
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 3.1
6
+ TargetRubyVersion: 3.2
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - test/support/dummy.rb
data/CHANGELOG.md CHANGED
@@ -11,10 +11,22 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## 2.0.1
15
+
16
+ - [Removed] Support for old format.
17
+ - [Added] Support for custom base scope targeting controller or controller +
18
+ action.
19
+
20
+ ## 2.0.0
21
+
22
+ - [Added] Add support for placeholders in base title.
23
+ - [Changed] Set minimum ruby version to 3.2.
24
+ - [Added] Add method to delete items by their name.
25
+
14
26
  ## 1.3.0
15
27
 
16
28
  - [Added] `page_meta.base` will now set the base url.
17
- - [Changed] Some tags will be enforced to show up first. It loosely follows
29
+ - [Changed] Some tags will be enforced to show up first. It loosely follows
18
30
  https://rviscomi.github.io/capo.js/user/rules/.
19
31
 
20
32
  ## 1.2.0
data/README.md CHANGED
@@ -231,6 +231,15 @@ would do.
231
231
  [Please read Rails docs](http://guides.rubyonrails.org/i18n.html#using-safe-html-translations)
232
232
  for more info.
233
233
 
234
+ ### Removing meta tags
235
+
236
+ You can use `PageMeta::Base#delete` to remove meta tags. All matching tags will
237
+ be removed.
238
+
239
+ ```ruby
240
+ page_meta.delete(:description)
241
+ ```
242
+
234
243
  ## Maintainer
235
244
 
236
245
  - [Nando Vieira](https://github.com/fnando)
@@ -3,4 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec path: ".."
5
5
 
6
- gem "rails", "~> 6.1.0"
6
+ gem "rails", "~> 7.2.0"
@@ -54,6 +54,11 @@ module PageMeta
54
54
  }
55
55
  end
56
56
 
57
+ # Delete all matching meta tags by name.
58
+ def delete(name)
59
+ items.delete_if { _1[:name] == name }
60
+ end
61
+
57
62
  # Add a new meta tag.
58
63
  def tag(name, value = nil, order: nil, **kwargs)
59
64
  order = order || META_TAG_ORDER[name] || DEFAULT_ORDER
@@ -73,13 +78,13 @@ module PageMeta
73
78
 
74
79
  # The title translation.
75
80
  def title
76
- @title ||= Translator.new(:titles, naming, store)
81
+ @title ||= Translator.new(:title, naming, store)
77
82
  end
78
83
 
79
84
  # The description translation.
80
85
  def description(html: false)
81
86
  @description[html] ||= Translator.new(
82
- :descriptions,
87
+ :description,
83
88
  naming,
84
89
  store.merge(html:)
85
90
  )
@@ -130,6 +135,7 @@ module PageMeta
130
135
  end
131
136
 
132
137
  private def compute_default_title
138
+ return if has?(:title)
133
139
  return if title.to_s.blank?
134
140
 
135
141
  html(:title, title.to_s, order: 3)
@@ -137,21 +143,31 @@ module PageMeta
137
143
  end
138
144
 
139
145
  private def compute_default_charset
146
+ return if has?(:charset)
147
+
140
148
  tag(:charset, Rails.configuration.encoding, order: 0)
141
149
  end
142
150
 
143
151
  private def compute_default_keywords
152
+ return if has?(:keywords)
153
+
144
154
  tag(:keywords, keywords.to_s) unless keywords.to_s.blank?
145
155
  end
146
156
 
147
157
  private def compute_default_description
158
+ return if has?(:description)
159
+
148
160
  tag(:description, description.to_s) unless description.to_s.blank?
149
161
  end
150
162
 
151
163
  private def compute_default_viewport
152
- return if items.any? { _1[:name] == :viewport && _1[:type] == :tag }
164
+ return if has?(:viewport)
153
165
 
154
166
  tag(:viewport, "width=device-width,initial-scale=1", order: 1)
155
167
  end
168
+
169
+ private def has?(name)
170
+ items.any? { _1[:name] == name }
171
+ end
156
172
  end
157
173
  end
@@ -13,33 +13,41 @@ module PageMeta
13
13
  @options = options
14
14
  end
15
15
 
16
- def singular_scope
17
- @singular_scope ||= if scope == :keywords
18
- "keywords"
19
- else
20
- scope.to_s.singularize
21
- end
22
- end
23
-
24
16
  def to_s
25
17
  return "" if simple.blank?
26
18
 
19
+ value = simple
20
+
27
21
  [
28
- t("page_meta.#{scope}.base", value: simple, default: ""),
29
- t("page_meta.#{singular_scope}_base", value: simple, default: simple)
22
+ # Set base scope for controller
23
+ t(
24
+ "page_meta.#{naming.controller}.#{scope}_base",
25
+ value:,
26
+ **override_options
27
+ ),
28
+
29
+ # Set base scope for action
30
+ t(
31
+ "page_meta.#{naming.controller}.#{naming.action}.#{scope}_base",
32
+ value:,
33
+ **override_options
34
+ ),
35
+
36
+ # Set base scope
37
+ t("page_meta.#{scope}_base", value:, **override_options,
38
+ default: value)
30
39
  ].reject(&:blank?).first || ""
31
40
  end
32
41
 
33
42
  def translation_scope
34
- [
35
- "page_meta.#{scope}.#{naming.controller}.#{naming.action}",
36
- "page_meta.#{naming.controller}.#{naming.action}.#{singular_scope}"
37
- ]
43
+ ["page_meta.#{naming.controller}.#{naming.action}.#{scope}"]
38
44
  end
39
45
 
40
- def simple
41
- override_options = options.merge(default: "")
46
+ def override_options
47
+ options.merge(default: "")
48
+ end
42
49
 
50
+ def simple
43
51
  translation = ""
44
52
 
45
53
  translation_scope.each do |scope|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PageMeta
4
- VERSION = "1.3.0"
4
+ VERSION = "2.0.1"
5
5
  end
data/page_meta.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = PageMeta::VERSION
8
8
  spec.authors = ["Nando Vieira"]
9
9
  spec.email = ["me@fnando.com"]
10
- spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
11
11
  spec.metadata = {
12
12
  "rubygems_mfa_required" => "true"
13
13
  }
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_development_dependency "bundler"
31
31
  spec.add_development_dependency "minitest-utils"
32
- spec.add_development_dependency "pry-meta"
33
32
  spec.add_development_dependency "rake"
34
33
  spec.add_development_dependency "rubocop"
35
34
  spec.add_development_dependency "rubocop-fnando"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-05-17 00:00:00.000000000 Z
10
+ date: 2024-12-29 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -52,20 +51,6 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: pry-meta
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
54
  - !ruby/object:Gem::Dependency
70
55
  name: rake
71
56
  requirement: !ruby/object:Gem::Requirement
@@ -148,9 +133,8 @@ files:
148
133
  - Rakefile
149
134
  - bin/console
150
135
  - bin/setup
151
- - gemfiles/6_1.gemfile
152
- - gemfiles/7_0.gemfile
153
136
  - gemfiles/7_1.gemfile
137
+ - gemfiles/7_2.gemfile
154
138
  - lib/page_meta.rb
155
139
  - lib/page_meta/action.rb
156
140
  - lib/page_meta/base.rb
@@ -176,7 +160,6 @@ licenses:
176
160
  - MIT
177
161
  metadata:
178
162
  rubygems_mfa_required: 'true'
179
- post_install_message:
180
163
  rdoc_options: []
181
164
  require_paths:
182
165
  - lib
@@ -184,15 +167,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
167
  requirements:
185
168
  - - ">="
186
169
  - !ruby/object:Gem::Version
187
- version: 3.1.0
170
+ version: 3.2.0
188
171
  required_rubygems_version: !ruby/object:Gem::Requirement
189
172
  requirements:
190
173
  - - ">="
191
174
  - !ruby/object:Gem::Version
192
175
  version: '0'
193
176
  requirements: []
194
- rubygems_version: 3.5.9
195
- signing_key:
177
+ rubygems_version: 3.6.2
196
178
  specification_version: 4
197
179
  summary: Easily define <meta> and <link> tags. I18n support for descriptions, keywords
198
180
  and titles.
data/gemfiles/7_0.gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
- gemspec path: ".."
5
-
6
- gem "rails", "~> 7.0.0"