page_meta 0.2.0 → 1.1.0

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
- SHA1:
3
- metadata.gz: e9c07868edd3c003b06253874a088a2ea0bb00bd
4
- data.tar.gz: d228a7a77ef36d2312c03bb0d7b2245872f44448
2
+ SHA256:
3
+ metadata.gz: 89a7406728480d6a3eb785869d6cae90f32b3bfe2fd3e0f8a6a6ced5c03da4b3
4
+ data.tar.gz: e5db2e7b705299c0f736164fa5352242e2211a1c6bed9d12802263643cec2930
5
5
  SHA512:
6
- metadata.gz: 51d00356fd9df12fcd14867e5bf158f9fa04cf1dbd66d1b20105a8fdeac5e8692fb765c3dc84bd319b8d246aa073345749cf5a7d490fc36dad78c23e05faddae
7
- data.tar.gz: 181ead8af4434898b10f609784abecd295f5f098fcf333647997d556ce6b236473e7000bdf8e1bc0d4e2fbe5b661c207470041a3b406fb8fc488c2338479d4d1
6
+ metadata.gz: e3961943c7d5506baaa3ce0f28d06819dc430aa3c3f38e503324cb52277c1aa2163ef224e4be4f2cfd41fa2e322cc087e0fd6d3680674ccd036e3d9bb6a34c61
7
+ data.tar.gz: bf19f1d84e6fdcb8ad48b8d44a898d3682316680459c34d661f5844797912fa21f704cde143d6d079ac8d32895be2182c29f58d068df3fa2795e314beab5f11c
@@ -0,0 +1,4 @@
1
+ # You can read more about CODEOWNERS at
2
+ # https://help.github.com/github/creating-cloning-and-archiving-repositories/about-code-owners
3
+
4
+ * @fnando
@@ -0,0 +1,3 @@
1
+ ---
2
+ github: [fnando]
3
+ custom: ["https://www.paypal.me/nandovieira/🍕"]
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: "🐛 Bug Report"
3
+ about: Report a reproducible bug or regression.
4
+ title: 'Bug: '
5
+ labels: 'Status: Unconfirmed'
6
+
7
+ ---
8
+
9
+ <!--
10
+ - Please provide a clear and concise description of what the bug is.
11
+ - If possible, add an example reproducing your issue.
12
+ - Please test using the latest version of page_meta
13
+ to make sure your issue has not already been fixed.
14
+ -->
15
+
16
+ ## Description
17
+
18
+ [Add bug description here]
19
+
20
+ ## How to reproduce
21
+
22
+ [Add steps on how to reproduce this issue]
23
+
24
+ ## What do you expect
25
+
26
+ [Describe what do you expect to happen]
27
+
28
+ ## What happened instead
29
+
30
+ [Describe the actual results]
31
+
32
+ ## Software:
33
+
34
+ - Gem version: [Add gem version here]
35
+ - Ruby version: [Add version here]
36
+
37
+ ## Full backtrace
38
+
39
+ ```text
40
+ [Paste full backtrace here]
41
+ ```
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: "💡 Feature request"
3
+ about: Have an idea that may be useful? Make a suggestion!
4
+ title: 'Feature Request: '
5
+ labels: 'Feature request'
6
+
7
+ ---
8
+
9
+ ## Description
10
+
11
+ _A clear and concise description of what the problem is._
12
+
13
+ ## Describe the solution
14
+
15
+ _A clear and concise description of what you want to happen._
16
+
17
+ ## Alternatives you considered
18
+
19
+ _A clear and concise description of any alternative solutions or features you've considered._
20
+
21
+ ## Additional context
22
+
23
+ _Add any other context, screenshots, links, etc about the feature request here._
@@ -0,0 +1,38 @@
1
+ <!--
2
+ If you're making a doc PR or something tiny where the below is irrelevant,
3
+ delete this template and use a short description, but in your description aim to
4
+ include both what the change is, and why it is being made, with enough context
5
+ for anyone to understand.
6
+ -->
7
+
8
+ <details>
9
+ <summary>PR Checklist</summary>
10
+
11
+ ### PR Structure
12
+
13
+ - [ ] This PR has reasonably narrow scope (if not, break it down into smaller
14
+ PRs).
15
+ - [ ] This PR avoids mixing refactoring changes with feature changes (split into
16
+ two PRs otherwise).
17
+ - [ ] This PR's title starts is concise and descriptive.
18
+
19
+ ### Thoroughness
20
+
21
+ - [ ] This PR adds tests for the most critical parts of the new functionality or
22
+ fixes.
23
+ - [ ] I've updated any docs, `.md` files, etc… affected by this change.
24
+
25
+ </details>
26
+
27
+ ### What
28
+
29
+ [TODO: Short statement about what is changing.]
30
+
31
+ ### Why
32
+
33
+ [TODO: Why this change is being made. Include any context required to understand
34
+ the why.]
35
+
36
+ ### Known limitations
37
+
38
+ [TODO or N/A]
@@ -0,0 +1,15 @@
1
+ ---
2
+ # Documentation:
3
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
4
+
5
+ version: 2
6
+ updates:
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
11
+
12
+ - package-ecosystem: "bundler"
13
+ directory: "/"
14
+ schedule:
15
+ interval: "daily"
@@ -0,0 +1,56 @@
1
+ ---
2
+ name: ruby-tests
3
+
4
+ on:
5
+ pull_request_target:
6
+ push:
7
+ branches:
8
+ - main
9
+ workflow_dispatch:
10
+ inputs: {}
11
+
12
+ jobs:
13
+ build:
14
+ name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
15
+ runs-on: "ubuntu-latest"
16
+ if: |
17
+ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
18
+ github.actor != 'dependabot[bot]'
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby: ["2.7", "3.0", "3.1"]
23
+ gemfile:
24
+ - Gemfile
25
+ - gemfiles/7_0.gemfile
26
+ - gemfiles/6_1.gemfile
27
+ - gemfiles/6_0.gemfile
28
+
29
+ steps:
30
+ - uses: actions/checkout@v3
31
+
32
+ - uses: actions/cache@v3
33
+ with:
34
+ path: vendor/bundle
35
+ key: >
36
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
37
+ hashFiles(matrix.gemfile) }}
38
+
39
+ - name: Set up Ruby
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby }}
43
+
44
+ - name: Install gem dependencies
45
+ env:
46
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
47
+ run: |
48
+ gem install bundler
49
+ bundle config path vendor/bundle
50
+ bundle update --jobs 4 --retry 3
51
+
52
+ - name: Run Tests
53
+ env:
54
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
55
+ run: |
56
+ bundle exec rake
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
3
+ *.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /log
11
+ /bin/*
data/.rubocop.yml CHANGED
@@ -1,50 +1,24 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
3
4
 
4
- Metrics/LineLength:
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+ Exclude:
9
+ - test/support/dummy.rb
10
+ - vendor/**/*
11
+ - bin/**/*
12
+ - gemfiles/vendor/**/*
13
+
14
+ Layout/LineLength:
5
15
  Enabled: false
6
16
 
7
- Style/Documentation:
17
+ Metrics:
8
18
  Enabled: false
9
19
 
10
- Style/StringLiterals:
11
- EnforcedStyle: double_quotes
12
-
13
- Layout/SpaceInsideBlockBraces:
14
- EnforcedStyle: space
15
- EnforcedStyleForEmptyBraces: space
16
- SpaceBeforeBlockParameters: false
17
-
18
- Layout/SpaceInsideHashLiteralBraces:
19
- EnforcedStyle: no_space
20
- EnforcedStyleForEmptyBraces: no_space
21
-
22
- Layout/FirstArrayElementLineBreak:
23
- Enabled: true
24
-
25
- Layout/FirstHashElementLineBreak:
26
- Enabled: true
27
-
28
- Style/SymbolArray:
29
- Enabled: true
30
-
31
- Style/PercentLiteralDelimiters:
32
- PreferredDelimiters:
33
- '%': '[]'
34
- '%i': '[]'
35
- '%q': '[]'
36
- '%Q': '[]'
37
- '%r': '[]'
38
- '%s': '[]'
39
- '%w': '[]'
40
- '%W': '[]'
41
- '%x': '[]'
42
-
43
- Metrics/MethodLength:
20
+ Minitest/MultipleAssertions:
44
21
  Enabled: false
45
22
 
46
- Style/FormatStringToken:
23
+ Gemspec/DevelopmentDependencies:
47
24
  Enabled: false
48
-
49
- Style/Alias:
50
- EnforcedStyle: prefer_alias_method
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ <!--
4
+ Prefix your message with one of the following:
5
+
6
+ - [Added] for new features.
7
+ - [Changed] for changes in existing functionality.
8
+ - [Deprecated] for soon-to-be removed features.
9
+ - [Removed] for now removed features.
10
+ - [Fixed] for any bug fixes.
11
+ - [Security] in case of vulnerabilities.
12
+ -->
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
+
21
+ ## 1.0.0
22
+
23
+ - Initial release.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,80 @@
1
+ # Contributing to page_meta
2
+
3
+ 👍🎉 First off, thanks for taking the time to contribute! 🎉👍
4
+
5
+ The following is a set of guidelines for contributing to this project. These are
6
+ mostly guidelines, not rules. Use your best judgment, and feel free to propose
7
+ changes to this document in a pull request.
8
+
9
+ ## Code of Conduct
10
+
11
+ Everyone interacting in this project's codebases, issue trackers, chat rooms and
12
+ mailing lists is expected to follow the
13
+ [code of conduct](https://github.com/fnando/page_meta/blob/main/CODE_OF_CONDUCT.md).
14
+
15
+ ## Reporting bugs
16
+
17
+ This section guides you through submitting a bug report. Following these
18
+ guidelines helps maintainers and the community understand your report, reproduce
19
+ the behavior, and find related reports.
20
+
21
+ - Before creating bug reports, please check the open issues; somebody may
22
+ already have submitted something similar, and you may not need to create a new
23
+ one.
24
+ - When you are creating a bug report, please include as many details as
25
+ possible, with an example reproducing the issue.
26
+
27
+ ## Contributing with code
28
+
29
+ Before making any radicals changes, please make sure you discuss your intention
30
+ by [opening an issue on Github](https://github.com/fnando/page_meta/issues).
31
+
32
+ When you're ready to make your pull request, follow checklist below to make sure
33
+ your contribution is according to how this project works.
34
+
35
+ 1. [Fork](https://help.github.com/forking/) page_meta
36
+ 2. Create a topic branch - `git checkout -b my_branch`
37
+ 3. Make your changes using [descriptive commit messages](#commit-messages)
38
+ 4. Update CHANGELOG.md describing your changes by adding an entry to the
39
+ "Unreleased" section. If this section is not available, create one right
40
+ before the last version.
41
+ 5. Push to your branch - `git push origin my_branch`
42
+ 6. [Create a pull request](https://help.github.com/articles/creating-a-pull-request)
43
+ 7. That's it!
44
+
45
+ ## Styleguides
46
+
47
+ ### Commit messages
48
+
49
+ - Use the present tense ("Add feature" not "Added feature")
50
+ - Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
51
+ - Limit the first line to 72 characters or less
52
+ - Reference issues and pull requests liberally after the first line
53
+
54
+ ### Changelog
55
+
56
+ - Add a message describing your changes to the "Unreleased" section. The
57
+ changelog message should follow the same style as the commit message.
58
+ - Prefix your message with one of the following:
59
+ - `[Added]` for new features.
60
+ - `[Changed]` for changes in existing functionality.
61
+ - `[Deprecated]` for soon-to-be removed features.
62
+ - `[Removed]` for now removed features.
63
+ - `[Fixed]` for any bug fixes.
64
+ - `[Security]` in case of vulnerabilities.
65
+
66
+ ### Ruby code
67
+
68
+ - This project uses [Rubocop](https://rubocop.org) to enforce code style. Before
69
+ submitting your changes, make sure your tests are passing and code conforms to
70
+ the expected style by running `rake`.
71
+ - Do not change the library version. This will be done by the maintainer
72
+ whenever a new version is about to be released.
73
+
74
+ ### JavaScript code
75
+
76
+ - This project uses [ESLint](https://eslint.org) to enforce code style. Before
77
+ submitting your changes, make sure your tests are passing and code conforms to
78
+ the expected style by running `yarn test:ci`.
79
+ - Do not change the library version. This will be done by the maintainer
80
+ whenever a new version is about to be released.
data/README.md CHANGED
@@ -1,65 +1,84 @@
1
- # PageMeta
1
+ # page_meta
2
2
 
3
- [![Travis-CI](https://travis-ci.org/fnando/page_meta.png)](https://travis-ci.org/fnando/page_meta)
4
- [![Code Climate](https://codeclimate.com/github/fnando/page_meta/badges/gpa.svg)](https://codeclimate.com/github/fnando/page_meta)
5
- [![Test Coverage](https://codeclimate.com/github/fnando/page_meta/badges/coverage.svg)](https://codeclimate.com/github/fnando/page_meta/coverage)
3
+ [![Tests](https://github.com/fnando/page_meta/workflows/ruby-tests/badge.svg)](https://github.com/fnando/page_meta)
6
4
  [![Gem](https://img.shields.io/gem/v/page_meta.svg)](https://rubygems.org/gems/page_meta)
7
5
  [![Gem](https://img.shields.io/gem/dt/page_meta.svg)](https://rubygems.org/gems/page_meta)
8
6
 
9
- Easily define `<meta>` and `<link>` tags. I18n support for descriptions, keywords and titles.
7
+ Easily define `<meta>` and `<link>` tags. I18n support for descriptions,
8
+ keywords and titles.
10
9
 
11
10
  ## Installation
12
11
 
13
- Add this line to your application's Gemfile:
12
+ ```bash
13
+ gem install page_meta
14
+ ```
15
+
16
+ Or add the following line to your project's Gemfile:
14
17
 
15
18
  ```ruby
16
19
  gem "page_meta"
17
20
  ```
18
21
 
19
- And then execute:
20
-
21
- $ bundle
22
-
23
- Or install it yourself as:
24
-
25
- $ gem install page_meta
26
-
27
22
  ## Usage
28
23
 
29
- Your controller and views have an object called `page_meta`. You can use it to define meta tags and links. By default, it will include the encoding and language meta tags.
24
+ Your controller and views have an object called `page_meta`. You can use it to
25
+ define meta tags and links. By default, it will include the encoding, language
26
+ and viewport meta tags.
30
27
 
31
28
  ```html
32
- <meta charset="utf-8">
33
- <meta name="language" content="en">
34
- <meta itemprop="language" content="en">
29
+ <meta charset="utf-8" />
30
+ <meta name="language" content="en" />
31
+ <meta itemprop="language" content="en" />
32
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
35
33
  ```
36
34
 
37
- You can use I18n to define titles, descriptions and keywords. These values will be inferred from the controller and action names. For an action `SiteController#index` you'll need the following translation scope:
35
+ You can use I18n to define titles, descriptions and keywords. These values will
36
+ be inferred from the controller and action names. For an action
37
+ `SiteController#index` you'll need the following translation scope:
38
38
 
39
39
  ```yaml
40
- page_meta:
41
- titles:
42
- base: "%{value} • MyApp"
40
+ en:
41
+ page_meta:
42
+ title_base: "%{value} • MyApp"
43
+
43
44
  site:
44
- index: "Welcome to MyApp"
45
+ index:
46
+ title: "Welcome to MyApp"
45
47
  ```
46
48
 
47
- The title can without the `base` context can be accessed through `page_meta.title.simple`.
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
63
+ `page_meta.title.simple`.
48
64
 
49
65
  ```erb
50
66
  <%= page_meta.title %> // Welcome to MyApp • MyApp
51
67
  <%= page_meta.title.simple %> // Welcome to MyApp
52
68
  ```
53
69
 
54
- Sometimes you need to render some dynamic value. In this case, you can use the I18n placeholders.
70
+ Sometimes you need to render some dynamic value. In this case, you can use the
71
+ I18n placeholders.
55
72
 
56
73
  ```yaml
74
+ ---
57
75
  en:
58
76
  page_meta:
59
- titles:
60
- base: "%{title} • MyCompany"
61
- workshops:
62
- show: "%{name}"
77
+ title_base: "%{title} • MyCompany"
78
+
79
+ workshops:
80
+ show:
81
+ title: "%{name}"
63
82
  ```
64
83
 
65
84
  You can then set dynamic values using the `PageMeta::Base#[]=`.
@@ -75,27 +94,28 @@ end
75
94
 
76
95
  Some actions are aliased, so you don't have to duplicate the translations:
77
96
 
78
- * Action `create` points to `new`
79
- * Action `update` points to `edit`
80
- * Action `destroy` points to `remove`
97
+ - Action `create` points to `new`
98
+ - Action `update` points to `edit`
99
+ - Action `destroy` points to `remove`
81
100
 
82
101
  The same concept is applied to descriptions and keywords.
83
102
 
84
103
  ```yaml
104
+ ---
85
105
  en:
86
106
  page_meta:
87
- descriptions:
88
- site:
89
- home: MyApp is the best way of doing something.
90
-
91
- keywords:
92
- site:
93
- 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"
94
113
  ```
95
114
 
96
115
  ### Defining meta tags
97
116
 
98
- To define other meta tags, you have to use `PageMeta::Base#tag` like the following:
117
+ To define other meta tags, you have to use `PageMeta::Base#tag` like the
118
+ following:
99
119
 
100
120
  ```ruby
101
121
  class Workshops Controller < ApplicationController
@@ -158,7 +178,8 @@ page_meta.link :last, href: article_url(articles.last)
158
178
  page_meta.link :first, href: article_url(articles.first)
159
179
  ```
160
180
 
161
- The hash can be any of the link tag's attributes. The following example defines the Safari 9 Pinned Tab icon:
181
+ The hash can be any of the link tag's attributes. The following example defines
182
+ the Safari 9 Pinned Tab icon:
162
183
 
163
184
  ```ruby
164
185
  page_meta.link :mask_icon, color: "#4078c0", href: helpers.asset_url("mask_icon.svg")
@@ -182,26 +203,42 @@ To render all tags, just do something like this:
182
203
 
183
204
  #### Rendering titles and descriptions
184
205
 
185
- You may want to render title and description on your page. In this case, you may use something like this:
206
+ You may want to render title and description on your page. In this case, you may
207
+ use something like this:
186
208
 
187
209
  ```erb
188
210
  <h1><%= page_meta.title.simple %></h1>
189
211
  <p><%= page_meta.description.simple %></p>
190
212
  ```
191
213
 
192
- If your description contains HTML, you can use `page_meta.description(html: true).simple` instead. It will use Rails' `html_safe` helpers to safely retrieve the translation, just like regular Rails would do. [Please read Rails docs](http://guides.rubyonrails.org/i18n.html#using-safe-html-translations) for more info.
214
+ If your description contains HTML, you can use
215
+ `page_meta.description(html: true).simple` instead. It will use Rails'
216
+ `html_safe` helpers to safely retrieve the translation, just like regular Rails
217
+ would do.
218
+ [Please read Rails docs](http://guides.rubyonrails.org/i18n.html#using-safe-html-translations)
219
+ for more info.
193
220
 
194
- ## Development
221
+ ## Maintainer
195
222
 
196
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
223
+ - [Nando Vieira](https://github.com/fnando)
197
224
 
198
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
225
+ ## Contributors
199
226
 
200
- ## Contributing
227
+ - https://github.com/fnando/page_meta/contributors
201
228
 
202
- Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/page_meta. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
229
+ ## Contributing
203
230
 
231
+ For more details about how to contribute, please read
232
+ https://github.com/fnando/page_meta/blob/main/CONTRIBUTING.md.
204
233
 
205
234
  ## License
206
235
 
207
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
236
+ The gem is available as open source under the terms of the
237
+ [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
238
+ found at https://github.com/fnando/page_meta/blob/main/LICENSE.md.
239
+
240
+ ## Code of Conduct
241
+
242
+ Everyone interacting in the page_meta project's codebases, issue trackers, chat
243
+ rooms and mailing lists is expected to follow the
244
+ [code of conduct](https://github.com/fnando/page_meta/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bundler/setup"
3
4
  require "bundler/gem_tasks"
4
5
  require "rake/testtask"
6
+ require "rubocop/rake_task"
7
+
8
+ RuboCop::RakeTask.new
5
9
 
6
10
  Rake::TestTask.new(:test) do |t|
7
11
  t.libs << "test"
8
- t.libs << "lib"
9
12
  t.test_files = FileList["test/**/*_test.rb"]
13
+ t.warning = false
10
14
  end
11
15
 
12
- task default: :test
16
+ task default: %i[test rubocop]
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 6.0.0"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
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"
@@ -4,10 +4,11 @@ module PageMeta
4
4
  class Action
5
5
  # rubocop:disable Style/MutableConstant
6
6
  ALIASES = {
7
- "update" => "edit",
8
- "create" => "new",
7
+ "update" => "edit",
8
+ "create" => "new",
9
9
  "destroy" => "remove"
10
10
  }
11
+ # rubocop:enable Style/MutableConstant
11
12
 
12
13
  def initialize(action)
13
14
  @action = action
@@ -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
 
@@ -46,7 +53,7 @@ module PageMeta
46
53
  compute_default_meta_tags
47
54
  render_meta_tags + render_links
48
55
  end
49
- alias_method :to_s, :render
56
+ alias to_s render
50
57
 
51
58
  def naming
52
59
  @naming ||= Naming.new(controller)
@@ -55,14 +62,14 @@ module PageMeta
55
62
  def render_meta_tags
56
63
  meta_tags
57
64
  .map {|name, value| MetaTag.build(name, value).render }
58
- .join("")
65
+ .join
59
66
  .html_safe
60
67
  end
61
68
 
62
69
  def render_links
63
70
  links
64
71
  .map {|info| Link.build(info[:rel], info[:options]).render }
65
- .join("")
72
+ .join
66
73
  .html_safe
67
74
  end
68
75
 
@@ -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
@@ -7,6 +7,7 @@ module PageMeta
7
7
 
8
8
  content.each_with_object([]) do |(attr, value), buffer|
9
9
  next if value.blank?
10
+
10
11
  attr = attr.to_s.tr("_", ":")
11
12
  buffer << helpers.tag(:meta, property: "#{base_name}:#{attr}", content: value)
12
13
  end.join
@@ -5,10 +5,10 @@ module PageMeta
5
5
  def self.build(rel, options)
6
6
  klass_name = "::PageMeta::Link::#{rel.to_s.camelize}"
7
7
  klass = begin
8
- const_get(klass_name)
9
- rescue ActionView::Template::Error, NameError
10
- Link
11
- end
8
+ const_get(klass_name)
9
+ rescue ActionView::Template::Error, NameError
10
+ Link
11
+ end
12
12
  klass.new(rel, options)
13
13
  end
14
14
 
@@ -7,10 +7,10 @@ module PageMeta
7
7
  def self.build(name, content)
8
8
  klass_name = "::PageMeta::MetaTag::#{name.to_s.camelize}"
9
9
  klass = begin
10
- const_get(klass_name)
11
- rescue ActionView::Template::Error, NameError
12
- MetaTag
13
- end
10
+ const_get(klass_name)
11
+ rescue ActionView::Template::Error, NameError
12
+ MetaTag
13
+ end
14
14
  klass.new(name, content)
15
15
  end
16
16
 
@@ -19,7 +19,7 @@ module PageMeta
19
19
  .name
20
20
  .underscore
21
21
  .gsub(/_controller/, "")
22
- .gsub(%r[/], ".")
22
+ .tr("/", ".")
23
23
  end
24
24
  end
25
25
  end
@@ -13,20 +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
- t("page_meta.#{scope}.base", value: simple, default: simple)
22
+
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 || ""
19
27
  end
20
28
 
21
29
  def translation_scope
22
- "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
+ ]
23
34
  end
24
35
 
25
36
  def simple
26
37
  override_options = options.merge(default: "")
27
38
 
28
- translation = t("#{translation_scope}_html", override_options) if html
29
- 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
+
30
48
  translation
31
49
  end
32
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PageMeta
4
- VERSION = "0.2.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/page_meta.gemspec CHANGED
@@ -7,22 +7,31 @@ Gem::Specification.new do |spec|
7
7
  spec.version = PageMeta::VERSION
8
8
  spec.authors = ["Nando Vieira"]
9
9
  spec.email = ["fnando.vieira@gmail.com"]
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
11
+ spec.metadata = {
12
+ "rubygems_mfa_required" => "true"
13
+ }
10
14
 
11
- spec.summary = "Easily define <meta> and <link> tags. I18n support for descriptions, keywords and titles."
15
+ spec.summary = "Easily define <meta> and <link> tags. I18n support " \
16
+ "for descriptions, keywords and titles."
12
17
  spec.description = spec.summary
13
18
  spec.homepage = "https://github.com/fnando/page_meta"
14
19
  spec.license = "MIT"
15
20
 
16
- spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r[^(test|spec|features)/]) }
21
+ spec.files = `git ls-files -z`
22
+ .split("\x0")
23
+ .reject {|f| f.match(%r{^(test|spec|features)/}) }
17
24
  spec.bindir = "exe"
18
- spec.executables = spec.files.grep(%r[^exe/]) {|f| File.basename(f) }
25
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
19
26
  spec.require_paths = ["lib"]
20
27
 
21
- spec.add_dependency "rails"
28
+ spec.add_dependency "rails", ">=6.0"
22
29
 
23
30
  spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "rake"
25
31
  spec.add_development_dependency "minitest-utils"
26
- spec.add_development_dependency "simplecov"
27
32
  spec.add_development_dependency "pry-meta"
33
+ spec.add_development_dependency "rake"
34
+ spec.add_development_dependency "rubocop"
35
+ spec.add_development_dependency "rubocop-fnando"
36
+ spec.add_development_dependency "simplecov"
28
37
  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: 0.2.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-04 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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ 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'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +81,7 @@ dependencies:
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: minitest-utils
84
+ name: rubocop
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - ">="
@@ -67,7 +95,7 @@ dependencies:
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: simplecov
98
+ name: rubocop-fnando
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - ">="
@@ -81,7 +109,7 @@ dependencies:
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: pry-meta
112
+ name: simplecov
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -102,16 +130,27 @@ executables: []
102
130
  extensions: []
103
131
  extra_rdoc_files: []
104
132
  files:
133
+ - ".github/CODEOWNERS"
134
+ - ".github/FUNDING.yml"
135
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
136
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
137
+ - ".github/PULL_REQUEST_TEMPLATE.md"
138
+ - ".github/dependabot.yml"
139
+ - ".github/workflows/ruby-tests.yml"
105
140
  - ".gitignore"
106
141
  - ".rubocop.yml"
107
- - ".travis.yml"
142
+ - CHANGELOG.md
108
143
  - CODE_OF_CONDUCT.md
144
+ - CONTRIBUTING.md
109
145
  - Gemfile
110
146
  - LICENSE.txt
111
147
  - README.md
112
148
  - Rakefile
113
149
  - bin/console
114
150
  - bin/setup
151
+ - gemfiles/6_0.gemfile
152
+ - gemfiles/6_1.gemfile
153
+ - gemfiles/7_0.gemfile
115
154
  - lib/page_meta.rb
116
155
  - lib/page_meta/action.rb
117
156
  - lib/page_meta/base.rb
@@ -133,8 +172,9 @@ files:
133
172
  homepage: https://github.com/fnando/page_meta
134
173
  licenses:
135
174
  - MIT
136
- metadata: {}
137
- post_install_message:
175
+ metadata:
176
+ rubygems_mfa_required: 'true'
177
+ post_install_message:
138
178
  rdoc_options: []
139
179
  require_paths:
140
180
  - lib
@@ -142,16 +182,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
182
  requirements:
143
183
  - - ">="
144
184
  - !ruby/object:Gem::Version
145
- version: '0'
185
+ version: 2.7.0
146
186
  required_rubygems_version: !ruby/object:Gem::Requirement
147
187
  requirements:
148
188
  - - ">="
149
189
  - !ruby/object:Gem::Version
150
190
  version: '0'
151
191
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.6.13
154
- signing_key:
192
+ rubygems_version: 3.4.5
193
+ signing_key:
155
194
  specification_version: 4
156
195
  summary: Easily define <meta> and <link> tags. I18n support for descriptions, keywords
157
196
  and titles.
data/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
- rvm:
5
- - 2.4.2
6
- - 2.3.5
7
- - 2.2.8
8
- before_install: gem install bundler --pre
9
- before_script:
10
- - "curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter"
11
- - chmod +x ./cc-test-reporter
12
- - "./cc-test-reporter before-build"
13
- after_script:
14
- - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
15
- notifications:
16
- email: false
17
- env:
18
- global:
19
- 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=