m3ta 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +94 -0
- data/Rakefile +5 -0
- data/lib/m3ta/builder.rb +28 -0
- data/lib/m3ta/controller.rb +21 -0
- data/lib/m3ta/helpers.rb +102 -0
- data/lib/m3ta/railtie.rb +17 -0
- data/lib/m3ta/version.rb +5 -0
- data/lib/m3ta.rb +19 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4bbd235e15bc17fd75e90fb5dd6b91f9ec6ff3344d6e264d973cc17c8b6f67d0
|
4
|
+
data.tar.gz: 3b6b16f0a2ba3d099296b86b71ff893577c33523824e686f81bf4e6ae6a7821c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ddf382e94a722791cb16da70c8452d0446442fcf0de8fde9e296db6287e89257125edc13ad33c070c66b9d93b35591e3585fca57b561fef0e4e45d080801b9cd
|
7
|
+
data.tar.gz: bd0842ae695601fdaf5578a51b1c5c3976333e52990977ed773aeb52f34584242bb4f10831cea4271966f947740cb56e33c4a5ae042b201fb7436b8ebbe01e8d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2023
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# M3ta
|
2
|
+
|
3
|
+
Writing meta tags can be awkward. M3ta attempts to make light work of configuring defaults that are reused on every page and giving as much flexibility as possible to append and modify those defaults on each request whether it is in a controller or view.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add it to this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "m3ta"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```bash
|
15
|
+
bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Meta tags can be configured in multiple different ways. You can set defaults in to ways
|
21
|
+
|
22
|
+
|
23
|
+
Via an initializer
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
M3ta.defaults do |b|
|
27
|
+
b.title = 'Some blog post'
|
28
|
+
b.image = 'https://robl.me/braindeaf.png'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Via I18n locales
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
en:
|
36
|
+
m3ta:
|
37
|
+
site_name: RobL Vs...
|
38
|
+
description: I write thems code
|
39
|
+
```
|
40
|
+
|
41
|
+
Each request has access to a *m3ta::Builder* object to append data to.
|
42
|
+
|
43
|
+
* Controllers
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class ApplicationController < ActionController::Base
|
47
|
+
m3ta do |b|
|
48
|
+
b.title = 'A better title'
|
49
|
+
b.description = %(...and then it will be over and that'll be alright with me...)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class ProjectsController < ApplicationController
|
56
|
+
m3ta do |b|
|
57
|
+
b.title = 'Sometimes dead is better'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
* Views
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
:ruby
|
66
|
+
m3ta.tap do |b|
|
67
|
+
b.title = %(Thundercats are better than Gobots)
|
68
|
+
b.description = "#{b.description} - J.R. Hayes"
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
<%=
|
74
|
+
m3ta.tap do |b|
|
75
|
+
b.title = %(Thundercats are better than Gobots)
|
76
|
+
b.description = "#{b.description} - J.R. Hayes"
|
77
|
+
end
|
78
|
+
%>
|
79
|
+
```
|
80
|
+
|
81
|
+
Finally you can render your Meta Tags with a single helper in the application layout
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
!!!
|
85
|
+
%head
|
86
|
+
= m3ta_tags
|
87
|
+
%body
|
88
|
+
```
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
If you wish to contribute please feel free to fork the repo and submit a PR.
|
92
|
+
|
93
|
+
## License
|
94
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/m3ta/builder.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module M3ta
|
6
|
+
class Builder < Hashie::Dash
|
7
|
+
# Core
|
8
|
+
property :site_name
|
9
|
+
property :type
|
10
|
+
property :title
|
11
|
+
property :description
|
12
|
+
property :url
|
13
|
+
property :image
|
14
|
+
property :keywords
|
15
|
+
property :player
|
16
|
+
property :video
|
17
|
+
|
18
|
+
# Social
|
19
|
+
property :facebook_app_id
|
20
|
+
property :twitter_handle
|
21
|
+
|
22
|
+
def apply(attributes = {}, &block)
|
23
|
+
merge!(attributes)
|
24
|
+
block.call(self) if block_given?
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module M3ta
|
4
|
+
module Controller
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class_attribute :_m3ta, default: M3ta.defaults.clone
|
9
|
+
|
10
|
+
def self.m3ta(&block)
|
11
|
+
_m3ta.apply(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def m3ta(&block)
|
15
|
+
@m3ta ||= self.class.m3ta.clone
|
16
|
+
@m3ta.apply(&block)
|
17
|
+
end
|
18
|
+
helper_method :m3ta
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/m3ta/helpers.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module M3ta
|
4
|
+
module Helpers
|
5
|
+
def meta_tags
|
6
|
+
[
|
7
|
+
meta_tag(property: 'fb:app_id', content: m3ta.fb_app_id || '1434650413476851'),
|
8
|
+
twitter_card,
|
9
|
+
meta_tag(name: 'twitter:site', content: m3ta.twitter),
|
10
|
+
meta_tag(name: 'twitter:creator', content: m3ta.twitter),
|
11
|
+
meta_tag(property: 'og:type', content: m3ta.type || 'website'),
|
12
|
+
meta_tag(property: 'og:site_name', content: site_name),
|
13
|
+
meta_tag(property: 'og:url', content: url),
|
14
|
+
tag(:link, rel: 'canonical', href: url),
|
15
|
+
title_tags,
|
16
|
+
description_tags,
|
17
|
+
player_tags,
|
18
|
+
image_tags,
|
19
|
+
video_tags,
|
20
|
+
keywords_tags
|
21
|
+
].flatten.compact.join("\n").html_safe
|
22
|
+
end
|
23
|
+
|
24
|
+
def title_tags
|
25
|
+
[
|
26
|
+
content_tag(:title, m3ta.title),
|
27
|
+
meta_tag(name: 'title', content: m3ta.title),
|
28
|
+
meta_tag(property: 'og:title', content: m3ta.title),
|
29
|
+
meta_tag(name: 'twitter:title', content: m3ta.title)
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def twitter_card
|
34
|
+
card = m3ta.player.present? ? 'player' : 'summary_large_image'
|
35
|
+
meta_tag(name: 'twitter:card', content: card)
|
36
|
+
end
|
37
|
+
|
38
|
+
def player_tags
|
39
|
+
return unless m3ta.player.present?
|
40
|
+
|
41
|
+
[
|
42
|
+
meta_tag(name: 'twitter:player', content: m3ta.player),
|
43
|
+
meta_tag(name: 'twitter:player:width', content: '1280'),
|
44
|
+
meta_tag(name: 'twitter:player:height', content: '720')
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
def keywords_tags
|
49
|
+
return unless keywords.present?
|
50
|
+
|
51
|
+
meta_tag(name: 'keywords', content: keywords)
|
52
|
+
end
|
53
|
+
|
54
|
+
def image_tags
|
55
|
+
return unless m3ta.image
|
56
|
+
|
57
|
+
[
|
58
|
+
meta_tag(property: 'og:image', content: m3ta.image),
|
59
|
+
meta_tag(name: 'twitter:image:src', content: m3ta.image)
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
def video_tags
|
64
|
+
return unless m3ta.video
|
65
|
+
|
66
|
+
[
|
67
|
+
meta_tag(property: 'og:video:url', content: m3ta.video),
|
68
|
+
meta_tag(property: 'og:video:secure_url', content: m3ta.video),
|
69
|
+
meta_tag(property: 'og:video:width', content: m3ta.video_width),
|
70
|
+
meta_tag(property: 'og:video:height', content: m3ta.video_height),
|
71
|
+
meta_tag(property: 'og:video:type', content: m3ta.video_type)
|
72
|
+
]
|
73
|
+
end
|
74
|
+
|
75
|
+
def description_tags
|
76
|
+
[
|
77
|
+
meta_tag(name: 'description', content: m3ta.description),
|
78
|
+
meta_tag(property: 'og:description', content: m3ta.description),
|
79
|
+
meta_tag(name: 'twitter:description', content: m3ta.description)
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
def keywords
|
84
|
+
@keywords ||= Array[m3ta.keywords,
|
85
|
+
I18n.t('meta.keywords', default: '')].flatten.select(&:present?).map do |section|
|
86
|
+
section.to_s.split(',')
|
87
|
+
end.flatten.select(&:present?).map(&:strip).uniq.join(', ')
|
88
|
+
end
|
89
|
+
|
90
|
+
def site_name
|
91
|
+
m3ta.site_name || t('site_name')
|
92
|
+
end
|
93
|
+
|
94
|
+
def url
|
95
|
+
(m3ta.url || request.url).split('?')[0]
|
96
|
+
end
|
97
|
+
|
98
|
+
def meta_tag(options = {})
|
99
|
+
tag(:meta, options)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/m3ta/railtie.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module M3ta
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer 'm3ta.action_controller' do
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
include M3ta::Controller
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer 'm3ta.action_view' do
|
12
|
+
ActiveSupport.on_load(:action_view) do
|
13
|
+
include M3ta::Helpers
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/m3ta/version.rb
ADDED
data/lib/m3ta.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'm3ta/railtie'
|
4
|
+
|
5
|
+
module M3ta
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Builder
|
9
|
+
autoload :Controller
|
10
|
+
autoload :Helpers
|
11
|
+
autoload :Version
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def defaults(&block)
|
15
|
+
@defaults ||= Builder.new(I18n.translate(:m3ta, default: {}))
|
16
|
+
@defaults.tap { |b| b.apply(&block) if block_given? }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m3ta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RobL
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 7.0.4.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '7.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 7.0.4.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: factory_bot
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 6.2.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 6.2.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: faker
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.1.1
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.1.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec-rails
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 6.0.1
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 6.0.1
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop-rails
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 2.17.4
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.17.4
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.22.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.22.0
|
117
|
+
description: Define meta tags in your Rails app in defaults, i18n locales, controllers
|
118
|
+
and views.
|
119
|
+
email:
|
120
|
+
- contact@robl.me
|
121
|
+
executables: []
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- MIT-LICENSE
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- lib/m3ta.rb
|
129
|
+
- lib/m3ta/builder.rb
|
130
|
+
- lib/m3ta/controller.rb
|
131
|
+
- lib/m3ta/helpers.rb
|
132
|
+
- lib/m3ta/railtie.rb
|
133
|
+
- lib/m3ta/version.rb
|
134
|
+
homepage: https://github.com/braindeaf/m3ta
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata:
|
138
|
+
homepage_uri: https://github.com/braindeaf/m3ta
|
139
|
+
source_code_uri: https://github.com/braindeaf/m3ta
|
140
|
+
changelog_uri: https://github.com/braindeaf/m3ta/CHANGELOG.md
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.4.3
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Define meta tags in your Rails app
|
160
|
+
test_files: []
|