nagybence-railhead_permalink 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/railhead_permalink.rb +10 -7
- data/railhead_permalink.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -26,6 +26,10 @@ You can setup reserved names too:
|
|
26
26
|
|
27
27
|
auto_permalink :title, :reserved_names => %w(reserved names)
|
28
28
|
|
29
|
+
You can keep already existing permalinks:
|
30
|
+
|
31
|
+
auto_permalink :title, :keep_existing => true
|
32
|
+
|
29
33
|
== License
|
30
34
|
|
31
35
|
Copyright (c) 2008-2009 Bence Nagy (nagybence@tipogral.hu), released under the MIT license.
|
data/lib/railhead_permalink.rb
CHANGED
@@ -15,6 +15,7 @@ module RailheadPermalink
|
|
15
15
|
|
16
16
|
write_inheritable_attribute(:permalink_options, {
|
17
17
|
:field => field,
|
18
|
+
:keep_existing => (options[:keep_existing] || false),
|
18
19
|
:reserved_names => (options[:reserved_names] || []).concat(ActionController::Base.resources_path_names.values)
|
19
20
|
})
|
20
21
|
|
@@ -34,17 +35,19 @@ module RailheadPermalink
|
|
34
35
|
|
35
36
|
module InstanceMethods
|
36
37
|
def create_permalink
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
if self.permalink.nil? or not permalink_options[:keep_existing]
|
39
|
+
key, counter = self[permalink_options[:field]].parameterize.to_s, '-1'
|
40
|
+
permalink = key
|
41
|
+
while permalink_options[:reserved_names].include?(permalink) or self.class.exists?(:permalink => permalink)
|
42
|
+
counter.succ!
|
43
|
+
permalink = key + counter
|
44
|
+
end
|
45
|
+
self[:permalink] = permalink
|
42
46
|
end
|
43
|
-
self[:permalink] = permalink
|
44
47
|
end
|
45
48
|
|
46
49
|
def to_param
|
47
|
-
permalink
|
50
|
+
self.permalink
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
data/railhead_permalink.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "railhead_permalink"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.5"
|
4
4
|
s.date = "2009-01-27"
|
5
5
|
s.summary = "RailheadPermalink is a Ruby on Rails plugin that automatically finds ActiveRecord objects with permalink."
|
6
6
|
s.email = "nagybence@tipogral.hu"
|