seorel 0.0.5 → 0.1.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 +22 -4
- data/lib/generators/seorel/templates/seorel_config.rb +7 -2
- data/lib/seorel/config.rb +14 -5
- data/lib/seorel/controller/params.rb +59 -16
- data/lib/seorel/helper.rb +3 -3
- data/lib/seorel/model/base.rb +5 -6
- data/lib/seorel/model/class_methods.rb +0 -2
- data/lib/seorel/model/instance_methods.rb +6 -4
- data/lib/seorel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04ded42a7de4c35cf8b3ca1ae7766053a264092f
|
4
|
+
data.tar.gz: 088956d78184b2bc7e7af053dd14d61ef970e9b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cfb0fa0dd75c4ba7035151b6489158ff271ebae44b6ed3dda4d09c2996c90c98934fb5f14a0700a7bca3b91912b1e443cd238f1550393c907aadbd5897fac9a
|
7
|
+
data.tar.gz: a914c39f7c167f76cc61e3a396af43247ada409869b46bd9bfe004791dccf547daad9d7576f7f4bf9168b51dc71a2827271f27b2bc738935dfb609bf73b7ec7a
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Ruby on Rails SEO Metatags plugins for ActiveRecord models
|
|
11
11
|
`Gemfile.rb`:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'seorel', '~> 0.0
|
14
|
+
gem 'seorel', '~> 0.1.0'
|
15
15
|
|
16
16
|
# the edge version can be had using:
|
17
17
|
# gem 'seorel', github: 'dalpo/seorel'
|
@@ -34,11 +34,16 @@ Will generate the `seorel_config.rb` initializer to customize the default values
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
Seorel.configure do |config|
|
37
|
+
# config.default_prepend_title = nil
|
37
38
|
# config.default_title = nil
|
39
|
+
# config.default_append_title = nil
|
40
|
+
#
|
41
|
+
# config.default_prepend_description = nil
|
38
42
|
# config.default_description = nil
|
43
|
+
# config.default_append_description = nil
|
44
|
+
#
|
39
45
|
# config.default_image = nil
|
40
|
-
#
|
41
|
-
# config.append_title = nil
|
46
|
+
#
|
42
47
|
# config.store_seorel_if = :empty # Available values :empty | :changed
|
43
48
|
end
|
44
49
|
```
|
@@ -92,7 +97,7 @@ class PostsController < ApplicationController
|
|
92
97
|
@post = Post.find(params[:id])
|
93
98
|
###
|
94
99
|
# Extract meta tags info from your Seorelified Model
|
95
|
-
add_metatags
|
100
|
+
add_metatags @post
|
96
101
|
|
97
102
|
...
|
98
103
|
end
|
@@ -111,7 +116,20 @@ For instance `seorel.en.yml`:
|
|
111
116
|
# encoding: utf-8
|
112
117
|
en:
|
113
118
|
seorel:
|
119
|
+
# controller_name:
|
120
|
+
# action_name:
|
121
|
+
# prepend_title: '...'
|
122
|
+
# title: '...'
|
123
|
+
# append_title: '...'
|
124
|
+
#
|
125
|
+
# prepend_description: '...'
|
126
|
+
# description: '...'
|
127
|
+
# append_description: '...'
|
128
|
+
|
114
129
|
posts:
|
130
|
+
show:
|
131
|
+
prepend_title: "Details for: "
|
132
|
+
|
115
133
|
history:
|
116
134
|
title: "Posts history metatitle"
|
117
135
|
description: "Posts history metadescriprion"
|
@@ -1,9 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
Seorel.configure do |config|
|
3
|
+
# config.default_prepend_title = nil
|
3
4
|
# config.default_title = nil
|
5
|
+
# config.default_append_title = nil
|
6
|
+
#
|
7
|
+
# config.default_prepend_description = nil
|
4
8
|
# config.default_description = nil
|
9
|
+
# config.default_append_description = nil
|
10
|
+
#
|
5
11
|
# config.default_image = nil
|
6
|
-
#
|
7
|
-
# config.append_title = nil
|
12
|
+
#
|
8
13
|
# config.store_seorel_if = :empty # Available values :empty | :changed
|
9
14
|
end
|
data/lib/seorel/config.rb
CHANGED
@@ -19,11 +19,16 @@ module Seorel
|
|
19
19
|
class Configuration #:nodoc:
|
20
20
|
include ActiveSupport::Configurable
|
21
21
|
|
22
|
+
config_accessor :default_prepend_title
|
22
23
|
config_accessor :default_title
|
24
|
+
config_accessor :default_append_title
|
25
|
+
|
26
|
+
config_accessor :default_prepend_description
|
23
27
|
config_accessor :default_description
|
28
|
+
config_accessor :default_append_description
|
29
|
+
|
24
30
|
config_accessor :default_image
|
25
|
-
|
26
|
-
config_accessor :append_title
|
31
|
+
|
27
32
|
config_accessor :store_seorel_if
|
28
33
|
|
29
34
|
def param_name
|
@@ -36,13 +41,17 @@ module Seorel
|
|
36
41
|
class_eval writer, __FILE__, line
|
37
42
|
end
|
38
43
|
|
39
|
-
# this is ugly. why can't we pass the default value to config_accessor...?
|
40
44
|
configure do |config|
|
45
|
+
config.default_prepend_title = nil
|
41
46
|
config.default_title = nil
|
47
|
+
config.default_append_title = nil
|
48
|
+
|
49
|
+
config.default_prepend_description = nil
|
42
50
|
config.default_description = nil
|
51
|
+
config.default_append_description = nil
|
52
|
+
|
43
53
|
config.default_image = nil
|
44
|
-
|
45
|
-
config.append_title = nil
|
54
|
+
|
46
55
|
config.store_seorel_if = :empty
|
47
56
|
end
|
48
57
|
end
|
@@ -14,40 +14,83 @@ module Seorel
|
|
14
14
|
@controller = controller
|
15
15
|
end
|
16
16
|
|
17
|
-
def full_title
|
18
|
-
[default_options.prepend_title, self.title, default_options.append_title].compact.join.html_safe
|
19
|
-
end
|
20
|
-
|
21
17
|
def title
|
22
|
-
|
18
|
+
[
|
19
|
+
self.lookup_prepend_title,
|
20
|
+
self.base_title,
|
21
|
+
self.lookup_append_title
|
22
|
+
].compact.join.html_safe
|
23
23
|
end
|
24
24
|
|
25
25
|
def description
|
26
|
-
|
26
|
+
[
|
27
|
+
self.lookup_prepend_description,
|
28
|
+
self.base_description,
|
29
|
+
self.lookup_append_description
|
30
|
+
].compact.join.html_safe
|
27
31
|
end
|
28
32
|
|
29
33
|
def image
|
30
34
|
config.image || default_options.default_image
|
31
35
|
end
|
32
36
|
|
37
|
+
def base_title
|
38
|
+
(config.title || self.lookup_title).html_safe
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_description
|
42
|
+
(config.description || self.lookup_description).html_safe
|
43
|
+
end
|
44
|
+
|
33
45
|
def default_options
|
34
46
|
::Seorel.config
|
35
47
|
end
|
36
48
|
|
37
|
-
|
49
|
+
def lookup_i18n(key, default = nil)
|
50
|
+
I18n.t i18n_path(key), default: (default || '')
|
51
|
+
end
|
52
|
+
|
53
|
+
def lookup_prepend_title
|
54
|
+
lookup_i18n :prepend_title, default_options.default_prepend_title
|
55
|
+
end
|
38
56
|
|
39
|
-
def
|
40
|
-
|
57
|
+
def lookup_title
|
58
|
+
lookup_i18n :title, default_options.default_title
|
41
59
|
end
|
42
60
|
|
43
|
-
def
|
44
|
-
|
45
|
-
'seorel',
|
46
|
-
controller.class.name.underscore,
|
47
|
-
controller.action_name,
|
48
|
-
key
|
49
|
-
].join('.')
|
61
|
+
def lookup_append_title
|
62
|
+
lookup_i18n :append_title, default_options.default_append_title
|
50
63
|
end
|
64
|
+
|
65
|
+
def lookup_prepend_description
|
66
|
+
lookup_i18n :prepend_description, default_options.default_prepend_description
|
67
|
+
end
|
68
|
+
|
69
|
+
def lookup_description
|
70
|
+
lookup_i18n :description, default_options.default_description
|
71
|
+
end
|
72
|
+
|
73
|
+
def lookup_append_description
|
74
|
+
lookup_i18n :append_description, default_options.default_append_description
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
|
79
|
+
def controller
|
80
|
+
@controller
|
81
|
+
end
|
82
|
+
|
83
|
+
def controller_name
|
84
|
+
controller.class.name.underscore.gsub(/_controller$/, '')
|
85
|
+
end
|
86
|
+
|
87
|
+
def action_name
|
88
|
+
controller.action_name
|
89
|
+
end
|
90
|
+
|
91
|
+
def i18n_path(key)
|
92
|
+
['seorel', self.controller_name, self.action_name, key].join('.')
|
93
|
+
end
|
51
94
|
end
|
52
95
|
end
|
53
96
|
end
|
data/lib/seorel/helper.rb
CHANGED
@@ -7,7 +7,7 @@ module Seorel
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def render_title
|
10
|
-
content_tag :title, seorel_params.
|
10
|
+
content_tag :title, seorel_params.title
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_description
|
@@ -17,7 +17,7 @@ module Seorel
|
|
17
17
|
def render_open_graph
|
18
18
|
[
|
19
19
|
content_tag(:meta, nil, name: 'og:type', content: 'website'),
|
20
|
-
content_tag(:meta, nil, name: 'og:title', content: seorel_params.
|
20
|
+
content_tag(:meta, nil, name: 'og:title', content: seorel_params.title),
|
21
21
|
content_tag(:meta, nil, name: 'og:description', content: seorel_params.description),
|
22
22
|
content_tag(:meta, nil, name: 'og:image', content: seorel_params.image),
|
23
23
|
content_tag(:meta, nil, name: 'og:locale', content: I18n.locale.to_s)
|
@@ -28,7 +28,7 @@ module Seorel
|
|
28
28
|
[
|
29
29
|
content_tag(:meta, nil, name: 'twitter:card', content: 'summary'),
|
30
30
|
content_tag(:meta, nil, name: 'twitter:url', content: request.url),
|
31
|
-
content_tag(:meta, nil, name: 'twitter:title', content: seorel_params.
|
31
|
+
content_tag(:meta, nil, name: 'twitter:title', content: seorel_params.title),
|
32
32
|
content_tag(:meta, nil, name: 'twitter:description', content: seorel_params.description),
|
33
33
|
content_tag(:meta, nil, name: 'twitter:image', content: seorel_params.image)
|
34
34
|
].join("\n").html_safe
|
data/lib/seorel/model/base.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
module Seorel
|
3
3
|
module Model
|
4
4
|
module Base
|
5
|
-
|
6
5
|
def seorelify(*args)
|
7
|
-
include InstanceMethods
|
8
6
|
extend ClassMethods
|
7
|
+
include InstanceMethods
|
9
8
|
|
10
9
|
cattr_accessor :seorel_title_field, :seorel_description_field, :seorel_image_field
|
11
10
|
|
@@ -20,13 +19,13 @@ module Seorel
|
|
20
19
|
end
|
21
20
|
|
22
21
|
has_one :seorel, as: :seorelable, dependent: :destroy, class_name: 'Seorel::Seorel'
|
23
|
-
accepts_nested_attributes_for :seorel, allow_destroy:
|
22
|
+
accepts_nested_attributes_for :seorel, allow_destroy: true
|
24
23
|
|
25
|
-
|
24
|
+
delegate :title, :title?, :description, :description?, :image, :image?,
|
25
|
+
to: :seorel, prefix: :seo, allow_nil: true
|
26
26
|
|
27
|
-
|
27
|
+
before_save :set_seorel
|
28
28
|
end
|
29
|
-
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -2,17 +2,20 @@
|
|
2
2
|
module Seorel
|
3
3
|
module Model
|
4
4
|
module InstanceMethods
|
5
|
-
|
6
5
|
def seorel?
|
7
6
|
self.try(:seorel).present?
|
8
7
|
end
|
9
8
|
|
9
|
+
def seorel_changed_mode?
|
10
|
+
::Seorel.config.store_seorel_if.eql?(:changed)
|
11
|
+
end
|
12
|
+
|
10
13
|
def should_update_seo_title?
|
11
|
-
|
14
|
+
self.seorel_changed_mode? || !self.seo_title?
|
12
15
|
end
|
13
16
|
|
14
17
|
def should_update_seo_description?
|
15
|
-
|
18
|
+
self.seorel_changed_mode? || !self.seo_description?
|
16
19
|
end
|
17
20
|
|
18
21
|
def set_seorel
|
@@ -35,7 +38,6 @@ module Seorel
|
|
35
38
|
def seorel_default_value?
|
36
39
|
self.class.seorel_base_field.present?
|
37
40
|
end
|
38
|
-
|
39
41
|
end
|
40
42
|
end
|
41
43
|
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.0
|
4
|
+
version: 0.1.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: 2014-06-
|
11
|
+
date: 2014-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|