page_meta 1.0.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: 0727fb1af7a2848d3cd1e6f2d44efd3c106c44588cd604d9738c0d1b90bdb67d
4
- data.tar.gz: fd339b23e757843cab438e5078d17253bcbaca18bf4351082706a2ec81da065d
3
+ metadata.gz: 6325d31942f9536c2a062706f746f49693cce7328d1c362009e822e80fa89a98
4
+ data.tar.gz: 942c213fc64a1324345f6ec08eb09c6ca40aabb1331d6960f6e4fa4261a10a80
5
5
  SHA512:
6
- metadata.gz: 790616651e1425832a679050c2d6c9b1805d4236f88fedcf3b622a0176cf7020be0f78672094b1660417c06c8283dc123a143ae1f666393f0afc4bcee26013d7
7
- data.tar.gz: 0c6981527e16056706a51088ad995a70167e8e55c47bd86c7c1613a394aea0835f4b047f642186a883c98c78f903dff905b7e804b63067a4bd838d4416509105
6
+ metadata.gz: a7fd41a5e0f3639a91f70afd26936ad740ecdcabdceb604b4fb5750f973f3879a76dbe3326d6124c0e786cb09936c8a29cb95245c1c9c161132d7b54a2914144
7
+ data.tar.gz: d7612bd88688c8ec272e3b2931e6b9d998458f0ef659a3f8697afd8ab0c380d0a2fe8269c8cea1fafafcb2df67c7e8e57e15e79c82a5a3f8a030b820131707bf
@@ -2,44 +2,42 @@
2
2
  name: ruby-tests
3
3
 
4
4
  on:
5
- pull_request:
6
- branches:
7
- - main
5
+ pull_request_target:
8
6
  push:
9
7
  branches:
10
8
  - main
11
-
12
- schedule:
13
- - cron: "0 10 * * *"
9
+ workflow_dispatch:
10
+ inputs: {}
14
11
 
15
12
  jobs:
16
13
  build:
17
14
  name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
18
15
  runs-on: "ubuntu-latest"
16
+ if: |
17
+ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
18
+ github.actor != 'dependabot[bot]'
19
19
  strategy:
20
20
  fail-fast: false
21
21
  matrix:
22
- ruby: [2.7.x, 3.0.x]
22
+ ruby: ["3.1", "3.2", "3.3"]
23
23
  gemfile:
24
24
  - Gemfile
25
- - gemfiles/6.1.gemfile
26
- - gemfiles/6.0.gemfile
25
+ - gemfiles/7_1.gemfile
26
+ - gemfiles/7_0.gemfile
27
+ - gemfiles/6_1.gemfile
27
28
 
28
29
  steps:
29
- - uses: actions/checkout@v1
30
+ - uses: actions/checkout@v4
30
31
 
31
- - uses: actions/cache@v2
32
+ - uses: actions/cache@v4
32
33
  with:
33
34
  path: vendor/bundle
34
35
  key: >
35
36
  ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
36
37
  hashFiles(matrix.gemfile) }}
37
- restore-keys: >
38
- ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
39
- hashFiles(matrix.gemfile) }}
40
38
 
41
39
  - name: Set up Ruby
42
- uses: actions/setup-ruby@v1
40
+ uses: ruby/setup-ruby@v1
43
41
  with:
44
42
  ruby-version: ${{ matrix.ruby }}
45
43
 
@@ -53,9 +51,6 @@ jobs:
53
51
 
54
52
  - name: Run Tests
55
53
  env:
56
- PGHOST: localhost
57
- PGUSER: postgres
58
54
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
59
55
  run: |
60
56
  bundle exec rake
61
- bundle exec rubocop
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /log
11
+ /bin/*
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
@@ -16,3 +16,9 @@ Layout/LineLength:
16
16
 
17
17
  Metrics:
18
18
  Enabled: false
19
+
20
+ Minitest/MultipleAssertions:
21
+ Enabled: false
22
+
23
+ Gemspec/DevelopmentDependencies:
24
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -11,6 +11,19 @@ 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
+
20
+ ## 1.1.0
21
+
22
+ - [Added] `<meta name="viewport" content="width=device-width,initial-scale=1">`
23
+ is now added by default.
24
+ - [Changed] You can now group all translations under
25
+ `page_meta.controller.action.{title,description,keywords}`.
26
+
14
27
  ## 1.0.0
15
28
 
16
29
  - Initial release.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # page_meta
2
2
 
3
3
  [![Tests](https://github.com/fnando/page_meta/workflows/ruby-tests/badge.svg)](https://github.com/fnando/page_meta)
4
- [![Code Climate](https://codeclimate.com/github/fnando/page_meta/badges/gpa.svg)](https://codeclimate.com/github/fnando/page_meta)
5
4
  [![Gem](https://img.shields.io/gem/v/page_meta.svg)](https://rubygems.org/gems/page_meta)
6
5
  [![Gem](https://img.shields.io/gem/dt/page_meta.svg)](https://rubygems.org/gems/page_meta)
7
6
 
@@ -23,13 +22,14 @@ gem "page_meta"
23
22
  ## Usage
24
23
 
25
24
  Your controller and views have an object called `page_meta`. You can use it to
26
- define meta tags and links. By default, it will include the encoding and
27
- language meta tags.
25
+ define meta tags and links. By default, it will include the encoding, language
26
+ and viewport meta tags.
28
27
 
29
28
  ```html
30
29
  <meta charset="utf-8" />
31
30
  <meta name="language" content="en" />
32
31
  <meta itemprop="language" content="en" />
32
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
33
33
  ```
34
34
 
35
35
  You can use I18n to define titles, descriptions and keywords. These values will
@@ -37,15 +37,29 @@ be inferred from the controller and action names. For an action
37
37
  `SiteController#index` you'll need the following translation scope:
38
38
 
39
39
  ```yaml
40
- ---
41
- page_meta:
42
- titles:
43
- base: "%{value} • MyApp"
40
+ en:
41
+ page_meta:
42
+ title_base: "%{value} • MyApp"
43
+
44
44
  site:
45
- index: "Welcome to MyApp"
45
+ index:
46
+ title: "Welcome to MyApp"
47
+ ```
48
+
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
+
52
+ ```yaml
53
+ ---
54
+ en:
55
+ page_meta:
56
+ titles:
57
+ base: "%{value} • MyApp"
58
+ site:
59
+ index: "Welcome to MyApp"
46
60
  ```
47
61
 
48
- The title can without the `base` context can be accessed through
62
+ The title without the `base` context can be accessed through
49
63
  `page_meta.title.simple`.
50
64
 
51
65
  ```erb
@@ -60,10 +74,11 @@ I18n placeholders.
60
74
  ---
61
75
  en:
62
76
  page_meta:
63
- titles:
64
- base: "%{title} • MyCompany"
65
- workshops:
66
- show: "%{name}"
77
+ title_base: "%{title} • MyCompany"
78
+
79
+ workshops:
80
+ show:
81
+ title: "%{name}"
67
82
  ```
68
83
 
69
84
  You can then set dynamic values using the `PageMeta::Base#[]=`.
@@ -89,13 +104,12 @@ The same concept is applied to descriptions and keywords.
89
104
  ---
90
105
  en:
91
106
  page_meta:
92
- descriptions:
93
- site:
94
- home: MyApp is the best way of doing something.
95
-
96
- keywords:
97
- site:
98
- home: "myapp, thing, other thing"
107
+ base_title: "%{value} • MyApp"
108
+ site:
109
+ show:
110
+ title: "Show"
111
+ description: MyApp is the best way of doing something.
112
+ keywords: "myapp, thing, other thing"
99
113
  ```
100
114
 
101
115
  ### Defining meta tags
@@ -113,6 +127,11 @@ class Workshops Controller < ApplicationController
113
127
  end
114
128
  ```
115
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
+
116
135
  You can define default meta/link tags in a `before_action`:
117
136
 
118
137
  ```ruby
@@ -3,4 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec path: ".."
5
5
 
6
- gem "rails", "~> 6.0"
6
+ gem "rails", "~> 6.1.0"
@@ -3,4 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec path: ".."
5
5
 
6
- gem "rails", "~> 6.1"
6
+ gem "rails", "~> 7.0.0"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 7.1.0"
@@ -2,7 +2,14 @@
2
2
 
3
3
  module PageMeta
4
4
  class Base
5
- DEFAULT_META_TAGS = %i[language charset title keywords description].freeze
5
+ DEFAULT_META_TAGS = %i[
6
+ language
7
+ charset
8
+ title
9
+ keywords
10
+ description
11
+ viewport
12
+ ].freeze
6
13
 
7
14
  attr_reader :controller, :store
8
15
 
@@ -27,7 +34,7 @@ module PageMeta
27
34
  end
28
35
 
29
36
  def link(rel, options)
30
- links << {rel: rel, options: options}
37
+ links << {rel:, options:}
31
38
  end
32
39
 
33
40
  def title
@@ -35,7 +42,7 @@ module PageMeta
35
42
  end
36
43
 
37
44
  def description(html: false)
38
- @description[html] ||= Translator.new(:descriptions, naming, store.merge(html: html))
45
+ @description[html] ||= Translator.new(:descriptions, naming, store.merge(html:))
39
46
  end
40
47
 
41
48
  def keywords
@@ -68,7 +75,7 @@ module PageMeta
68
75
 
69
76
  def compute_default_meta_tags
70
77
  DEFAULT_META_TAGS.each do |method_name|
71
- public_send("compute_default_#{method_name}")
78
+ public_send(:"compute_default_#{method_name}")
72
79
  end
73
80
  end
74
81
 
@@ -77,7 +84,7 @@ module PageMeta
77
84
  end
78
85
 
79
86
  def compute_default_title
80
- tag(:title, title) unless title.to_s.empty?
87
+ tag(:title, title) unless title.to_s.blank?
81
88
  end
82
89
 
83
90
  def compute_default_charset
@@ -85,11 +92,15 @@ module PageMeta
85
92
  end
86
93
 
87
94
  def compute_default_keywords
88
- tag(:keywords, keywords.to_s) unless keywords.to_s.empty?
95
+ tag(:keywords, keywords.to_s) unless keywords.to_s.blank?
89
96
  end
90
97
 
91
98
  def compute_default_description
92
- tag(:description, description.to_s) unless description.to_s.empty?
99
+ tag(:description, description.to_s) unless description.to_s.blank?
100
+ end
101
+
102
+ def compute_default_viewport
103
+ tag(:viewport, "width=device-width,initial-scale=1") unless meta_tags[:viewport]
93
104
  end
94
105
  end
95
106
  end
@@ -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
@@ -13,21 +13,38 @@ module PageMeta
13
13
  @options = options
14
14
  end
15
15
 
16
+ def singular_scope
17
+ @singular_scope ||= scope == :keywords ? "keywords" : scope.to_s.singularize
18
+ end
19
+
16
20
  def to_s
17
21
  return "" if simple.blank?
18
22
 
19
- t("page_meta.#{scope}.base", value: simple, default: simple)
23
+ [
24
+ t("page_meta.#{scope}.base", value: simple, default: ""),
25
+ t("page_meta.#{singular_scope}_base", value: simple, default: simple)
26
+ ].reject(&:blank?).first || ""
20
27
  end
21
28
 
22
29
  def translation_scope
23
- "page_meta.#{scope}.#{naming.controller}.#{naming.action}"
30
+ [
31
+ "page_meta.#{scope}.#{naming.controller}.#{naming.action}",
32
+ "page_meta.#{naming.controller}.#{naming.action}.#{singular_scope}"
33
+ ]
24
34
  end
25
35
 
26
36
  def simple
27
37
  override_options = options.merge(default: "")
28
38
 
29
- translation = t("#{translation_scope}_html", **override_options) if html
30
- translation = t(translation_scope, **override_options) if translation.blank?
39
+ translation = ""
40
+
41
+ translation_scope.each do |scope|
42
+ translation = t("#{scope}_html", **override_options) if html
43
+ translation = t(scope, **override_options) if translation.blank?
44
+
45
+ break if translation.present?
46
+ end
47
+
31
48
  translation
32
49
  end
33
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PageMeta
4
- VERSION = "1.0.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.0.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: 2021-11-25 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: []
@@ -139,7 +139,6 @@ files:
139
139
  - ".github/workflows/ruby-tests.yml"
140
140
  - ".gitignore"
141
141
  - ".rubocop.yml"
142
- - ".travis.yml"
143
142
  - CHANGELOG.md
144
143
  - CODE_OF_CONDUCT.md
145
144
  - CONTRIBUTING.md
@@ -149,8 +148,9 @@ files:
149
148
  - Rakefile
150
149
  - bin/console
151
150
  - bin/setup
152
- - gemfiles/6.0.gemfile
153
- - gemfiles/6.1.gemfile
151
+ - gemfiles/6_1.gemfile
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.2.32
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
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
- rvm:
5
- - 2.7.1
6
- - 2.6.5
7
- before_install: gem install bundler --pre
8
- before_script:
9
- - "curl -L
10
- https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
11
- > ./cc-test-reporter"
12
- - chmod +x ./cc-test-reporter
13
- - "./cc-test-reporter before-build"
14
- after_script:
15
- - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
16
- notifications:
17
- email: false
18
- env:
19
- global:
20
- secure: pN+1uDJEgbIfpvSmk9owADeqXcQAXzMYMkM6XHR3IgfjbRZ39sBL11EkYziF90boEJPoMkVYmwYuTfGePPN7uWxkDBQJXTEaAXGeuAlQc1Fhzsj0WQZlOcQn1JHYmLtzBVe/B8J4z5ZuQMDFTMe+f2i1qIk00P/R1ozcbz9+g3Pi/5Esf7+6NY2rxQYeEw21/D7WM4UGAOJ+uX6rHdEUo/ej18bUZC8GBxZZy6jVeVqbBE8PPdzNcLkkUu+soPbZVBZiVF2bXn+N3AqXQqA4oL4t7zorG7xU4+2mUldbHRr3HaJBPSwnWzw6mjnSEq6OO77nTOrpwdrkb/Qz/slgL5cuqjlO0MRNq6THdBZT29vCqErxAFs9w4AUoFgwkzMe1mR8ZB8QuUct3xFpAMtE2q35efCuHFb5h682Ske8v0COnzsIRjN1NgSX3nx1oKIh7V9c9O84oDx+W/h0oL2RH/OjW4DcLaVBDS5MhaMZ1ySuBktmqDJD2OqsfbO4Gn+LrWbQAM2RFp2TTROyfDJJU3ITgE7DMqn0QiOcZIoCWzastamGJJs99WzmliouO87ZDSG5Kct2JXml0syyY/jBuR5nnJ9x6TyJpDD9jNMz6LOW9LZ31aOttGbAOQbYVgUgtPkITEuo8xhLCBc6ae+GVA4t8NcJx/rAn1U9E/CXiPs=