page_meta 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89a7406728480d6a3eb785869d6cae90f32b3bfe2fd3e0f8a6a6ced5c03da4b3
4
- data.tar.gz: e5db2e7b705299c0f736164fa5352242e2211a1c6bed9d12802263643cec2930
3
+ metadata.gz: 6325d31942f9536c2a062706f746f49693cce7328d1c362009e822e80fa89a98
4
+ data.tar.gz: 942c213fc64a1324345f6ec08eb09c6ca40aabb1331d6960f6e4fa4261a10a80
5
5
  SHA512:
6
- metadata.gz: e3961943c7d5506baaa3ce0f28d06819dc430aa3c3f38e503324cb52277c1aa2163ef224e4be4f2cfd41fa2e322cc087e0fd6d3680674ccd036e3d9bb6a34c61
7
- data.tar.gz: bf19f1d84e6fdcb8ad48b8d44a898d3682316680459c34d661f5844797912fa21f704cde143d6d079ac8d32895be2182c29f58d068df3fa2795e314beab5f11c
6
+ metadata.gz: a7fd41a5e0f3639a91f70afd26936ad740ecdcabdceb604b4fb5750f973f3879a76dbe3326d6124c0e786cb09936c8a29cb95245c1c9c161132d7b54a2914144
7
+ data.tar.gz: d7612bd88688c8ec272e3b2931e6b9d998458f0ef659a3f8697afd8ab0c380d0a2fe8269c8cea1fafafcb2df67c7e8e57e15e79c82a5a3f8a030b820131707bf
@@ -19,17 +19,17 @@ jobs:
19
19
  strategy:
20
20
  fail-fast: false
21
21
  matrix:
22
- ruby: ["2.7", "3.0", "3.1"]
22
+ ruby: ["3.1", "3.2", "3.3"]
23
23
  gemfile:
24
24
  - Gemfile
25
+ - gemfiles/7_1.gemfile
25
26
  - gemfiles/7_0.gemfile
26
27
  - gemfiles/6_1.gemfile
27
- - gemfiles/6_0.gemfile
28
28
 
29
29
  steps:
30
- - uses: actions/checkout@v3
30
+ - uses: actions/checkout@v4
31
31
 
32
- - uses: actions/cache@v3
32
+ - uses: actions/cache@v4
33
33
  with:
34
34
  path: vendor/bundle
35
35
  key: >
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.1
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - test/support/dummy.rb
data/CHANGELOG.md CHANGED
@@ -11,6 +11,12 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## 1.2.0
15
+
16
+ - [Added] The meta tag's content can also be any object that responds to the
17
+ method `call`, like procs.
18
+ - [Fixed] Fixed case where meta tags were being rendered with blank content.
19
+
14
20
  ## 1.1.0
15
21
 
16
22
  - [Added] `<meta name="viewport" content="width=device-width,initial-scale=1">`
data/README.md CHANGED
@@ -46,8 +46,8 @@ en:
46
46
  title: "Welcome to MyApp"
47
47
  ```
48
48
 
49
- Previously, you could also use the `page_meta.{titles,description,keywords}` scopes, but this is now
50
- deprecated in favor of the above.
49
+ Previously, you could also use the `page_meta.{titles,description,keywords}`
50
+ scopes, but this is now deprecated in favor of the above.
51
51
 
52
52
  ```yaml
53
53
  ---
@@ -127,6 +127,11 @@ class Workshops Controller < ApplicationController
127
127
  end
128
128
  ```
129
129
 
130
+ > [!TIP]
131
+ >
132
+ > The meta tag's content can also be any object that responds to the method
133
+ > `call`. This way you can lazy evaluate the content.
134
+
130
135
  You can define default meta/link tags in a `before_action`:
131
136
 
132
137
  ```ruby
@@ -3,4 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec path: ".."
5
5
 
6
- gem "rails", "~> 6.0.0"
6
+ gem "rails", "~> 7.1.0"
@@ -34,7 +34,7 @@ module PageMeta
34
34
  end
35
35
 
36
36
  def link(rel, options)
37
- links << {rel: rel, options: options}
37
+ links << {rel:, options:}
38
38
  end
39
39
 
40
40
  def title
@@ -42,7 +42,7 @@ module PageMeta
42
42
  end
43
43
 
44
44
  def description(html: false)
45
- @description[html] ||= Translator.new(:descriptions, naming, store.merge(html: html))
45
+ @description[html] ||= Translator.new(:descriptions, naming, store.merge(html:))
46
46
  end
47
47
 
48
48
  def keywords
@@ -75,7 +75,7 @@ module PageMeta
75
75
 
76
76
  def compute_default_meta_tags
77
77
  DEFAULT_META_TAGS.each do |method_name|
78
- public_send("compute_default_#{method_name}")
78
+ public_send(:"compute_default_#{method_name}")
79
79
  end
80
80
  end
81
81
 
@@ -84,7 +84,7 @@ module PageMeta
84
84
  end
85
85
 
86
86
  def compute_default_title
87
- tag(:title, title) unless title.to_s.empty?
87
+ tag(:title, title) unless title.to_s.blank?
88
88
  end
89
89
 
90
90
  def compute_default_charset
@@ -92,11 +92,11 @@ module PageMeta
92
92
  end
93
93
 
94
94
  def compute_default_keywords
95
- tag(:keywords, keywords.to_s) unless keywords.to_s.empty?
95
+ tag(:keywords, keywords.to_s) unless keywords.to_s.blank?
96
96
  end
97
97
 
98
98
  def compute_default_description
99
- tag(:description, description.to_s) unless description.to_s.empty?
99
+ tag(:description, description.to_s) unless description.to_s.blank?
100
100
  end
101
101
 
102
102
  def compute_default_viewport
@@ -6,10 +6,18 @@ module PageMeta
6
6
  return if content.empty?
7
7
 
8
8
  content.each_with_object([]) do |(attr, value), buffer|
9
+ value = value.call if value.respond_to?(:call)
10
+ value = value.to_s
11
+
9
12
  next if value.blank?
10
13
 
11
14
  attr = attr.to_s.tr("_", ":")
12
- buffer << helpers.tag(:meta, property: "#{base_name}:#{attr}", content: value)
15
+
16
+ buffer << helpers.tag(
17
+ :meta,
18
+ property: "#{base_name}:#{attr}",
19
+ content: value
20
+ )
13
21
  end.join
14
22
  end
15
23
  end
@@ -20,7 +20,7 @@ module PageMeta
20
20
  end
21
21
 
22
22
  def render
23
- helpers.tag(:link, options.merge(rel: rel)) unless options.empty?
23
+ helpers.tag(:link, options.merge(rel:)) unless options.empty?
24
24
  end
25
25
 
26
26
  def helpers
@@ -4,8 +4,8 @@ module PageMeta
4
4
  class MetaTag
5
5
  class Language < MetaTag
6
6
  def render
7
- helpers.tag(:meta, name: name, content: content) +
8
- helpers.tag(:meta, itemprop: name, content: content)
7
+ helpers.tag(:meta, name:, content:) +
8
+ helpers.tag(:meta, itemprop: name, content:)
9
9
  end
10
10
  end
11
11
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module PageMeta
4
4
  class MetaTag
5
- attr_reader :name, :content
5
+ attr_reader :name
6
6
 
7
7
  def self.build(name, content)
8
8
  klass_name = "::PageMeta::MetaTag::#{name.to_s.camelize}"
@@ -16,11 +16,16 @@ module PageMeta
16
16
 
17
17
  def initialize(name, content)
18
18
  @name = name.to_s.dasherize
19
- @content = content
19
+ @raw_content = content
20
+ end
21
+
22
+ def content
23
+ @content ||=
24
+ @raw_content.respond_to?(:call) ? @raw_content.call : @raw_content
20
25
  end
21
26
 
22
27
  def render
23
- helpers.tag(:meta, name: name, content: content) unless content.empty?
28
+ helpers.tag(:meta, name:, content:) unless content.blank?
24
29
  end
25
30
 
26
31
  def helpers
@@ -29,18 +34,18 @@ module PageMeta
29
34
 
30
35
  class MultipleMetaTag < MetaTag
31
36
  def render
32
- return if content.empty?
37
+ return if content.blank?
33
38
 
34
- helpers.tag(:meta, name: name, content: content) +
35
- helpers.tag(:meta, itemprop: name, content: content)
39
+ helpers.tag(:meta, name:, content:) +
40
+ helpers.tag(:meta, itemprop: name, content:)
36
41
  end
37
42
  end
38
43
 
39
44
  class HttpEquiv < MetaTag
40
45
  def render
41
- return if content.empty?
46
+ return if content.blank?
42
47
 
43
- helpers.tag(:meta, "http-equiv" => name, content: content)
48
+ helpers.tag(:meta, "http-equiv" => name, content:)
44
49
  end
45
50
  end
46
51
 
@@ -18,7 +18,7 @@ module PageMeta
18
18
  .class
19
19
  .name
20
20
  .underscore
21
- .gsub(/_controller/, "")
21
+ .gsub("_controller", "")
22
22
  .tr("/", ".")
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PageMeta
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
data/page_meta.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "page_meta"
7
7
  spec.version = PageMeta::VERSION
8
8
  spec.authors = ["Nando Vieira"]
9
- spec.email = ["fnando.vieira@gmail.com"]
10
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
9
+ spec.email = ["me@fnando.com"]
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
11
11
  spec.metadata = {
12
12
  "rubygems_mfa_required" => "true"
13
13
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-30 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -125,7 +125,7 @@ dependencies:
125
125
  description: Easily define <meta> and <link> tags. I18n support for descriptions,
126
126
  keywords and titles.
127
127
  email:
128
- - fnando.vieira@gmail.com
128
+ - me@fnando.com
129
129
  executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
@@ -148,9 +148,9 @@ files:
148
148
  - Rakefile
149
149
  - bin/console
150
150
  - bin/setup
151
- - gemfiles/6_0.gemfile
152
151
  - gemfiles/6_1.gemfile
153
152
  - gemfiles/7_0.gemfile
153
+ - gemfiles/7_1.gemfile
154
154
  - lib/page_meta.rb
155
155
  - lib/page_meta/action.rb
156
156
  - lib/page_meta/base.rb
@@ -182,14 +182,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
182
  requirements:
183
183
  - - ">="
184
184
  - !ruby/object:Gem::Version
185
- version: 2.7.0
185
+ version: 3.1.0
186
186
  required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  requirements:
188
188
  - - ">="
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubygems_version: 3.4.5
192
+ rubygems_version: 3.5.9
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Easily define <meta> and <link> tags. I18n support for descriptions, keywords