seorel 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -22
- data/lib/generators/seorel/install_generator.rb +30 -0
- data/lib/{seorel → generators/seorel/templates}/initializer.rb +8 -0
- data/lib/{seorel → generators/seorel/templates}/migration.rb +0 -2
- data/lib/generators/seorel/templates/seorel.en.yml +21 -0
- data/lib/seorel.rb +1 -2
- data/lib/seorel/{config.rb → configuration.rb} +34 -24
- data/lib/seorel/controller/params.rb +44 -34
- data/lib/seorel/engine.rb +1 -0
- data/lib/seorel/helper.rb +5 -33
- data/lib/seorel/helper/base.rb +54 -0
- data/lib/seorel/helper/generic.rb +23 -0
- data/lib/seorel/helper/manager.rb +37 -0
- data/lib/seorel/helper/open_graph.rb +50 -0
- data/lib/seorel/helper/twitter.rb +45 -0
- data/lib/seorel/version.rb +1 -1
- metadata +13 -7
- data/lib/generators/seorel_generator.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9be1f063d4b6922248d3215633a98028d3f7cce1
|
4
|
+
data.tar.gz: 1494c970b2bc4ad181e78eab57928bd30694c9c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea6d3f1b88a10a0597364535d69a3507a00ee8366e2b6a44e7e8f2ad8b657ef52318e3edd630edbb04b1d0ba0679d6d66b416ecdde772d29b1c54050f58b3221
|
7
|
+
data.tar.gz: 9619a225614c03a932bf1ac28d9f70fa9e85165b5790d74747a74d78b18e7c946299664174f673d68d646e779ba544fd7e9e41516c619c8b62dfad192bdcb8ec
|
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
Ruby on Rails SEO Metatags plugins for ActiveRecord models
|
4
4
|
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/seorel.
|
6
|
-
[![Code Climate](https://codeclimate.com/github/dalpo/seorel.
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/seorel.svg)](https://badge.fury.io/rb/seorel)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/dalpo/seorel/badges/gpa.svg)](https://codeclimate.com/github/dalpo/seorel)
|
7
7
|
[![Build Status](https://travis-ci.org/dalpo/seorel.svg?branch=master)](https://travis-ci.org/dalpo/seorel)
|
8
8
|
|
9
9
|
## Rails Setup
|
@@ -12,7 +12,7 @@ Ruby on Rails SEO Metatags plugins for ActiveRecord models
|
|
12
12
|
`Gemfile.rb`:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'seorel', '~> 0.
|
15
|
+
gem 'seorel', '~> 0.3.0'
|
16
16
|
|
17
17
|
# the edge version can be had using:
|
18
18
|
# gem 'seorel', github: 'dalpo/seorel'
|
@@ -21,40 +21,46 @@ gem 'seorel', '~> 0.2.3'
|
|
21
21
|
`Console`:
|
22
22
|
```bash
|
23
23
|
$ bundle install
|
24
|
-
$ bundle exec rails generate seorel
|
24
|
+
$ bundle exec rails generate seorel:install
|
25
25
|
$ bundle exec rake db:migrate
|
26
26
|
```
|
27
27
|
|
28
|
-
|
28
|
+
It will generate the `seorel.rb` initializer and a new migration.
|
29
29
|
|
30
|
-
|
31
|
-
% rails generate seorel:config
|
32
|
-
```
|
30
|
+
### Configurations
|
33
31
|
|
34
|
-
|
32
|
+
You could change default meta tags values into the seorel initializer:
|
35
33
|
|
36
34
|
```ruby
|
37
35
|
Seorel.configure do |config|
|
36
|
+
config.default_title = 'My default page title goes here'
|
38
37
|
# config.default_prepend_title = nil
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
config.default_append_title = ' / Every title will be appended with this string'
|
39
|
+
|
40
|
+
config.default_description = 'Lorem ipsum sit dolor...'
|
42
41
|
# config.default_prepend_description = nil
|
43
|
-
# config.default_description = nil
|
44
42
|
# config.default_append_description = nil
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
|
44
|
+
config.default_image = 'http://www.example.com/share_image.png'
|
45
|
+
|
48
46
|
# config.store_seorel_if = :empty # Available values :empty | :changed
|
47
|
+
|
48
|
+
config.default_og_metas = {
|
49
|
+
type: 'website'
|
50
|
+
}
|
51
|
+
|
52
|
+
config.default_twitter_metas = {
|
53
|
+
card: 'summary_large_image'
|
54
|
+
}
|
49
55
|
end
|
50
56
|
```
|
51
57
|
|
52
|
-
|
53
58
|
## Usage
|
54
59
|
|
55
|
-
###
|
60
|
+
### Usage with an active record model
|
61
|
+
|
62
|
+
Given a sample model Post:
|
56
63
|
|
57
|
-
For instance generate a post model:
|
58
64
|
```ruby
|
59
65
|
rails generate model post title:string description:text, publish_date:date
|
60
66
|
```
|
@@ -63,7 +69,9 @@ Edit `app/models/post.rb`:
|
|
63
69
|
```ruby
|
64
70
|
class Post < ActiveRecord::Base
|
65
71
|
extend Seorelify
|
66
|
-
seorelify
|
72
|
+
seorelify title: :customized_title, description: :description, image: :share_image
|
73
|
+
# Or more simply:
|
74
|
+
# seorelify :customized_title, :description, :share_image
|
67
75
|
|
68
76
|
def customized_title
|
69
77
|
"THE BLOG: #{self.title}"
|
@@ -147,7 +155,7 @@ In your layout <head></head> section just call the `render_meta_tags
|
|
147
155
|
|
148
156
|
```html
|
149
157
|
<head>
|
150
|
-
<%=render_meta_tags %>
|
158
|
+
<%= render_meta_tags %>
|
151
159
|
...
|
152
160
|
</head>
|
153
161
|
```
|
@@ -168,7 +176,7 @@ Submitting a Pull Request:
|
|
168
176
|
|
169
177
|
## This project rocks and uses MIT-LICENSE.
|
170
178
|
|
171
|
-
Copyright
|
179
|
+
Copyright 2016 Andrea Dal Ponte
|
172
180
|
|
173
181
|
Permission is hereby granted, free of charge, to any person obtaining
|
174
182
|
a copy of this software and associated documentation files (the
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require "rails/generators/active_record"
|
3
|
+
|
4
|
+
module Seorel
|
5
|
+
# This generator adds a migration and aa configuration initializer
|
6
|
+
class InstallGenerator < ActiveRecord::Generators::Base
|
7
|
+
# ActiveRecord::Generators::Base inherits from Rails::Generators::NamedBase which requires a NAME parameter for the
|
8
|
+
argument :name, type: :string, default: 'random_name'
|
9
|
+
|
10
|
+
class_option :'skip-migration', type: :boolean, desc: "Don't generate a migration for the seorel table"
|
11
|
+
class_option :'skip-initializer', type: :boolean, desc: "Don't generate an initializer"
|
12
|
+
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
|
15
|
+
# Copies the migration template to db/migrate.
|
16
|
+
def copy_files
|
17
|
+
return if options['skip-migration']
|
18
|
+
migration_template 'migration.rb', 'db/migrate/create_seorel_seorels.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_initializer
|
22
|
+
return if options['skip-initializer']
|
23
|
+
copy_file 'initializer.rb', 'config/initializers/seorel.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
def cpoy_sample_locale
|
27
|
+
copy_file 'seorel.en.yml', 'config/locales/seorel.en.yml'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -11,4 +11,12 @@ Seorel.configure do |config|
|
|
11
11
|
# config.default_image = nil
|
12
12
|
#
|
13
13
|
# config.store_seorel_if = :empty # Available values :empty | :changed
|
14
|
+
|
15
|
+
# config.default_og_metas = {
|
16
|
+
# type: 'website'
|
17
|
+
# }
|
18
|
+
|
19
|
+
# config.default_twitter_metas = {
|
20
|
+
# card: 'summary_large_image'
|
21
|
+
# }
|
14
22
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
en:
|
2
|
+
seorel:
|
3
|
+
# Available keys:
|
4
|
+
#
|
5
|
+
# controller_name:
|
6
|
+
# action_name:
|
7
|
+
# prepend_title: '...'
|
8
|
+
# title: '...'
|
9
|
+
# append_title: '...'
|
10
|
+
#
|
11
|
+
# prepend_description: '...'
|
12
|
+
# description: '...'
|
13
|
+
# append_description: '...'
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Example for a PostsController:
|
17
|
+
#
|
18
|
+
# posts:
|
19
|
+
# index:
|
20
|
+
# title: 'My title tag content for posts#index goes here'
|
21
|
+
# description: 'My description meta tag content for posts#index goes here'
|
data/lib/seorel.rb
CHANGED
@@ -3,7 +3,7 @@ end
|
|
3
3
|
|
4
4
|
###
|
5
5
|
# Load Seorel components
|
6
|
-
require 'seorel/
|
6
|
+
require 'seorel/configuration'
|
7
7
|
require 'seorel/engine'
|
8
8
|
require 'seorel/seorel'
|
9
9
|
require 'seorel/model/base'
|
@@ -14,4 +14,3 @@ require 'seorel/controller/class_methods'
|
|
14
14
|
require 'seorel/controller/params'
|
15
15
|
require 'seorel/seorelify'
|
16
16
|
require 'seorel/helper'
|
17
|
-
|
@@ -2,21 +2,7 @@
|
|
2
2
|
require 'active_support/configurable'
|
3
3
|
|
4
4
|
module Seorel
|
5
|
-
|
6
|
-
# Seorel.configure do |config|
|
7
|
-
# config.default_default_title = 10
|
8
|
-
# end
|
9
|
-
def self.configure(&block)
|
10
|
-
yield @config ||= Seorel::Configuration.new
|
11
|
-
end
|
12
|
-
|
13
|
-
# Global settings for Seorel
|
14
|
-
def self.config
|
15
|
-
@config
|
16
|
-
end
|
17
|
-
|
18
|
-
# need a Class for 3.0
|
19
|
-
class Configuration #:nodoc:
|
5
|
+
class Configuration
|
20
6
|
include ActiveSupport::Configurable
|
21
7
|
|
22
8
|
config_accessor :default_prepend_title
|
@@ -27,6 +13,8 @@ module Seorel
|
|
27
13
|
config_accessor :default_append_description
|
28
14
|
config_accessor :default_image
|
29
15
|
config_accessor :store_seorel_if
|
16
|
+
config_accessor :default_og_metas
|
17
|
+
config_accessor :default_twitter_metas
|
30
18
|
|
31
19
|
def param_name
|
32
20
|
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
@@ -36,16 +24,38 @@ module Seorel
|
|
36
24
|
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
37
25
|
singleton_class.class_eval writer, __FILE__, line
|
38
26
|
class_eval writer, __FILE__, line
|
27
|
+
|
28
|
+
def initialize_defaults
|
29
|
+
self.default_prepend_title = nil
|
30
|
+
self.default_title = nil
|
31
|
+
self.default_append_title = nil
|
32
|
+
self.default_prepend_description = nil
|
33
|
+
self.default_description = nil
|
34
|
+
self.default_append_description = nil
|
35
|
+
self.default_image = nil
|
36
|
+
self.store_seorel_if = :empty
|
37
|
+
self.default_og_metas = {}
|
38
|
+
self.default_twitter_metas = {}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Global settings for Seorel
|
43
|
+
def self.config
|
44
|
+
@config ||= ::Seorel::Configuration.new.tap do |conf|
|
45
|
+
conf.initialize_defaults
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Configures global settings for Seorel
|
50
|
+
# Seorel.configure do |config|
|
51
|
+
# config.default_default_title = 'Default website title'
|
52
|
+
# end
|
53
|
+
def self.configure(&block)
|
54
|
+
yield(config)
|
39
55
|
end
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
config
|
44
|
-
config.default_append_title = nil
|
45
|
-
config.default_prepend_description = nil
|
46
|
-
config.default_description = nil
|
47
|
-
config.default_append_description = nil
|
48
|
-
config.default_image = nil
|
49
|
-
config.store_seorel_if = :empty
|
57
|
+
# Reset global settings for Seorel
|
58
|
+
def self.reset!
|
59
|
+
@config = nil
|
50
60
|
end
|
51
61
|
end
|
@@ -10,7 +10,7 @@ module Seorel
|
|
10
10
|
config_accessor :description
|
11
11
|
config_accessor :image
|
12
12
|
|
13
|
-
def initialize(controller)
|
13
|
+
def initialize(controller = nil)
|
14
14
|
@controller = controller
|
15
15
|
end
|
16
16
|
|
@@ -34,58 +34,68 @@ module Seorel
|
|
34
34
|
config.image || default_options.default_image
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
37
|
+
def open_graph_extras
|
38
|
+
default_options.default_og_metas
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def twitter_extras
|
42
|
+
default_options.default_twitter_metas
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
::Seorel.config
|
47
|
-
end
|
45
|
+
protected
|
48
46
|
|
49
|
-
|
50
|
-
I18n.t i18n_path(key), default: (default || '')
|
51
|
-
end
|
47
|
+
attr_reader :controller
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
def base_title
|
50
|
+
(config.title || self.lookup_title).html_safe
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
def base_description
|
54
|
+
(config.description || self.lookup_description).html_safe
|
55
|
+
end
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
def default_options
|
58
|
+
::Seorel.config
|
59
|
+
end
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
def lookup_i18n(key, default = nil)
|
62
|
+
I18n.t i18n_path(key), default: (default || '')
|
63
|
+
end
|
68
64
|
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
def lookup_prepend_title
|
66
|
+
lookup_i18n :prepend_title, default_options.default_prepend_title
|
67
|
+
end
|
72
68
|
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
def lookup_title
|
70
|
+
lookup_i18n :title, default_options.default_title
|
71
|
+
end
|
76
72
|
|
77
|
-
|
73
|
+
def lookup_append_title
|
74
|
+
lookup_i18n :append_title, default_options.default_append_title
|
75
|
+
end
|
76
|
+
|
77
|
+
def lookup_prepend_description
|
78
|
+
lookup_i18n :prepend_description, default_options.default_prepend_description
|
79
|
+
end
|
80
|
+
|
81
|
+
def lookup_description
|
82
|
+
lookup_i18n :description, default_options.default_description
|
83
|
+
end
|
78
84
|
|
79
|
-
def
|
80
|
-
|
85
|
+
def lookup_append_description
|
86
|
+
lookup_i18n :append_description, default_options.default_append_description
|
81
87
|
end
|
82
88
|
|
83
89
|
def controller_name
|
84
|
-
controller
|
90
|
+
if controller
|
91
|
+
controller.class.name.underscore.gsub(/_controller$/, '')
|
92
|
+
else
|
93
|
+
'undefined'
|
94
|
+
end
|
85
95
|
end
|
86
96
|
|
87
97
|
def action_name
|
88
|
-
controller.action_name
|
98
|
+
controller ? controller.action_name : 'undefined'
|
89
99
|
end
|
90
100
|
|
91
101
|
def i18n_path(key)
|
data/lib/seorel/engine.rb
CHANGED
data/lib/seorel/helper.rb
CHANGED
@@ -1,41 +1,13 @@
|
|
1
|
+
require 'seorel/helper/manager'
|
2
|
+
|
1
3
|
module Seorel
|
2
4
|
module Helper
|
3
|
-
def
|
4
|
-
|
5
|
-
"#{locale[0..1].downcase}_#{locale[3..4].upcase}"
|
5
|
+
def seorel_manager
|
6
|
+
@seorel_manager ||= ::Seorel::Helper::Manager.new(request, seorel_params)
|
6
7
|
end
|
7
8
|
|
8
9
|
def render_meta_tags
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def render_title
|
13
|
-
content_tag :title, seorel_params.title
|
14
|
-
end
|
15
|
-
|
16
|
-
def render_description
|
17
|
-
content_tag :meta, nil, name: 'description', content: seorel_params.description
|
18
|
-
end
|
19
|
-
|
20
|
-
def render_open_graph
|
21
|
-
[
|
22
|
-
content_tag(:meta, nil, property: 'og:type', content: 'website'),
|
23
|
-
content_tag(:meta, nil, property: 'og:url', content: request.url),
|
24
|
-
content_tag(:meta, nil, property: 'og:title', content: seorel_params.title),
|
25
|
-
content_tag(:meta, nil, property: 'og:description', content: seorel_params.description),
|
26
|
-
content_tag(:meta, nil, property: 'og:image', content: seorel_params.image),
|
27
|
-
content_tag(:meta, nil, property: 'og:locale', content: seorel_locale)
|
28
|
-
].join("\n").html_safe
|
29
|
-
end
|
30
|
-
|
31
|
-
def render_twitter_cards
|
32
|
-
[
|
33
|
-
content_tag(:meta, nil, name: 'twitter:card', content: 'summary_large_image'),
|
34
|
-
content_tag(:meta, nil, name: 'twitter:url', content: request.url),
|
35
|
-
content_tag(:meta, nil, name: 'twitter:title', content: seorel_params.title),
|
36
|
-
content_tag(:meta, nil, name: 'twitter:description', content: seorel_params.description),
|
37
|
-
content_tag(:meta, nil, name: 'twitter:image', content: seorel_params.image)
|
38
|
-
].join("\n").html_safe
|
10
|
+
seorel_manager.render
|
39
11
|
end
|
40
12
|
end
|
41
13
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# require 'action_view/helpers/tag_helper/capture_helper'
|
2
|
+
# require 'action_view/helpers/tag_helper'
|
3
|
+
|
4
|
+
# encoding: utf-8
|
5
|
+
module Seorel
|
6
|
+
module Helper
|
7
|
+
class Base
|
8
|
+
# include ActionView::Helpers::TagHelper
|
9
|
+
|
10
|
+
attr_reader :request, :params
|
11
|
+
|
12
|
+
delegate :title, :description, :image, to: :params
|
13
|
+
|
14
|
+
def initialize(request, params)
|
15
|
+
@request = request
|
16
|
+
@params = params
|
17
|
+
end
|
18
|
+
|
19
|
+
def helpers
|
20
|
+
ActionController::Base.helpers
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :h, :helpers
|
24
|
+
|
25
|
+
# def h.content_tag(*args)
|
26
|
+
# ActionView::Helpers::TagHelper.h.content_tag(*args)
|
27
|
+
# end
|
28
|
+
|
29
|
+
def locale
|
30
|
+
if I18n.locale.to_s.size == 2
|
31
|
+
"#{I18n.locale}_#{I18n.locale.to_s.upcase}"
|
32
|
+
else
|
33
|
+
I18n.locale
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def image_url
|
38
|
+
if /^(http|https|\/\/)/.match(image)
|
39
|
+
image
|
40
|
+
else
|
41
|
+
"#{request.protocol}#{request.host_with_port}#{image}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def all
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
|
49
|
+
def render
|
50
|
+
all.join.html_safe
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'seorel/helper/base'
|
2
|
+
|
3
|
+
# encoding: utf-8
|
4
|
+
module Seorel
|
5
|
+
module Helper
|
6
|
+
class Generic < Base
|
7
|
+
def title_tag
|
8
|
+
h.content_tag :title, title
|
9
|
+
end
|
10
|
+
|
11
|
+
def description_tag
|
12
|
+
h.content_tag :meta, nil, name: 'description', content: params.description
|
13
|
+
end
|
14
|
+
|
15
|
+
def all
|
16
|
+
[
|
17
|
+
title_tag,
|
18
|
+
description_tag
|
19
|
+
].compact
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'seorel/helper/generic'
|
2
|
+
require 'seorel/helper/open_graph'
|
3
|
+
require 'seorel/helper/twitter'
|
4
|
+
|
5
|
+
# encoding: utf-8
|
6
|
+
module Seorel
|
7
|
+
module Helper
|
8
|
+
class Manager
|
9
|
+
attr_reader :request, :params
|
10
|
+
|
11
|
+
def initialize(request, params)
|
12
|
+
@request = request
|
13
|
+
@params = params
|
14
|
+
end
|
15
|
+
|
16
|
+
def generic
|
17
|
+
@generic ||= ::Seorel::Helper::Generic.new(request, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def open_graph
|
21
|
+
@open_graph ||= ::Seorel::Helper::OpenGraph.new(request, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def twitter
|
25
|
+
@twitter ||= ::Seorel::Helper::Twitter.new(request, params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def all
|
29
|
+
(generic.all + open_graph.all + twitter.all)
|
30
|
+
end
|
31
|
+
|
32
|
+
def render
|
33
|
+
all.join.html_safe
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'seorel/helper/base'
|
2
|
+
|
3
|
+
# encoding: utf-8
|
4
|
+
module Seorel
|
5
|
+
module Helper
|
6
|
+
class OpenGraph < Base
|
7
|
+
def title_tag
|
8
|
+
h.content_tag :meta, nil, property: 'og:title', content: title
|
9
|
+
end
|
10
|
+
|
11
|
+
def description_tag
|
12
|
+
h.content_tag :meta, nil, property: 'og:description', content: description
|
13
|
+
end
|
14
|
+
|
15
|
+
def locale_tag
|
16
|
+
h.content_tag(:meta, nil, property: 'og:locale', content: locale)
|
17
|
+
end
|
18
|
+
|
19
|
+
def image_tag
|
20
|
+
h.content_tag(:meta, nil, property: 'og:image', content: image_url) if image
|
21
|
+
end
|
22
|
+
|
23
|
+
def url_tag
|
24
|
+
h.content_tag(:meta, nil, property: 'og:url', content: request.url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def custom_tags
|
28
|
+
params.open_graph_extras.reduce([]) do |data, (key, value)|
|
29
|
+
data.push custum_tag(key, value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def all
|
34
|
+
([
|
35
|
+
title_tag,
|
36
|
+
description_tag,
|
37
|
+
locale_tag,
|
38
|
+
image_tag,
|
39
|
+
url_tag
|
40
|
+
] + custom_tags).compact
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def custum_tag(key, value)
|
46
|
+
h.content_tag(:meta, nil, property: "og:#{key}", content: value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'seorel/helper/base'
|
2
|
+
|
3
|
+
# encoding: utf-8
|
4
|
+
module Seorel
|
5
|
+
module Helper
|
6
|
+
class Twitter < Base
|
7
|
+
def title_tag
|
8
|
+
h.content_tag :meta, nil, name: 'twitter:title', content: title
|
9
|
+
end
|
10
|
+
|
11
|
+
def description_tag
|
12
|
+
h.content_tag :meta, nil, name: 'twitter:description', content: description
|
13
|
+
end
|
14
|
+
|
15
|
+
def image_tag
|
16
|
+
h.content_tag(:meta, nil, name: 'twitter:image', content: image_url) if image
|
17
|
+
end
|
18
|
+
|
19
|
+
def url_tag
|
20
|
+
h.content_tag(:meta, nil, name: 'twitter:url', content: request.url)
|
21
|
+
end
|
22
|
+
|
23
|
+
def custom_tags
|
24
|
+
params.twitter_extras.reduce([]) do |data, (key, value)|
|
25
|
+
data.push custum_tag(key, value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def all
|
30
|
+
([
|
31
|
+
title_tag,
|
32
|
+
description_tag,
|
33
|
+
image_tag,
|
34
|
+
url_tag
|
35
|
+
] + custom_tags).compact
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def custum_tag(key, value)
|
41
|
+
h.content_tag(:meta, nil, name: "twitter:#{key}", content: value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/seorel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seorel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Dal Ponte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -106,16 +106,22 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- config/locales/en.seorel.yml
|
108
108
|
- config/locales/it.seorel.yml
|
109
|
-
- lib/generators/
|
109
|
+
- lib/generators/seorel/install_generator.rb
|
110
|
+
- lib/generators/seorel/templates/initializer.rb
|
111
|
+
- lib/generators/seorel/templates/migration.rb
|
112
|
+
- lib/generators/seorel/templates/seorel.en.yml
|
110
113
|
- lib/seorel.rb
|
111
|
-
- lib/seorel/
|
114
|
+
- lib/seorel/configuration.rb
|
112
115
|
- lib/seorel/controller/class_methods.rb
|
113
116
|
- lib/seorel/controller/instance_methods.rb
|
114
117
|
- lib/seorel/controller/params.rb
|
115
118
|
- lib/seorel/engine.rb
|
116
119
|
- lib/seorel/helper.rb
|
117
|
-
- lib/seorel/
|
118
|
-
- lib/seorel/
|
120
|
+
- lib/seorel/helper/base.rb
|
121
|
+
- lib/seorel/helper/generic.rb
|
122
|
+
- lib/seorel/helper/manager.rb
|
123
|
+
- lib/seorel/helper/open_graph.rb
|
124
|
+
- lib/seorel/helper/twitter.rb
|
119
125
|
- lib/seorel/model/base.rb
|
120
126
|
- lib/seorel/model/class_methods.rb
|
121
127
|
- lib/seorel/model/instance_methods.rb
|
@@ -143,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
149
|
version: '0'
|
144
150
|
requirements: []
|
145
151
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.5.1
|
147
153
|
signing_key:
|
148
154
|
specification_version: 4
|
149
155
|
summary: Ruby on Rails SEO Metatags engine for ActiveRecord models
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/active_record'
|
3
|
-
|
4
|
-
# This generator adds a migration and aa configuration initializer
|
5
|
-
class SeorelGenerator < ActiveRecord::Generators::Base
|
6
|
-
# ActiveRecord::Generators::Base inherits from Rails::Generators::NamedBase which requires a NAME parameter for the
|
7
|
-
# new table name. Our generator always uses 'friendly_id_slugs', so we just set a random name here.
|
8
|
-
# argument :name, type: :string, default: 'random_name'
|
9
|
-
|
10
|
-
class_option :'skip-migration', :type => :boolean, :desc => "Don't generate a migration for the seorel table"
|
11
|
-
class_option :'skip-initializer', :type => :boolean, :desc => "Don't generate an initializer"
|
12
|
-
|
13
|
-
source_root File.expand_path('../../seorel', __FILE__)
|
14
|
-
|
15
|
-
# Copies the migration template to db/migrate.
|
16
|
-
def copy_files
|
17
|
-
return if options['skip-migration']
|
18
|
-
migration_template 'migration.rb', 'db/migrate/create_seorel_seorels.rb'
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_initializer
|
22
|
-
return if options['skip-initializer']
|
23
|
-
copy_file 'initializer.rb', 'config/initializers/seorel.rb'
|
24
|
-
end
|
25
|
-
end
|