active_seo 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +31 -35
- data/Rakefile +5 -5
- data/lib/active_seo/config.rb +23 -0
- data/lib/active_seo/loader.rb +20 -0
- data/lib/active_seo/meta.rb +19 -3
- data/lib/active_seo/seo_metum.rb +4 -0
- data/lib/active_seo/version.rb +1 -1
- data/lib/active_seo.rb +14 -27
- data/lib/generators/active_seo/templates/migration/migration.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e5cf1fba10d192d5fed5b93794b6d49830700a
|
4
|
+
data.tar.gz: d8e26d3483fe856f460bdd00ef272324ee5121bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14f6f75a483f39969e9ffb30af4e7781a4027b88f921ec5981f39551c27909f681f7f40074c5b09ba52f17bb66ebe65751b73fd0c06c4c14251f8ec9faebdf54
|
7
|
+
data.tar.gz: d3dfd528d884af2b7d544af0b5a22a7cd40d6ecd5035b88e94cf3d9e23066deef8c63921a372485798d786b91895afaf0485bcc0be6855a5ee1093c58c596415
|
data/README.md
CHANGED
@@ -16,49 +16,43 @@ gem 'active_seo'
|
|
16
16
|
|
17
17
|
And then execute:
|
18
18
|
|
19
|
-
|
20
|
-
$ bundle
|
21
|
-
```
|
19
|
+
$ bundle
|
22
20
|
|
23
21
|
Or install it yourself as:
|
24
22
|
|
25
|
-
|
26
|
-
$ gem install active_seo
|
27
|
-
```
|
23
|
+
$ gem install active_seo
|
28
24
|
|
29
25
|
Then run the generator that will create a migration for the SeoMetum model and an initializer:
|
30
26
|
|
31
|
-
|
32
|
-
$ rails g active_seo:install
|
33
|
-
```
|
27
|
+
$ rails g active_seo:install
|
34
28
|
|
35
29
|
And finally run the migrations:
|
36
30
|
|
37
|
-
|
38
|
-
$ rails db:migrate
|
39
|
-
```
|
31
|
+
$ rails db:migrate
|
40
32
|
|
41
33
|
## Usage
|
42
34
|
|
43
|
-
To add SEO meta support to an ActiveRecord model include the `ActiveSeo::Meta` Concern:
|
35
|
+
To add SEO meta support to an ActiveRecord model include the `ActiveSeo::Meta` Concern or use the `has_seo` class method:
|
44
36
|
|
45
37
|
```ruby
|
46
38
|
class Page < ApplicationRecord
|
39
|
+
# Using concern
|
47
40
|
include ActiveSeo::Meta
|
41
|
+
|
42
|
+
# Or using `has_seo` class method
|
43
|
+
has_seo
|
48
44
|
end
|
49
45
|
```
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
E.g. in your the form:
|
47
|
+
SeoMetum's attributes will be automatically delegated by your model with the `seo` prefix and you can use them in forms:
|
54
48
|
|
55
49
|
```erb
|
56
50
|
<%= form_for @page do |f| %>
|
57
51
|
<%= f.text_field :seo_title %>
|
58
|
-
<%= f.text_area
|
59
|
-
<%= f.text_area
|
60
|
-
<%= f.check_box
|
61
|
-
<%= f.check_box
|
52
|
+
<%= f.text_area :seo_description %>
|
53
|
+
<%= f.text_area :seo_keywords %>
|
54
|
+
<%= f.check_box :seo_noindex %>
|
55
|
+
<%= f.check_box :seo_nofollow %>
|
62
56
|
<% end %>
|
63
57
|
```
|
64
58
|
|
@@ -76,7 +70,7 @@ To get all SEO attributes:
|
|
76
70
|
|
77
71
|
## Configuration
|
78
72
|
|
79
|
-
The install generator will create an initializer
|
73
|
+
The install generator will create an initializer:
|
80
74
|
|
81
75
|
```ruby
|
82
76
|
ActiveSeo.setup do |config|
|
@@ -103,35 +97,41 @@ end
|
|
103
97
|
|
104
98
|
You can set global defaults for attribute validations, automatic meta generation, OpenGraph and Twitter meta.
|
105
99
|
|
106
|
-
Settings `title_fallback` and `description_fallback` can
|
100
|
+
Settings `title_fallback` and `description_fallback` can be a `Symbol` or an `Array` of symbols that reference a model attribute/method which will be used to autogenerate the title and description attributes. When using an `Array` the first attribute that returns a value will be used.
|
107
101
|
|
108
|
-
This behavior can also be configured on a model level
|
102
|
+
This behavior can also be configured on a model level:
|
109
103
|
|
110
104
|
```ruby
|
111
105
|
class Page < ApplicationRecord
|
106
|
+
# Using concern
|
112
107
|
include ActiveSeo::Meta
|
113
108
|
|
114
|
-
#
|
109
|
+
# With `seo_setup` method
|
115
110
|
seo_setup title_fallback: :name, description_fallback: [:content, :excerpt]
|
111
|
+
|
112
|
+
# Or using `has_seo` class method
|
113
|
+
has_seo title_fallback: :name, description_fallback: [:content, :excerpt]
|
116
114
|
end
|
117
115
|
```
|
118
116
|
|
119
|
-
## OpenGraph and Twitter
|
120
|
-
|
121
|
-
If you want to define non-global OpenGraph and Twitter configurations you can create a custom meta contextualizer.
|
117
|
+
## OpenGraph and Twitter
|
122
118
|
|
123
|
-
ActiveSeo will look for a class defined in the model
|
119
|
+
If you want to define non-global OpenGraph and Twitter configurations you can create a custom meta contextualizer. ActiveSeo will look for a class defined in the model:
|
124
120
|
|
125
121
|
```ruby
|
126
122
|
class Page < ApplicationRecord
|
123
|
+
# Using concern
|
127
124
|
include ActiveSeo::Meta
|
128
125
|
|
129
|
-
#
|
126
|
+
# With `seo_contextualizer` method
|
130
127
|
seo_contextualizer 'CustomContextualizer'
|
128
|
+
|
129
|
+
# Or using `has_seo` class method
|
130
|
+
has_seo contextualizer: 'CustomContextualizer'
|
131
131
|
end
|
132
132
|
```
|
133
133
|
|
134
|
-
|
134
|
+
Or for a class located in `app/contextualizers` with a name like `ModelContextualizer`.
|
135
135
|
|
136
136
|
```ruby
|
137
137
|
class PageContextualizer < ActiveSeo::Contextualizer
|
@@ -152,8 +152,6 @@ class PageContextualizer < ActiveSeo::Contextualizer
|
|
152
152
|
end
|
153
153
|
```
|
154
154
|
|
155
|
-
#### Notes
|
156
|
-
|
157
155
|
Inside the contextualizer you can define values using a `Proc` which gives you access to the record, a `Symbol` which will look for an attibute or method first inside the contextualizer and then in the model, or a `String` for a static value.
|
158
156
|
|
159
157
|
## Printing SEO meta
|
@@ -168,9 +166,7 @@ So, if you're using Meta Tags you can do the following:
|
|
168
166
|
|
169
167
|
## Development
|
170
168
|
|
171
|
-
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.
|
172
|
-
|
173
|
-
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).
|
169
|
+
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. To install this gem onto your local machine, run `bundle exec rake install`.
|
174
170
|
|
175
171
|
## Contributing
|
176
172
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
8
|
end
|
9
9
|
|
10
10
|
task :default => :test
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveSeo
|
2
|
+
class Config < Hashie::Dash
|
3
|
+
# Set properties and defaults
|
4
|
+
property :title_limit, default: 70
|
5
|
+
property :description_limit, default: 160
|
6
|
+
property :keywords_limit, default: 255
|
7
|
+
property :title_fallback, default: true
|
8
|
+
property :description_fallback, default: true
|
9
|
+
property :generate_keywords, default: true
|
10
|
+
property :opengraph, default: {}
|
11
|
+
property :twitter, default: {}
|
12
|
+
|
13
|
+
def opengraph_setup(&block)
|
14
|
+
self.opengraph = Hashie::Mash.new
|
15
|
+
yield self.opengraph
|
16
|
+
end
|
17
|
+
|
18
|
+
def twitter_setup(&block)
|
19
|
+
self.twitter = Hashie::Mash.new
|
20
|
+
yield self.twitter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActiveSeo
|
2
|
+
module Loader
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
# Helper to include ActiveSeo::Meta
|
7
|
+
def has_seo(options={})
|
8
|
+
include ActiveSeo::Meta
|
9
|
+
|
10
|
+
if options.present?
|
11
|
+
seo_setup options.except(:contextualizer)
|
12
|
+
end
|
13
|
+
|
14
|
+
if options[:contextualizer].present?
|
15
|
+
seo_contextualizer options[:contextualizer]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/active_seo/meta.rb
CHANGED
@@ -14,14 +14,30 @@ module ActiveSeo
|
|
14
14
|
self.seo_config = ActiveSeo.config
|
15
15
|
|
16
16
|
# Has associations
|
17
|
-
has_one :
|
17
|
+
has_one :seo_metum, as: :seoable, class_name: 'ActiveSeo::SeoMetum', autosave: true, dependent: :destroy
|
18
18
|
|
19
19
|
# Delegate attributes
|
20
|
-
delegate_attributes to: :
|
20
|
+
delegate_attributes to: :seo_metum, prefix: 'seo', allow_nil: true
|
21
21
|
|
22
22
|
# Add validations
|
23
23
|
define_seo_validations
|
24
|
-
|
24
|
+
|
25
|
+
# Action callbacks
|
26
|
+
before_validation do
|
27
|
+
ActiveSeo::Helpers.sanitize_keywords(seo_keywords) if seo_keywords?
|
28
|
+
end
|
29
|
+
|
30
|
+
before_save do
|
31
|
+
seo_foreign = self.class.seo_meta_attribute_names.map(&:to_s)
|
32
|
+
seo_current = seo_foreign.map { |n| send(n) }
|
33
|
+
seo_foreign = seo_foreign.map { |a| a.sub('seo_', '') }
|
34
|
+
seo_default = ActiveSeo::SeoMetum.column_defaults.select { |n, _d| seo_foreign.include?(n) }.values
|
35
|
+
seo_changes = (seo_current - seo_default).reject { |v| (v.is_a?(String) && v.blank?) || v.nil? }
|
36
|
+
|
37
|
+
if seo_changes.empty?
|
38
|
+
self.seo_metum = nil
|
39
|
+
end
|
40
|
+
end
|
25
41
|
end
|
26
42
|
|
27
43
|
class_methods do
|
data/lib/active_seo/seo_metum.rb
CHANGED
@@ -3,6 +3,10 @@ module ActiveSeo
|
|
3
3
|
# Set table name
|
4
4
|
self.table_name = 'seo_meta'
|
5
5
|
|
6
|
+
# Set attributes
|
7
|
+
attribute :noindex, :boolean, default: false
|
8
|
+
attribute :nofollow, :boolean, default: false
|
9
|
+
|
6
10
|
# Belongs associations
|
7
11
|
belongs_to :seoable, polymorphic: true, optional: true
|
8
12
|
end
|
data/lib/active_seo/version.rb
CHANGED
data/lib/active_seo.rb
CHANGED
@@ -2,37 +2,20 @@ require 'active_support'
|
|
2
2
|
require 'action_view'
|
3
3
|
require 'hashie'
|
4
4
|
require 'active_delegate'
|
5
|
-
require 'active_seo/helpers'
|
6
|
-
require 'active_seo/contextualize'
|
7
|
-
require 'active_seo/contextualizer'
|
8
|
-
require 'active_seo/meta'
|
9
|
-
require 'active_seo/seo_metum'
|
10
|
-
require 'active_seo/seo_meta'
|
11
5
|
require 'active_seo/version'
|
12
6
|
|
13
7
|
module ActiveSeo
|
14
|
-
|
15
|
-
class Config < Hashie::Dash
|
16
|
-
# Set properties and defaults
|
17
|
-
property :title_limit, default: 70
|
18
|
-
property :description_limit, default: 160
|
19
|
-
property :keywords_limit, default: 255
|
20
|
-
property :title_fallback, default: true
|
21
|
-
property :description_fallback, default: true
|
22
|
-
property :generate_keywords, default: true
|
23
|
-
property :opengraph, default: {}
|
24
|
-
property :twitter, default: {}
|
8
|
+
extend ActiveSupport::Concern
|
25
9
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
10
|
+
# Autoload modules
|
11
|
+
autoload :Config, 'active_seo/config'
|
12
|
+
autoload :Helpers, 'active_seo/helpers'
|
13
|
+
autoload :Contextualize, 'active_seo/contextualize'
|
14
|
+
autoload :Contextualizer, 'active_seo/contextualizer'
|
15
|
+
autoload :Meta, 'active_seo/meta'
|
16
|
+
autoload :SeoMeta, 'active_seo/seo_meta'
|
17
|
+
autoload :SeoMetum, 'active_seo/seo_metum'
|
18
|
+
autoload :Loader, 'active_seo/loader'
|
36
19
|
|
37
20
|
# Set attr accessors
|
38
21
|
mattr_accessor :config
|
@@ -45,3 +28,7 @@ module ActiveSeo
|
|
45
28
|
yield config
|
46
29
|
end
|
47
30
|
end
|
31
|
+
|
32
|
+
ActiveSupport.on_load(:active_record) do
|
33
|
+
include ActiveSeo::Loader
|
34
|
+
end
|
@@ -4,8 +4,8 @@ class CreateSeoMeta < ActiveRecord::Migration[5.0]
|
|
4
4
|
t.string :title
|
5
5
|
t.text :description
|
6
6
|
t.text :keywords
|
7
|
-
t.boolean :noindex
|
8
|
-
t.boolean :nofollow
|
7
|
+
t.boolean :noindex, default: false
|
8
|
+
t.boolean :nofollow, default: false
|
9
9
|
t.integer :seoable_id, null: false
|
10
10
|
t.string :seoable_type, null: false
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_seo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olibia Tsati
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -122,9 +122,11 @@ files:
|
|
122
122
|
- README.md
|
123
123
|
- Rakefile
|
124
124
|
- lib/active_seo.rb
|
125
|
+
- lib/active_seo/config.rb
|
125
126
|
- lib/active_seo/contextualize.rb
|
126
127
|
- lib/active_seo/contextualizer.rb
|
127
128
|
- lib/active_seo/helpers.rb
|
129
|
+
- lib/active_seo/loader.rb
|
128
130
|
- lib/active_seo/meta.rb
|
129
131
|
- lib/active_seo/seo_meta.rb
|
130
132
|
- lib/active_seo/seo_metum.rb
|