page_meta 0.1.1 → 1.0.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: 47b05c4d0f3a885ff8629fcd3a0c7a94e7b02ce9
4
- data.tar.gz: 864f07a8590ad4348747251d1702259ea7ffe60f
2
+ SHA256:
3
+ metadata.gz: 0727fb1af7a2848d3cd1e6f2d44efd3c106c44588cd604d9738c0d1b90bdb67d
4
+ data.tar.gz: fd339b23e757843cab438e5078d17253bcbaca18bf4351082706a2ec81da065d
5
5
  SHA512:
6
- metadata.gz: 76be3317383dc4c0c4fa0e79ae04801c39308c45483c565b85ae8aa03d91da39f8bd832e1966ac9ef8b7fa6bef592ffcbb6964cbdae74aa89559b8bd24b3f539
7
- data.tar.gz: ce9cf345d3b877a69be7ad736139790193726f03c8376a27657720e0840bfa39cefe8e2d7bed0714b9ba9ac3208fea32736dcb87ebb7efbab8a3fc7778db4c87
6
+ metadata.gz: 790616651e1425832a679050c2d6c9b1805d4236f88fedcf3b622a0176cf7020be0f78672094b1660417c06c8283dc123a143ae1f666393f0afc4bcee26013d7
7
+ data.tar.gz: 0c6981527e16056706a51088ad995a70167e8e55c47bd86c7c1613a394aea0835f4b047f642186a883c98c78f903dff905b7e804b63067a4bd838d4416509105
@@ -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,61 @@
1
+ ---
2
+ name: ruby-tests
3
+
4
+ on:
5
+ pull_request:
6
+ branches:
7
+ - main
8
+ push:
9
+ branches:
10
+ - main
11
+
12
+ schedule:
13
+ - cron: "0 10 * * *"
14
+
15
+ jobs:
16
+ build:
17
+ name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
18
+ runs-on: "ubuntu-latest"
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby: [2.7.x, 3.0.x]
23
+ gemfile:
24
+ - Gemfile
25
+ - gemfiles/6.1.gemfile
26
+ - gemfiles/6.0.gemfile
27
+
28
+ steps:
29
+ - uses: actions/checkout@v1
30
+
31
+ - uses: actions/cache@v2
32
+ with:
33
+ path: vendor/bundle
34
+ key: >
35
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
36
+ hashFiles(matrix.gemfile) }}
37
+ restore-keys: >
38
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
39
+ hashFiles(matrix.gemfile) }}
40
+
41
+ - name: Set up Ruby
42
+ uses: actions/setup-ruby@v1
43
+ with:
44
+ ruby-version: ${{ matrix.ruby }}
45
+
46
+ - name: Install gem dependencies
47
+ env:
48
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
49
+ run: |
50
+ gem install bundler
51
+ bundle config path vendor/bundle
52
+ bundle update --jobs 4 --retry 3
53
+
54
+ - name: Run Tests
55
+ env:
56
+ PGHOST: localhost
57
+ PGUSER: postgres
58
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
59
+ run: |
60
+ bundle exec rake
61
+ bundle exec rubocop
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/
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
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:
15
+ Enabled: false
16
+
17
+ Metrics:
18
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,5 +2,19 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 2.2.3
6
- before_install: gem install bundler -v 1.10.6
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=
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
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.0.0
15
+
16
+ - 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/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in page_meta.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,38 +1,43 @@
1
- # PageMeta
1
+ # page_meta
2
2
 
3
- [![Build Status](https://travis-ci.org/fnando/page_meta.svg?branch=master)](https://travis-ci.org/fnando/page_meta)
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
+ [![Gem](https://img.shields.io/gem/v/page_meta.svg)](https://rubygems.org/gems/page_meta)
6
+ [![Gem](https://img.shields.io/gem/dt/page_meta.svg)](https://rubygems.org/gems/page_meta)
4
7
 
5
- Easily define `<meta>` and `<link>` tags. I18n support for descriptions, keywords and titles.
8
+ Easily define `<meta>` and `<link>` tags. I18n support for descriptions,
9
+ keywords and titles.
6
10
 
7
11
  ## Installation
8
12
 
9
- Add this line to your application's Gemfile:
13
+ ```bash
14
+ gem install page_meta
15
+ ```
16
+
17
+ Or add the following line to your project's Gemfile:
10
18
 
11
19
  ```ruby
12
20
  gem "page_meta"
13
21
  ```
14
22
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install page_meta
22
-
23
23
  ## Usage
24
24
 
25
- 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.
25
+ 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.
26
28
 
27
29
  ```html
28
- <meta charset="utf-8">
29
- <meta name="language" content="en">
30
- <meta itemprop="language" content="en">
30
+ <meta charset="utf-8" />
31
+ <meta name="language" content="en" />
32
+ <meta itemprop="language" content="en" />
31
33
  ```
32
34
 
33
- 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:
34
38
 
35
39
  ```yaml
40
+ ---
36
41
  page_meta:
37
42
  titles:
38
43
  base: "%{value} • MyApp"
@@ -40,14 +45,25 @@ page_meta:
40
45
  index: "Welcome to MyApp"
41
46
  ```
42
47
 
43
- Sometimes you need to render some dynamic value. In this case, you can use the I18n placeholders.
48
+ The title can without the `base` context can be accessed through
49
+ `page_meta.title.simple`.
50
+
51
+ ```erb
52
+ <%= page_meta.title %> // Welcome to MyApp • MyApp
53
+ <%= page_meta.title.simple %> // Welcome to MyApp
54
+ ```
55
+
56
+ Sometimes you need to render some dynamic value. In this case, you can use the
57
+ I18n placeholders.
44
58
 
45
59
  ```yaml
60
+ ---
46
61
  en:
47
- titles:
48
- base: "%{title} • MyCompany"
49
- workshops:
50
- show: "%{name}"
62
+ page_meta:
63
+ titles:
64
+ base: "%{title} • MyCompany"
65
+ workshops:
66
+ show: "%{name}"
51
67
  ```
52
68
 
53
69
  You can then set dynamic values using the `PageMeta::Base#[]=`.
@@ -63,19 +79,20 @@ end
63
79
 
64
80
  Some actions are aliased, so you don't have to duplicate the translations:
65
81
 
66
- * Action `create` points to `new`
67
- * Action `update` points to `edit`
68
- * Action `destroy` points to `remove`
82
+ - Action `create` points to `new`
83
+ - Action `update` points to `edit`
84
+ - Action `destroy` points to `remove`
69
85
 
70
86
  The same concept is applied to descriptions and keywords.
71
87
 
72
88
  ```yaml
89
+ ---
73
90
  en:
74
91
  page_meta:
75
92
  descriptions:
76
93
  site:
77
94
  home: MyApp is the best way of doing something.
78
-
95
+
79
96
  keywords:
80
97
  site:
81
98
  home: "myapp, thing, other thing"
@@ -83,7 +100,8 @@ en:
83
100
 
84
101
  ### Defining meta tags
85
102
 
86
- To define other meta tags, you have to use `PageMeta::Base#tag` like the following:
103
+ To define other meta tags, you have to use `PageMeta::Base#tag` like the
104
+ following:
87
105
 
88
106
  ```ruby
89
107
  class Workshops Controller < ApplicationController
@@ -116,7 +134,7 @@ Finally, you can define meta tags for Facebook and Twitter:
116
134
  ```ruby
117
135
  # Meta tags for Facebook
118
136
  page_meta.tag :og, {
119
- image: asset_url("fb.png"),
137
+ image: helpers.asset_url("fb.png"),
120
138
  image_type: "image/png",
121
139
  image_width: 800,
122
140
  image_height: 600,
@@ -132,7 +150,7 @@ page_meta.tag :twitter, {
132
150
  description: @workshop.description,
133
151
  site: "@howto",
134
152
  creator: "@fnando",
135
- image: asset_url(@workshop.cover_image)
153
+ image: helpers.asset_url(@workshop.cover_image)
136
154
  }
137
155
  ```
138
156
 
@@ -146,10 +164,11 @@ page_meta.link :last, href: article_url(articles.last)
146
164
  page_meta.link :first, href: article_url(articles.first)
147
165
  ```
148
166
 
149
- The hash can be any of the link tag's attributes. The following example defines the Safari 9 Pinned Tab icon:
167
+ The hash can be any of the link tag's attributes. The following example defines
168
+ the Safari 9 Pinned Tab icon:
150
169
 
151
170
  ```ruby
152
- page_meta.link :mask_icon, color: "#4078c0", href: asset_url("mask_icon.svg")
171
+ page_meta.link :mask_icon, color: "#4078c0", href: helpers.asset_url("mask_icon.svg")
153
172
  ```
154
173
 
155
174
  ### Rendering the elements
@@ -168,17 +187,44 @@ To render all tags, just do something like this:
168
187
  </html>
169
188
  ```
170
189
 
171
- ## Development
190
+ #### Rendering titles and descriptions
191
+
192
+ You may want to render title and description on your page. In this case, you may
193
+ use something like this:
194
+
195
+ ```erb
196
+ <h1><%= page_meta.title.simple %></h1>
197
+ <p><%= page_meta.description.simple %></p>
198
+ ```
172
199
 
173
- 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.
200
+ If your description contains HTML, you can use
201
+ `page_meta.description(html: true).simple` instead. It will use Rails'
202
+ `html_safe` helpers to safely retrieve the translation, just like regular Rails
203
+ would do.
204
+ [Please read Rails docs](http://guides.rubyonrails.org/i18n.html#using-safe-html-translations)
205
+ for more info.
174
206
 
175
- 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).
207
+ ## Maintainer
176
208
 
177
- ## Contributing
209
+ - [Nando Vieira](https://github.com/fnando)
178
210
 
179
- 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.
211
+ ## Contributors
180
212
 
213
+ - https://github.com/fnando/page_meta/contributors
214
+
215
+ ## Contributing
216
+
217
+ For more details about how to contribute, please read
218
+ https://github.com/fnando/page_meta/blob/main/CONTRIBUTING.md.
181
219
 
182
220
  ## License
183
221
 
184
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
222
+ The gem is available as open source under the terms of the
223
+ [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
224
+ found at https://github.com/fnando/page_meta/blob/main/LICENSE.md.
225
+
226
+ ## Code of Conduct
227
+
228
+ Everyone interacting in the page_meta project's codebases, issue trackers, chat
229
+ rooms and mailing lists is expected to follow the
230
+ [code of conduct](https://github.com/fnando/page_meta/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,10 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
1
4
  require "bundler/gem_tasks"
2
5
  require "rake/testtask"
6
+ require "rubocop/rake_task"
7
+
8
+ RuboCop::RakeTask.new
3
9
 
4
10
  Rake::TestTask.new(:test) do |t|
5
11
  t.libs << "test"
6
- t.libs << "lib"
7
12
  t.test_files = FileList["test/**/*_test.rb"]
13
+ t.warning = false
8
14
  end
9
15
 
10
- task :default => :test
16
+ task default: %i[test rubocop]
data/bin/console CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #!/usr/bin/env ruby
2
3
 
3
4
  require "bundler/setup"
@@ -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 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 6.1"
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class Action
5
+ # rubocop:disable Style/MutableConstant
3
6
  ALIASES = {
4
- "update" => "edit",
5
- "create" => "new",
7
+ "update" => "edit",
8
+ "create" => "new",
6
9
  "destroy" => "remove"
7
10
  }
11
+ # rubocop:enable Style/MutableConstant
8
12
 
9
13
  def initialize(action)
10
14
  @action = action
@@ -1,11 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class Base
5
+ DEFAULT_META_TAGS = %i[language charset title keywords description].freeze
6
+
3
7
  attr_reader :controller, :store
4
8
 
5
9
  delegate :[], :[]=, to: :store
6
10
 
7
11
  def initialize(controller)
8
12
  @controller = controller
13
+ @description = {}
9
14
  @store = {}
10
15
  end
11
16
 
@@ -14,23 +19,23 @@ module PageMeta
14
19
  end
15
20
 
16
21
  def links
17
- @links ||= {}
22
+ @links ||= []
18
23
  end
19
24
 
20
25
  def tag(name, value)
21
26
  meta_tags[name] = value
22
27
  end
23
28
 
24
- def link(name, value)
25
- links[name] = value
29
+ def link(rel, options)
30
+ links << {rel: rel, options: options}
26
31
  end
27
32
 
28
33
  def title
29
34
  @title ||= Translator.new(:titles, naming, store)
30
35
  end
31
36
 
32
- def description
33
- @description ||= Translator.new(:descriptions, naming, store)
37
+ def description(html: false)
38
+ @description[html] ||= Translator.new(:descriptions, naming, store.merge(html: html))
34
39
  end
35
40
 
36
41
  def keywords
@@ -41,7 +46,7 @@ module PageMeta
41
46
  compute_default_meta_tags
42
47
  render_meta_tags + render_links
43
48
  end
44
- alias_method :to_s, :render
49
+ alias to_s render
45
50
 
46
51
  def naming
47
52
  @naming ||= Naming.new(controller)
@@ -50,22 +55,40 @@ module PageMeta
50
55
  def render_meta_tags
51
56
  meta_tags
52
57
  .map {|name, value| MetaTag.build(name, value).render }
53
- .join("")
58
+ .join
54
59
  .html_safe
55
60
  end
56
61
 
57
62
  def render_links
58
63
  links
59
- .map {|rel, options| Link.build(rel, options).render }
60
- .join("")
64
+ .map {|info| Link.build(info[:rel], info[:options]).render }
65
+ .join
61
66
  .html_safe
62
67
  end
63
68
 
64
69
  def compute_default_meta_tags
70
+ DEFAULT_META_TAGS.each do |method_name|
71
+ public_send("compute_default_#{method_name}")
72
+ end
73
+ end
74
+
75
+ def compute_default_language
65
76
  tag(:language, I18n.locale)
66
- tag(:charset, Rails.configuration.encoding)
77
+ end
78
+
79
+ def compute_default_title
67
80
  tag(:title, title) unless title.to_s.empty?
81
+ end
82
+
83
+ def compute_default_charset
84
+ tag(:charset, Rails.configuration.encoding)
85
+ end
86
+
87
+ def compute_default_keywords
68
88
  tag(:keywords, keywords.to_s) unless keywords.to_s.empty?
89
+ end
90
+
91
+ def compute_default_description
69
92
  tag(:description, description.to_s) unless description.to_s.empty?
70
93
  end
71
94
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PageMeta
4
+ class HashMetaTag < MetaTag
5
+ def render
6
+ return if content.empty?
7
+
8
+ content.each_with_object([]) do |(attr, value), buffer|
9
+ next if value.blank?
10
+
11
+ attr = attr.to_s.tr("_", ":")
12
+ buffer << helpers.tag(:meta, property: "#{base_name}:#{attr}", content: value)
13
+ end.join
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  module Helpers
3
5
  def page_meta
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class Link
3
5
  def self.build(rel, options)
4
6
  klass_name = "::PageMeta::Link::#{rel.to_s.camelize}"
5
- klass = const_get(klass_name) rescue Link
7
+ klass = begin
8
+ const_get(klass_name)
9
+ rescue ActionView::Template::Error, NameError
10
+ Link
11
+ end
6
12
  klass.new(rel, options)
7
13
  end
8
14
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
5
  class Charset < MetaTag
4
6
  def render
5
- return if content.empty?
7
+ return if content.blank?
6
8
 
7
- helpers.tag(:meta, charset: content)
9
+ helpers.tag(:meta, charset: content.to_s.upcase)
8
10
  end
9
11
  end
10
12
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
5
  class DnsPrefetchControl < MetaTag
4
6
  def render
5
7
  helpers.tag(:meta, "http-equiv" => "x-dns-prefetch-control", content: "on") +
6
- helpers.tag(:link, rel: "dns-prefetch", href: content)
8
+ helpers.tag(:link, rel: "dns-prefetch", href: content)
7
9
  end
8
10
  end
9
11
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
5
  class Language < MetaTag
4
6
  def render
5
7
  helpers.tag(:meta, name: name, content: content) +
6
- helpers.tag(:meta, itemprop: name, content: content)
8
+ helpers.tag(:meta, itemprop: name, content: content)
7
9
  end
8
10
  end
9
11
  end
@@ -1,14 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
- class Og < MetaTag
4
- def render
5
- return if content.empty?
6
-
7
- content.each_with_object("") do |(attr, value), buffer|
8
- next if value.blank?
9
- attr = attr.to_s.gsub(/_/, ":")
10
- buffer << helpers.tag(:meta, property: "og:#{attr}", content: value)
11
- end
5
+ class Og < HashMetaTag
6
+ def base_name
7
+ "og"
12
8
  end
13
9
  end
14
10
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
5
  class Title < MetaTag
4
6
  def render
5
7
  helpers.content_tag(:title, content.to_s) +
6
- helpers.tag(:meta, name: "DC.title", content: content.simple) +
7
- helpers.tag(:meta, itemprop: "name", content: content.simple)
8
+ helpers.tag(:meta, name: "DC.title", content: content.simple) +
9
+ helpers.tag(:meta, itemprop: "name", content: content.simple)
8
10
  end
9
11
  end
10
12
  end
@@ -1,14 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
- class Twitter < MetaTag
4
- def render
5
- return if content.empty?
6
-
7
- content.each_with_object("") do |(attr, value), buffer|
8
- next if value.blank?
9
- attr = attr.to_s.gsub(/_/, ":")
10
- buffer << helpers.tag(:meta, property: "twitter:#{attr}", content: value)
11
- end
5
+ class Twitter < HashMetaTag
6
+ def base_name
7
+ "twitter"
12
8
  end
13
9
  end
14
10
  end
@@ -1,10 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class MetaTag
3
5
  attr_reader :name, :content
4
6
 
5
7
  def self.build(name, content)
6
8
  klass_name = "::PageMeta::MetaTag::#{name.to_s.camelize}"
7
- klass = const_get(klass_name) rescue MetaTag
9
+ klass = begin
10
+ const_get(klass_name)
11
+ rescue ActionView::Template::Error, NameError
12
+ MetaTag
13
+ end
8
14
  klass.new(name, content)
9
15
  end
10
16
 
@@ -26,7 +32,7 @@ module PageMeta
26
32
  return if content.empty?
27
33
 
28
34
  helpers.tag(:meta, name: name, content: content) +
29
- helpers.tag(:meta, itemprop: name, content: content)
35
+ helpers.tag(:meta, itemprop: name, content: content)
30
36
  end
31
37
  end
32
38
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class Naming
3
5
  def initialize(controller)
@@ -12,9 +14,12 @@ module PageMeta
12
14
  # Converts `PagesController` into `pages` and
13
15
  # `Admin::PagesController` into `admin.pages`.
14
16
  def controller
15
- @controller ||= @_controller.class.name.underscore
16
- .gsub(/_controller/, "")
17
- .gsub(%r[/], ".")
17
+ @controller ||= @_controller
18
+ .class
19
+ .name
20
+ .underscore
21
+ .gsub(/_controller/, "")
22
+ .tr("/", ".")
18
23
  end
19
24
  end
20
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class Railtie < Rails::Railtie
3
5
  initializer "page_meta" do
@@ -1,23 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  class Translator
3
- attr_reader :scope, :naming, :options
5
+ include ::ActionView::Helpers::TranslationHelper
6
+
7
+ attr_reader :scope, :naming, :options, :html
4
8
 
5
9
  def initialize(scope, naming, options = {})
6
10
  @scope = scope
7
11
  @naming = naming
12
+ @html = options[:html]
8
13
  @options = options
9
14
  end
10
15
 
11
16
  def to_s
12
17
  return "" if simple.blank?
13
- I18n.t("page_meta.#{scope}.base", value: simple, default: simple)
18
+
19
+ t("page_meta.#{scope}.base", value: simple, default: simple)
20
+ end
21
+
22
+ def translation_scope
23
+ "page_meta.#{scope}.#{naming.controller}.#{naming.action}"
14
24
  end
15
25
 
16
26
  def simple
17
- I18n.t(
18
- "page_meta.#{scope}.#{naming.controller}.#{naming.action}",
19
- options.merge(default: "")
20
- )
27
+ override_options = options.merge(default: "")
28
+
29
+ translation = t("#{translation_scope}_html", **override_options) if html
30
+ translation = t(translation_scope, **override_options) if translation.blank?
31
+ translation
21
32
  end
22
33
  end
23
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
- VERSION = "0.1.1"
4
+ VERSION = "1.0.0"
3
5
  end
data/lib/page_meta.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PageMeta
2
4
  require "i18n"
3
5
  require "rails/railtie"
@@ -5,6 +7,7 @@ module PageMeta
5
7
  require "page_meta/version"
6
8
  require "page_meta/base"
7
9
  require "page_meta/meta_tag"
10
+ require "page_meta/hash_meta_tag"
8
11
  require "page_meta/meta_tag/charset"
9
12
  require "page_meta/meta_tag/dns_prefetch_control"
10
13
  require "page_meta/meta_tag/title"
data/page_meta.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "./lib/page_meta/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -5,24 +7,31 @@ Gem::Specification.new do |spec|
5
7
  spec.version = PageMeta::VERSION
6
8
  spec.authors = ["Nando Vieira"]
7
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
+ }
8
14
 
9
- 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."
10
17
  spec.description = spec.summary
11
18
  spec.homepage = "https://github.com/fnando/page_meta"
12
19
  spec.license = "MIT"
13
20
 
14
- 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)/}) }
15
24
  spec.bindir = "exe"
16
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
17
26
  spec.require_paths = ["lib"]
18
27
 
19
- spec.add_dependency "rails"
28
+ spec.add_dependency "rails", ">=6.0"
20
29
 
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "bundler"
24
31
  spec.add_development_dependency "minitest-utils"
25
- spec.add_development_dependency "minitest-autotest"
26
- spec.add_development_dependency "test_notifier"
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.1.1
4
+ version: 1.0.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: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2021-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,44 +16,44 @@ 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
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: minitest-utils
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: pry-meta
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: minitest-utils
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: minitest-autotest
84
+ name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: test_notifier
98
+ name: rubocop-fnando
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: pry-meta
112
+ name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -130,18 +130,31 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
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"
133
140
  - ".gitignore"
141
+ - ".rubocop.yml"
134
142
  - ".travis.yml"
143
+ - CHANGELOG.md
135
144
  - CODE_OF_CONDUCT.md
145
+ - CONTRIBUTING.md
136
146
  - Gemfile
137
147
  - LICENSE.txt
138
148
  - README.md
139
149
  - Rakefile
140
150
  - bin/console
141
151
  - bin/setup
152
+ - gemfiles/6.0.gemfile
153
+ - gemfiles/6.1.gemfile
142
154
  - lib/page_meta.rb
143
155
  - lib/page_meta/action.rb
144
156
  - lib/page_meta/base.rb
157
+ - lib/page_meta/hash_meta_tag.rb
145
158
  - lib/page_meta/helpers.rb
146
159
  - lib/page_meta/link.rb
147
160
  - lib/page_meta/meta_tag.rb
@@ -159,8 +172,9 @@ files:
159
172
  homepage: https://github.com/fnando/page_meta
160
173
  licenses:
161
174
  - MIT
162
- metadata: {}
163
- post_install_message:
175
+ metadata:
176
+ rubygems_mfa_required: 'true'
177
+ post_install_message:
164
178
  rdoc_options: []
165
179
  require_paths:
166
180
  - lib
@@ -168,16 +182,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
182
  requirements:
169
183
  - - ">="
170
184
  - !ruby/object:Gem::Version
171
- version: '0'
185
+ version: 2.7.0
172
186
  required_rubygems_version: !ruby/object:Gem::Requirement
173
187
  requirements:
174
188
  - - ">="
175
189
  - !ruby/object:Gem::Version
176
190
  version: '0'
177
191
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.4.5.1
180
- signing_key:
192
+ rubygems_version: 3.2.32
193
+ signing_key:
181
194
  specification_version: 4
182
195
  summary: Easily define <meta> and <link> tags. I18n support for descriptions, keywords
183
196
  and titles.