acts_more_seo 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +2 -0
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/acts_more_seo.gemspec +1 -1
- data/lib/acts_more_seo.rb +38 -26
- data/spec/acts_more_seo_spec.rb +16 -17
- metadata +5 -5
data/CHANGELOG.rdoc
CHANGED
data/README.md
CHANGED
@@ -53,9 +53,9 @@ However, if you do so - it is highly recommended to create string seo_url column
|
|
53
53
|
|
54
54
|
add_column :model, :seo_url, :string
|
55
55
|
|
56
|
-
so you can search via
|
56
|
+
so you can search via seo method:
|
57
57
|
|
58
|
-
CoolElement.
|
58
|
+
CoolElement.find_by_seo(params[:id])
|
59
59
|
|
60
60
|
You don't need to update seo_url, gem will hook up with this field automatically if it exists.
|
61
61
|
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('acts_more_seo', '0.2.
|
6
|
+
Echoe.new('acts_more_seo', '0.2.3') do |p|
|
7
7
|
p.description = "Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better"
|
8
8
|
p.url = "https://github.com/mensfeld/Css-Image-Embedder"
|
9
9
|
p.author = "Maciej Mensfeld"
|
data/acts_more_seo.gemspec
CHANGED
data/lib/acts_more_seo.rb
CHANGED
@@ -46,40 +46,33 @@ module Acts
|
|
46
46
|
|
47
47
|
# Overwrite default to_param - should return nice url
|
48
48
|
def to_param
|
49
|
-
self.
|
49
|
+
self.to_url
|
50
50
|
end
|
51
51
|
|
52
52
|
# Lets return nice and smooth url
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
el.to_url if el
|
59
|
-
end
|
60
|
-
seo_parts.delete_if{|el| el.to_s.length == 0}
|
61
|
-
seo_path = seo_parts.join('-')
|
62
|
-
else
|
63
|
-
el = self.send(self.class.seo_columns)
|
64
|
-
seo_path = el ? el.to_url : ''
|
65
|
-
end
|
53
|
+
def to_url
|
54
|
+
seo_path = seo_text_part
|
55
|
+
seo_path = "#{self.id}#{"-#{seo_path}" if seo_path && seo_path.length > 0}"
|
56
|
+
seo_path.length > 0 ? seo_path : "#{self.id}"
|
57
|
+
end
|
66
58
|
|
67
|
-
|
68
|
-
|
59
|
+
def to_seo
|
60
|
+
if self.seo_use_id
|
61
|
+
to_url
|
62
|
+
else
|
63
|
+
seo_text_part.length > 0 ? seo_text_part : "#{self.id}"
|
69
64
|
end
|
70
|
-
|
71
|
-
seo_path.length > 0 ? seo_path : "#{self.id}"
|
72
65
|
end
|
73
66
|
|
74
67
|
def update_seo_url
|
75
68
|
if self.class.seo_url_table?
|
76
|
-
self.update_column(:seo_url,
|
69
|
+
self.update_column(:seo_url, to_seo)
|
77
70
|
end
|
78
71
|
end
|
79
72
|
|
80
73
|
def set_seo_url
|
81
74
|
if self.class.seo_url_table?
|
82
|
-
self.update_column(:seo_url,
|
75
|
+
self.update_column(:seo_url, to_seo)
|
83
76
|
end
|
84
77
|
end
|
85
78
|
|
@@ -89,17 +82,36 @@ module Acts
|
|
89
82
|
self.column_names.include?("#{:seo_url}")
|
90
83
|
end
|
91
84
|
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
if !self.seo_use_id && !(el = find_by_seo_url(args.first, :first)).nil?
|
96
|
-
el
|
85
|
+
def find_by_seo(id)
|
86
|
+
if self.seo_use_id
|
87
|
+
find(id)
|
97
88
|
else
|
98
|
-
|
89
|
+
el = find_by_seo_url id, :first
|
90
|
+
raise ActiveRecord::RecordNotFound unless el
|
91
|
+
el
|
99
92
|
end
|
100
93
|
end
|
101
94
|
|
102
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def seo_text_part
|
100
|
+
# If there is more than one SEO column - prepare url "text" part
|
101
|
+
if self.class.seo_columns.is_a?(Array)
|
102
|
+
seo_parts = self.class.seo_columns.collect do |field|
|
103
|
+
el = self.send(field)
|
104
|
+
el.to_url if el
|
105
|
+
end
|
106
|
+
seo_parts.delete_if{|el| el.to_s.length == 0}
|
107
|
+
seo_path = seo_parts.join('-')
|
108
|
+
else
|
109
|
+
el = self.send(self.class.seo_columns)
|
110
|
+
seo_path = el ? el.to_url : ''
|
111
|
+
end
|
112
|
+
seo_path
|
113
|
+
end
|
114
|
+
|
103
115
|
end
|
104
116
|
end
|
105
117
|
end
|
data/spec/acts_more_seo_spec.rb
CHANGED
@@ -25,10 +25,10 @@ describe CoolElement do
|
|
25
25
|
context "when we have a class which has use_id => true" do
|
26
26
|
it "should find element unless id is corrupted" do
|
27
27
|
a = subject.create(:name => 'bla bla bla')
|
28
|
-
subject.
|
29
|
-
subject.
|
30
|
-
subject.
|
31
|
-
lambda { subject.
|
28
|
+
subject.find_by_seo(a.id).should eql(a)
|
29
|
+
subject.find_by_seo(a.to_param).should eql(a)
|
30
|
+
subject.find_by_seo("#{a.to_param}aaa").should eql(a)
|
31
|
+
lambda { subject.find_by_seo("134534dass") }.should raise_error(ActiveRecord::RecordNotFound)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -65,12 +65,12 @@ describe CoolerElement do
|
|
65
65
|
|
66
66
|
it "should be able to find existing element" do
|
67
67
|
a = subject.create
|
68
|
-
subject.
|
68
|
+
subject.find_by_seo(a.id).should eql(a)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should raise error when there is no element" do
|
72
72
|
a = subject.create
|
73
|
-
lambda { subject.
|
73
|
+
lambda { subject.find_by_seo(a.id+1) }.should raise_error(ActiveRecord::RecordNotFound)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,7 +78,7 @@ describe CoolerElement do
|
|
78
78
|
it "should return nice url" do
|
79
79
|
a = subject.create(:title => 'bla bla bla')
|
80
80
|
a.to_param.should eql("#{a.id}-bla-bla-bla")
|
81
|
-
subject.
|
81
|
+
subject.find_by_seo(a.to_param).should eql(a)
|
82
82
|
end
|
83
83
|
|
84
84
|
context "and there are some url-not-friendly letters" do
|
@@ -125,7 +125,7 @@ describe BestElement do
|
|
125
125
|
context "but surname and title exists" do
|
126
126
|
it "should return nice looking url " do
|
127
127
|
a = subject.create({:name => 'mensfeld', :title => 'test abc'})
|
128
|
-
a.
|
128
|
+
a.to_seo.should eql("mensfeld-test-abc")
|
129
129
|
a.seo_url.should eql("mensfeld-test-abc")
|
130
130
|
end
|
131
131
|
end
|
@@ -135,7 +135,7 @@ describe BestElement do
|
|
135
135
|
context "but surname and title exists" do
|
136
136
|
it "should return nice looking url " do
|
137
137
|
a = subject.create({:surname => 'mensfeld', :title => 'test abc'})
|
138
|
-
a.
|
138
|
+
a.to_seo.should eql("mensfeld-test-abc")
|
139
139
|
a.reload
|
140
140
|
a.seo_url.should eql("mensfeld-test-abc")
|
141
141
|
end
|
@@ -144,7 +144,7 @@ describe BestElement do
|
|
144
144
|
context "and no other param" do
|
145
145
|
it "should return only id" do
|
146
146
|
a = subject.create()
|
147
|
-
a.
|
147
|
+
a.to_seo.should eql("#{a.id}")
|
148
148
|
a.reload
|
149
149
|
a.seo_url.should eql("#{a.id}")
|
150
150
|
end
|
@@ -154,7 +154,7 @@ describe BestElement do
|
|
154
154
|
context "when there are all the params" do
|
155
155
|
it "should return nice url" do
|
156
156
|
a = subject.create({:name => 'maciej', :surname => 'mensfeld', :title => 'test abc'})
|
157
|
-
a.
|
157
|
+
a.to_seo.should eql("maciej-mensfeld-test-abc")
|
158
158
|
a.reload
|
159
159
|
a.seo_url.should eql("maciej-mensfeld-test-abc")
|
160
160
|
end
|
@@ -163,20 +163,19 @@ describe BestElement do
|
|
163
163
|
context "when we have a class which has use_id => false" do
|
164
164
|
it "should find element only when seo_url is same (or by id)" do
|
165
165
|
a = subject.create(:name => 'bla bla bla')
|
166
|
-
subject.
|
167
|
-
subject.
|
168
|
-
lambda { subject.find("#{a.to_param}aaa") }.should raise_error(ActiveRecord::RecordNotFound)
|
166
|
+
subject.find_by_seo(a.to_seo).should eql(a)
|
167
|
+
lambda { subject.find_by_seo("#{a.to_param}aaa") }.should raise_error(ActiveRecord::RecordNotFound)
|
169
168
|
end
|
170
169
|
end
|
171
170
|
|
172
171
|
context "when updating object" do
|
173
172
|
it "should have refreshed seo_url" do
|
174
173
|
a = subject.create({:name => 'mensfeld', :title => 'test abc'})
|
175
|
-
a.
|
174
|
+
a.to_seo.should eql("mensfeld-test-abc")
|
176
175
|
a.name = 'kowalski'
|
177
176
|
a.save
|
178
|
-
a.
|
179
|
-
subject.
|
177
|
+
a.to_seo.should eql("kowalski-test-abc")
|
178
|
+
subject.find_by_seo("kowalski-test-abc").should eql(a)
|
180
179
|
end
|
181
180
|
end
|
182
181
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_more_seo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-04 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &13506420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *13506420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: active_record
|
27
|
-
requirement: &
|
27
|
+
requirement: &13505960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *13505960
|
36
36
|
description: Gem makes your ActiveRecord models more SEO friendly. Changes URL to
|
37
37
|
look way better
|
38
38
|
email: maciej@mensfeld.pl
|