meta_tags_engine 1.0.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 +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +171 -0
- data/Rakefile +6 -0
- data/USAGE.md +138 -0
- data/app/models/current.rb +8 -0
- data/app/models/meta_tags.rb +109 -0
- data/lib/generators/meta_tags_engine/install_generator.rb +19 -0
- data/lib/generators/meta_tags_engine/templates/INSTALL_README +16 -0
- data/lib/generators/meta_tags_engine/templates/meta_tags_engine.rb +11 -0
- data/lib/meta_tags_engine/configuration.rb +14 -0
- data/lib/meta_tags_engine/engine.rb +20 -0
- data/lib/meta_tags_engine/version.rb +3 -0
- data/lib/meta_tags_engine.rb +18 -0
- metadata +88 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e71b5dde626b685519e459f434330433a568094b615b5c518ad32146372937d2
|
|
4
|
+
data.tar.gz: e19c98a8f24b59cb2270b75c1d8cbebf9b13a6bbc9a7e343112177ed1f23d009
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 48af1d02b3b0c60c87075e5f5d5ae4651bb9aacefe992cf625b9355af166ed189a40affbcfcf3e5a11ad60be83f355259705a0faa1870a65b66ce3f04565586a
|
|
7
|
+
data.tar.gz: fadfbe2146698989e813aa9e2005ae683d7572287514353feab9ef6d652410d3b9d50496e7e3b497aea13918e24d2d0bb4c24b13289793886ead0c5ae169b2cc
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 MetaTags Engine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# MetaTagsEngine
|
|
2
|
+
|
|
3
|
+
A comprehensive Rails Engine that provides easy-to-use meta tags functionality for SEO, including Open Graph and Twitter Cards support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 Easy SEO meta tags management
|
|
8
|
+
- 📱 Open Graph protocol support
|
|
9
|
+
- 🐦 Twitter Cards support
|
|
10
|
+
- 🎨 Customizable defaults
|
|
11
|
+
- 🔧 Simple configuration
|
|
12
|
+
- 📋 Object-based meta tag assignment
|
|
13
|
+
- 🚀 Rails 7+ compatible
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Add this line to your application's Gemfile:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem 'meta_tags_engine'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And then execute:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bundle install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or install it yourself as:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
gem install meta_tags_engine
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
After installation, run the generator to set up the engine:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
rails generate meta_tags_engine:install
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This will create an initializer file at `config/initializers/meta_tags_engine.rb`.
|
|
42
|
+
|
|
43
|
+
The engine provides a `Current` model with meta_tags functionality automatically.
|
|
44
|
+
|
|
45
|
+
**For apps with existing Current models, add this line:**
|
|
46
|
+
```ruby
|
|
47
|
+
attribute :meta_tags, default: -> { MetaTags.new }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
Configure the engine in `config/initializers/meta_tags_engine.rb`:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
MetaTagsEngine.configure do |config|
|
|
56
|
+
config.application_name = "My Awesome App"
|
|
57
|
+
config.default_title = "Welcome to My Awesome App"
|
|
58
|
+
config.default_description = "The best app for awesome things"
|
|
59
|
+
config.default_image = "opengraph.png"
|
|
60
|
+
config.default_twitter_site = "@myawesomeapp"
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
### Basic Usage
|
|
67
|
+
|
|
68
|
+
In your views, set meta tags like this:
|
|
69
|
+
|
|
70
|
+
```erb
|
|
71
|
+
<% Current.meta_tags.set(title: "About Us", description: "Learn more about our company") %>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Object-based Meta Tags
|
|
75
|
+
|
|
76
|
+
You can also set meta tags from an object by implementing a `to_meta_tags` method:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
class BlogPost < ApplicationRecord
|
|
80
|
+
def to_meta_tags
|
|
81
|
+
{
|
|
82
|
+
title: title,
|
|
83
|
+
description: excerpt,
|
|
84
|
+
image: featured_image.present? ? featured_image.url : nil,
|
|
85
|
+
og_type: "article"
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Then in your view:
|
|
92
|
+
|
|
93
|
+
```erb
|
|
94
|
+
<% Current.meta_tags.set_from(@blog_post) %>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Rendering Meta Tags
|
|
98
|
+
|
|
99
|
+
Add this to your application layout's `<head>` section:
|
|
100
|
+
|
|
101
|
+
```erb
|
|
102
|
+
<%= render Current.meta_tags %>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Available Attributes
|
|
106
|
+
|
|
107
|
+
You can set the following attributes:
|
|
108
|
+
|
|
109
|
+
- `site` - Site name (defaults to configured application_name)
|
|
110
|
+
- `title` - Page title
|
|
111
|
+
- `description` - Page description
|
|
112
|
+
- `image` - Image URL or asset pipeline path
|
|
113
|
+
- `current_url` - Canonical URL (auto-detected from request)
|
|
114
|
+
- `og_type` - Open Graph type (default: "website")
|
|
115
|
+
- `twitter_type` - Twitter card type (default: "summary")
|
|
116
|
+
- `twitter_site` - Twitter site handle
|
|
117
|
+
- `theme_color` - Browser theme color (default: "#ffffff")
|
|
118
|
+
- `canonical_url` - Canonical URL override
|
|
119
|
+
- `next_url` - Next page URL
|
|
120
|
+
- `prev_url` - Previous page URL
|
|
121
|
+
- `web_app_capable` - Mobile web app capability (default: true)
|
|
122
|
+
- `noindex` - Prevent search engine indexing
|
|
123
|
+
- `icons` - Array of favicon configurations
|
|
124
|
+
- `apple_touch_icon` - Apple touch icon path
|
|
125
|
+
- `separator` - Title separator (default: "|")
|
|
126
|
+
|
|
127
|
+
### Example Usage
|
|
128
|
+
|
|
129
|
+
```erb
|
|
130
|
+
<% Current.meta_tags.set(
|
|
131
|
+
title: "Product Details",
|
|
132
|
+
description: "Check out this amazing product",
|
|
133
|
+
image: @product.image.url,
|
|
134
|
+
og_type: "product",
|
|
135
|
+
twitter_type: "summary_large_image",
|
|
136
|
+
canonical_url: product_url(@product)
|
|
137
|
+
) %>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Generated HTML
|
|
141
|
+
|
|
142
|
+
The engine generates comprehensive meta tags including:
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<title>Product Details | My Awesome App</title>
|
|
146
|
+
<meta name="title" content="Product Details | My Awesome App">
|
|
147
|
+
<meta name="description" content="Check out this amazing product">
|
|
148
|
+
<meta property="og:type" content="product">
|
|
149
|
+
<meta property="og:url" content="https://example.com/products/1">
|
|
150
|
+
<meta property="og:title" content="Product Details | My Awesome App">
|
|
151
|
+
<meta property="og:description" content="Check out this amazing product">
|
|
152
|
+
<meta property="og:image" content="https://example.com/product-image.jpg">
|
|
153
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
154
|
+
<meta name="twitter:title" content="Product Details | My Awesome App">
|
|
155
|
+
<meta name="twitter:description" content="Check out this amazing product">
|
|
156
|
+
<meta name="twitter:image" content="https://example.com/product-image.jpg">
|
|
157
|
+
<!-- And more... -->
|
|
158
|
+
```
|
|
159
|
+
## Usage Guide
|
|
160
|
+
For a deeper dive into MetaTags features and implementation, head over to the full [usage guide](https://github.com/Nickiam7/MetaTags/blob/main/USAGE.md) for detailed instructions.
|
|
161
|
+
## Requirements
|
|
162
|
+
|
|
163
|
+
- Rails 7.0+
|
|
164
|
+
- Ruby 3.0+
|
|
165
|
+
|
|
166
|
+
## Contributing
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/USAGE.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Usage Examples
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
The MetaTagsEngine provides a `Current` model automatically. For apps with existing Current models, add this line:
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
attribute :meta_tags, default: -> { MetaTags.new }
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Usage in Views
|
|
12
|
+
|
|
13
|
+
```erb
|
|
14
|
+
<!-- Set basic meta tags -->
|
|
15
|
+
<% Current.meta_tags.set(
|
|
16
|
+
title: "About Our Company",
|
|
17
|
+
description: "Learn more about our mission, vision, and team"
|
|
18
|
+
) %>
|
|
19
|
+
|
|
20
|
+
<!-- Set meta tags with social media optimization -->
|
|
21
|
+
<% Current.meta_tags.set(
|
|
22
|
+
title: "Product Launch",
|
|
23
|
+
description: "Introducing our revolutionary new product",
|
|
24
|
+
image: asset_path("product-hero.jpg"),
|
|
25
|
+
og_type: "article",
|
|
26
|
+
twitter_type: "summary_large_image"
|
|
27
|
+
) %>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Object-based Meta Tags
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
# In your model (e.g., BlogPost)
|
|
34
|
+
class BlogPost < ApplicationRecord
|
|
35
|
+
def to_meta_tags
|
|
36
|
+
{
|
|
37
|
+
title: title,
|
|
38
|
+
description: excerpt.present? ? excerpt : description,
|
|
39
|
+
image: featured_image.attached? ? featured_image.url : nil,
|
|
40
|
+
og_type: "article",
|
|
41
|
+
twitter_type: "summary_large_image"
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# In your controller or view
|
|
47
|
+
<% Current.meta_tags.set_from(@blog_post) %>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Product/E-commerce Meta Tags
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
class Product < ApplicationRecord
|
|
54
|
+
def to_meta_tags
|
|
55
|
+
{
|
|
56
|
+
title: "#{name} - #{price_formatted}",
|
|
57
|
+
description: description.truncate(160),
|
|
58
|
+
image: main_image&.url,
|
|
59
|
+
og_type: "product",
|
|
60
|
+
twitter_type: "summary_large_image"
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Application Layout
|
|
67
|
+
|
|
68
|
+
```erb
|
|
69
|
+
<!DOCTYPE html>
|
|
70
|
+
<html>
|
|
71
|
+
<head>
|
|
72
|
+
<!-- Your meta tags will be rendered here -->
|
|
73
|
+
<%= render Current.meta_tags %>
|
|
74
|
+
|
|
75
|
+
<!-- Other head elements -->
|
|
76
|
+
<%= csrf_meta_tags %>
|
|
77
|
+
<%= csp_meta_tag %>
|
|
78
|
+
<%= stylesheet_link_tag "application" %>
|
|
79
|
+
<%= javascript_importmap_tags %>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
<%= yield %>
|
|
83
|
+
</body>
|
|
84
|
+
</html>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Configuration Examples
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
# config/initializers/meta_tags_engine.rb
|
|
91
|
+
|
|
92
|
+
MetaTagsEngine.configure do |config|
|
|
93
|
+
# Basic app information
|
|
94
|
+
config.application_name = "My Amazing App"
|
|
95
|
+
|
|
96
|
+
# Default meta tags for pages that don't set their own
|
|
97
|
+
config.default_title = "My Amazing App - The best app ever"
|
|
98
|
+
config.default_description = "Discover amazing features and join thousands of happy users"
|
|
99
|
+
config.default_image = "opengraph-default.png"
|
|
100
|
+
|
|
101
|
+
# Social media
|
|
102
|
+
config.default_twitter_site = "@myamazingapp"
|
|
103
|
+
end
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Advanced Usage
|
|
107
|
+
|
|
108
|
+
### Custom Separators
|
|
109
|
+
|
|
110
|
+
```erb
|
|
111
|
+
<% Current.meta_tags.set(
|
|
112
|
+
title: "Product Details",
|
|
113
|
+
separator: "•"
|
|
114
|
+
) %>
|
|
115
|
+
<!-- Results in: "Product Details • My Amazing App" -->
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### SEO-specific Meta Tags
|
|
119
|
+
|
|
120
|
+
```erb
|
|
121
|
+
<% Current.meta_tags.set(
|
|
122
|
+
title: "Blog Post",
|
|
123
|
+
canonical_url: blog_post_url(@post),
|
|
124
|
+
noindex: @post.draft?,
|
|
125
|
+
prev_url: @prev_post ? blog_post_url(@prev_post) : nil,
|
|
126
|
+
next_url: @next_post ? blog_post_url(@next_post) : nil
|
|
127
|
+
) %>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Mobile/PWA Meta Tags
|
|
131
|
+
|
|
132
|
+
```erb
|
|
133
|
+
<% Current.meta_tags.set(
|
|
134
|
+
theme_color: "#ff6b35",
|
|
135
|
+
web_app_capable: true,
|
|
136
|
+
apple_touch_icon: asset_path("app-icon-180.png")
|
|
137
|
+
) %>
|
|
138
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# A word of caution: It's easy to overdo a global singleton like Current and tangle your model as a result.
|
|
2
|
+
# Current should only be used for a few, top-level globals, like account, user, and request details.
|
|
3
|
+
# The attributes stuck in Current should be used by more or less all actions on all requests.
|
|
4
|
+
# If you start sticking controller-specific attributes in there, you're going to create a mess.
|
|
5
|
+
|
|
6
|
+
class Current < ActiveSupport::CurrentAttributes
|
|
7
|
+
attribute :meta_tags, default: -> { MetaTags.new }
|
|
8
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
class MetaTags
|
|
2
|
+
# Helps rendering title and meta tags consistently for SEO
|
|
3
|
+
#
|
|
4
|
+
# To set meta tags in a view:
|
|
5
|
+
#
|
|
6
|
+
# <% Current.meta_tags.set(title: "Example", description: "This is a page.") %>
|
|
7
|
+
#
|
|
8
|
+
# Meta tags can also be set from an object like a database record:
|
|
9
|
+
#
|
|
10
|
+
# <% Current.meta_tags.set_from(@blog_post) %>
|
|
11
|
+
#
|
|
12
|
+
# This will call `to_meta_tags` on the object which should return a Hash of title, description, etc.
|
|
13
|
+
#
|
|
14
|
+
# def to_meta_tags
|
|
15
|
+
# {
|
|
16
|
+
# title: name,
|
|
17
|
+
# description: short_description
|
|
18
|
+
# }
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# Render meta tags in the head tag:
|
|
22
|
+
#
|
|
23
|
+
# <%= render Current.meta_tags %>
|
|
24
|
+
|
|
25
|
+
include ActiveModel::Model
|
|
26
|
+
include ActiveModel::Attributes
|
|
27
|
+
|
|
28
|
+
class_attribute :default_title
|
|
29
|
+
class_attribute :default_description
|
|
30
|
+
class_attribute :default_image, default: nil
|
|
31
|
+
class_attribute :default_twitter_site
|
|
32
|
+
|
|
33
|
+
# Page details
|
|
34
|
+
attribute :site, default: -> { MetaTagsEngine.config.application_name }
|
|
35
|
+
attribute :title, default: -> { default_title } # 50 - 60 characters (for site + separator + title)
|
|
36
|
+
attribute :description, default: -> { default_description } # 140 - 160 characters recommended
|
|
37
|
+
attribute :image, default: -> { default_image } # A full URL or filename for an image in the asset pipeline
|
|
38
|
+
|
|
39
|
+
# Social media
|
|
40
|
+
attribute :current_url
|
|
41
|
+
attribute :og_type, default: "website" # website | profile | article | video.movie
|
|
42
|
+
attribute :twitter_type, default: "summary" # summary | summary_large_image
|
|
43
|
+
attribute :twitter_site, default: -> { default_twitter_site } # @username
|
|
44
|
+
|
|
45
|
+
# General meta tags
|
|
46
|
+
attribute :theme_color, default: "#ffffff"
|
|
47
|
+
attribute :canonical_url
|
|
48
|
+
attribute :next_url
|
|
49
|
+
attribute :prev_url
|
|
50
|
+
attribute :web_app_capable, default: true
|
|
51
|
+
attribute :noindex
|
|
52
|
+
attribute :icons, default: [{href: "/favicon.ico", sizes: :any}, {href: "/icon.svg", type: "image/svg+xml", sizes: :any}]
|
|
53
|
+
attribute :apple_touch_icon, default: "/apple-touch-icon.png"
|
|
54
|
+
|
|
55
|
+
# Separator for title & site
|
|
56
|
+
attribute :separator, default: "|"
|
|
57
|
+
|
|
58
|
+
def set(new_attributes)
|
|
59
|
+
assign_attributes(new_attributes.compact_blank)
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set_from(object)
|
|
64
|
+
assign_attributes(object.to_meta_tags.compact_blank)
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def render_in(view_context)
|
|
69
|
+
self.current_url ||= view_context.request.url
|
|
70
|
+
full_title = [view_context.content_for(:title) || title, site].compact.join(" #{separator} ")
|
|
71
|
+
|
|
72
|
+
# Only process image if it exists
|
|
73
|
+
image_url = if image.present?
|
|
74
|
+
image.start_with?("http") ? image : view_context.image_url(image)
|
|
75
|
+
else
|
|
76
|
+
nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
view_context.render inline: <<~CONTENT, locals: {full_title: full_title, image_url: image_url}.merge(attributes.symbolize_keys)
|
|
80
|
+
<%= tag.title full_title %>
|
|
81
|
+
<%= tag.meta name: :title, content: full_title %>
|
|
82
|
+
<%= tag.meta name: :description, content: description %>
|
|
83
|
+
<%= tag.meta property: "og:type", content: og_type %>
|
|
84
|
+
<%= tag.meta property: "og:url", content: current_url %>
|
|
85
|
+
<%= tag.meta property: "og:title", content: full_title %>
|
|
86
|
+
<%= tag.meta property: "og:description", content: description %>
|
|
87
|
+
<%= tag.meta(property: "og:image", content: image_url) if image_url.present? %>
|
|
88
|
+
<%= tag.meta name: "twitter:card", content: twitter_type %>
|
|
89
|
+
<%= tag.meta(name: "twitter:site", content: twitter_site) if twitter_site %>
|
|
90
|
+
<%= tag.meta name: "twitter:title", content: full_title %>
|
|
91
|
+
<%= tag.meta name: "twitter:description", content: description %>
|
|
92
|
+
<%= tag.meta(name: "twitter:image", content: image_url) if image_url.present? %>
|
|
93
|
+
<% icons.each do |attributes| %>
|
|
94
|
+
<%= tag.link rel: :icon, **attributes %>
|
|
95
|
+
<% end %>
|
|
96
|
+
<%= tag.link rel: "apple-touch-icon", href: apple_touch_icon %>
|
|
97
|
+
<%= tag.meta name: "application-name", content: site %>
|
|
98
|
+
<%= tag.link(name: :robots, content: :noindex) if noindex %>
|
|
99
|
+
<%= tag.meta(name: "mobile-web-app-capable", content: :yes) if web_app_capable %>
|
|
100
|
+
<%= tag.link(rel: :canonical, href: canonical_url) if canonical_url %>
|
|
101
|
+
<%= tag.link(rel: :prev, href: prev_url) if prev_url %>
|
|
102
|
+
<%= tag.link(rel: :next, href: next_url) if next_url %>
|
|
103
|
+
CONTENT
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def format
|
|
107
|
+
:html
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'rails/generators/base'
|
|
2
|
+
|
|
3
|
+
module MetaTagsEngine
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
|
7
|
+
|
|
8
|
+
desc "Creates MetaTagsEngine initializer"
|
|
9
|
+
|
|
10
|
+
def copy_initializer
|
|
11
|
+
template "meta_tags_engine.rb", "config/initializers/meta_tags_engine.rb"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def show_readme
|
|
15
|
+
readme "INSTALL_README" if behavior == :invoke
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
===============================================================================
|
|
2
|
+
|
|
3
|
+
MetaTagsEngine has been successfully installed!
|
|
4
|
+
|
|
5
|
+
The engine provides a Current model with meta_tags functionality.
|
|
6
|
+
You can now use Current.meta_tags in your views and controllers.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
<%= render Current.meta_tags %>
|
|
10
|
+
|
|
11
|
+
For apps with existing Current models, add this line:
|
|
12
|
+
attribute :meta_tags, default: -> { MetaTags.new }
|
|
13
|
+
|
|
14
|
+
Configure the engine in config/initializers/meta_tags_engine.rb
|
|
15
|
+
|
|
16
|
+
===============================================================================
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# MetaTagsEngine configuration
|
|
2
|
+
MetaTagsEngine.configure do |config|
|
|
3
|
+
# Set your application name
|
|
4
|
+
config.application_name = "My App"
|
|
5
|
+
|
|
6
|
+
# Set default meta tags (optional)
|
|
7
|
+
# config.default_title = "Default page title"
|
|
8
|
+
# config.default_description = "Default page description"
|
|
9
|
+
# config.default_image = "opengraph.png" # Use image from the asset pipeline
|
|
10
|
+
# config.default_twitter_site = "@username"
|
|
11
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module MetaTagsEngine
|
|
2
|
+
class Configuration
|
|
3
|
+
attr_accessor :application_name, :default_title, :default_description,
|
|
4
|
+
:default_image, :default_twitter_site
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@application_name = "My App"
|
|
8
|
+
@default_title = nil
|
|
9
|
+
@default_description = nil
|
|
10
|
+
@default_image = nil
|
|
11
|
+
@default_twitter_site = nil
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module MetaTagsEngine
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace MetaTagsEngine
|
|
4
|
+
|
|
5
|
+
config.generators do |g|
|
|
6
|
+
g.test_framework :rspec
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
initializer "meta_tags_engine.configure_meta_tags", after: :load_config_initializers do |app|
|
|
10
|
+
ActiveSupport::Reloader.to_prepare do
|
|
11
|
+
MetaTags.default_title = MetaTagsEngine.config.default_title
|
|
12
|
+
MetaTags.default_description = MetaTagsEngine.config.default_description
|
|
13
|
+
MetaTags.default_image = MetaTagsEngine.config.default_image
|
|
14
|
+
MetaTags.default_twitter_site = MetaTagsEngine.config.default_twitter_site
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "meta_tags_engine/version"
|
|
2
|
+
require "meta_tags_engine/engine"
|
|
3
|
+
require "meta_tags_engine/configuration"
|
|
4
|
+
|
|
5
|
+
module MetaTagsEngine
|
|
6
|
+
class << self
|
|
7
|
+
attr_accessor :configuration
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.configure
|
|
11
|
+
self.configuration ||= Configuration.new
|
|
12
|
+
yield(configuration)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.config
|
|
16
|
+
configuration || Configuration.new
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: meta_tags_engine
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nick McNeany
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-09-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 7.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: 7.0.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec-rails
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: A comprehensive Rails Engine that provides easy-to-use meta tags functionality
|
|
42
|
+
for SEO, including Open Graph and Twitter Cards support.
|
|
43
|
+
email:
|
|
44
|
+
- nick@railsyeah.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- MIT-LICENSE
|
|
50
|
+
- README.md
|
|
51
|
+
- Rakefile
|
|
52
|
+
- USAGE.md
|
|
53
|
+
- app/models/current.rb
|
|
54
|
+
- app/models/meta_tags.rb
|
|
55
|
+
- lib/generators/meta_tags_engine/install_generator.rb
|
|
56
|
+
- lib/generators/meta_tags_engine/templates/INSTALL_README
|
|
57
|
+
- lib/generators/meta_tags_engine/templates/meta_tags_engine.rb
|
|
58
|
+
- lib/meta_tags_engine.rb
|
|
59
|
+
- lib/meta_tags_engine/configuration.rb
|
|
60
|
+
- lib/meta_tags_engine/engine.rb
|
|
61
|
+
- lib/meta_tags_engine/version.rb
|
|
62
|
+
homepage: https://github.com/Nickiam7/MetaTags
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
65
|
+
metadata:
|
|
66
|
+
homepage_uri: https://github.com/Nickiam7/MetaTags
|
|
67
|
+
source_code_uri: https://github.com/Nickiam7/MetaTags
|
|
68
|
+
changelog_uri: https://github.com/Nickiam7/MetaTags/blob/main/CHANGELOG.md
|
|
69
|
+
post_install_message:
|
|
70
|
+
rdoc_options: []
|
|
71
|
+
require_paths:
|
|
72
|
+
- lib
|
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - ">="
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
requirements: []
|
|
84
|
+
rubygems_version: 3.0.3.1
|
|
85
|
+
signing_key:
|
|
86
|
+
specification_version: 4
|
|
87
|
+
summary: A Rails Engine for easy SEO meta tags management
|
|
88
|
+
test_files: []
|