page_meta 1.0.0 → 1.1.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: 89a7406728480d6a3eb785869d6cae90f32b3bfe2fd3e0f8a6a6ced5c03da4b3
4
+ data.tar.gz: e5db2e7b705299c0f736164fa5352242e2211a1c6bed9d12802263643cec2930
5
5
  SHA512:
6
- metadata.gz: 790616651e1425832a679050c2d6c9b1805d4236f88fedcf3b622a0176cf7020be0f78672094b1660417c06c8283dc123a143ae1f666393f0afc4bcee26013d7
7
- data.tar.gz: 0c6981527e16056706a51088ad995a70167e8e55c47bd86c7c1613a394aea0835f4b047f642186a883c98c78f903dff905b7e804b63067a4bd838d4416509105
6
+ metadata.gz: e3961943c7d5506baaa3ce0f28d06819dc430aa3c3f38e503324cb52277c1aa2163ef224e4be4f2cfd41fa2e322cc087e0fd6d3680674ccd036e3d9bb6a34c61
7
+ data.tar.gz: bf19f1d84e6fdcb8ad48b8d44a898d3682316680459c34d661f5844797912fa21f704cde143d6d079ac8d32895be2182c29f58d068df3fa2795e314beab5f11c
@@ -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: ["2.7", "3.0", "3.1"]
23
23
  gemfile:
24
24
  - Gemfile
25
- - gemfiles/6.1.gemfile
26
- - gemfiles/6.0.gemfile
25
+ - gemfiles/7_0.gemfile
26
+ - gemfiles/6_1.gemfile
27
+ - gemfiles/6_0.gemfile
27
28
 
28
29
  steps:
29
- - uses: actions/checkout@v1
30
+ - uses: actions/checkout@v3
30
31
 
31
- - uses: actions/cache@v2
32
+ - uses: actions/cache@v3
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
@@ -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,13 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## 1.1.0
15
+
16
+ - [Added] `<meta name="viewport" content="width=device-width,initial-scale=1">`
17
+ is now added by default.
18
+ - [Changed] You can now group all translations under
19
+ `page_meta.controller.action.{title,description,keywords}`.
20
+
14
21
  ## 1.0.0
15
22
 
16
23
  - 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"
46
47
  ```
47
48
 
48
- The title can without the `base` context can be accessed through
49
+ Previously, you could also use the `page_meta.{titles,description,keywords}` scopes, but this is now
50
+ 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"
60
+ ```
61
+
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
@@ -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.0.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", "~> 6.1.0"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 7.0.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
 
@@ -91,5 +98,9 @@ module PageMeta
91
98
  def compute_default_description
92
99
  tag(:description, description.to_s) unless description.to_s.empty?
93
100
  end
101
+
102
+ def compute_default_viewport
103
+ tag(:viewport, "width=device-width,initial-scale=1") unless meta_tags[:viewport]
104
+ end
94
105
  end
95
106
  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.1.0"
5
5
  end
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.1.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: 2023-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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_0.gemfile
152
+ - gemfiles/6_1.gemfile
153
+ - gemfiles/7_0.gemfile
154
154
  - lib/page_meta.rb
155
155
  - lib/page_meta/action.rb
156
156
  - lib/page_meta/base.rb
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubygems_version: 3.2.32
192
+ rubygems_version: 3.4.5
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=