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 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.
@@ -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
- key, counter = self[permalink_options[:field]].parameterize.to_s, '-1'
38
- permalink = key
39
- while permalink_options[:reserved_names].include?(permalink) or self.class.exists?(:permalink => permalink)
40
- counter.succ!
41
- permalink = key + counter
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "railhead_permalink"
3
- s.version = "0.1.4"
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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagybence-railhead_permalink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bence Nagy