sluggable_finder 2.3.2 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.markdown +11 -0
- data/lib/sluggable_finder/orm.rb +3 -1
- data/lib/sluggable_finder/version.rb +1 -1
- data/spec/sluggable_finder_spec.rb +17 -0
- metadata +26 -26
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
## sluggable_finder
|
2
|
+
NOTE: THIS GEM IS RAILS 2.X COMPATIBLE ONLY.
|
3
|
+
|
4
|
+
I have no intention to port it to 3.x, since this kind of thing is much easier in the newest ActiveRecord, anyway.
|
2
5
|
|
3
6
|
Ismael Celis
|
4
7
|
|
@@ -78,6 +81,14 @@ Slug uniqueness will be checked accross all classes in STI models. If you want t
|
|
78
81
|
sluggable_finder :title, :ignore_sti => true
|
79
82
|
end
|
80
83
|
|
84
|
+
You can pass an optional block to pre-process the slug before saving
|
85
|
+
|
86
|
+
class Comment < SomeParentClass
|
87
|
+
sluggable_finder :title do |slug_candidate|
|
88
|
+
"comment-#{slug_candidate}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
81
92
|
### Controllers
|
82
93
|
|
83
94
|
You can do Model.find(slug) just how you would with a single numerical ID. It will also raise a RecordNotFound exception so you can handle that in your application controller.
|
data/lib/sluggable_finder/orm.rb
CHANGED
@@ -3,7 +3,7 @@ module SluggableFinder
|
|
3
3
|
|
4
4
|
module ClassMethods
|
5
5
|
|
6
|
-
def sluggable_finder(field = :title, options = {})
|
6
|
+
def sluggable_finder(field = :title, options = {}, &slug_modifier)
|
7
7
|
return if self.included_modules.include?(SluggableFinder::Orm::InstanceMethods)
|
8
8
|
extend SluggableFinder::Finder
|
9
9
|
extend SluggableFinder::BaseFinder
|
@@ -21,6 +21,7 @@ module SluggableFinder
|
|
21
21
|
:reserved_slugs => [],
|
22
22
|
:allow_integer_ids => true,
|
23
23
|
:upcase => false,
|
24
|
+
:slug_modifier => slug_modifier || nil,
|
24
25
|
:ignore_sti => false # if true, Uniqueness won't check sibling classes.
|
25
26
|
}.merge( options ))
|
26
27
|
class_inheritable_reader :sluggable_finder_options
|
@@ -76,6 +77,7 @@ module SluggableFinder
|
|
76
77
|
|
77
78
|
def get_value_or_generate_random(column_name)
|
78
79
|
v = self.send(column_name)
|
80
|
+
v = sluggable_finder_options[:slug_modifier].call(v) if sluggable_finder_options[:slug_modifier]
|
79
81
|
v || SluggableFinder.random_slug_for(self.class)
|
80
82
|
end
|
81
83
|
|
@@ -39,6 +39,12 @@ class SimpleItem < Item
|
|
39
39
|
sluggable_finder :title, :reserved_slugs => ['admin','settings'] # defaults :to => :slug
|
40
40
|
end
|
41
41
|
|
42
|
+
class SimpleItemWithBlock < Item
|
43
|
+
sluggable_finder :title do |slug_candidate|
|
44
|
+
slug_candidate =~ /\A\d+\Z/ ? "p#{slug_candidate}" : slug_candidate
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
42
48
|
class SimpleUpcaseItem < Item
|
43
49
|
sluggable_finder :title, :upcase => true
|
44
50
|
end
|
@@ -142,6 +148,17 @@ describe "SluggableFinder" do
|
|
142
148
|
end
|
143
149
|
end
|
144
150
|
|
151
|
+
describe 'with modifier block' do
|
152
|
+
|
153
|
+
it 'should pass slug through block before saving' do
|
154
|
+
item1 = SimpleItemWithBlock.create!(:title => 'Hello World')
|
155
|
+
item1.to_param.should == 'hello-world'
|
156
|
+
|
157
|
+
item2 = SimpleItemWithBlock.create!(:title => '1234')
|
158
|
+
item2.to_param.should == 'p1234'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
145
162
|
describe SimpleUpcaseItem, 'uppercase slugs' do
|
146
163
|
|
147
164
|
it 'should uppercase slugs' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sluggable_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 5
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
9
|
+
- 3
|
10
|
+
version: 2.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ismael Celis
|
@@ -15,14 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-04 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
type: :development
|
23
|
-
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
24
|
none: false
|
27
25
|
requirements:
|
28
26
|
- - ">="
|
@@ -33,12 +31,12 @@ dependencies:
|
|
33
31
|
- 0
|
34
32
|
- 0
|
35
33
|
version: 1.0.0
|
36
|
-
|
34
|
+
version_requirements: *id001
|
35
|
+
name: bundler
|
36
|
+
prerelease: false
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
type: :development
|
39
|
-
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
40
|
none: false
|
43
41
|
requirements:
|
44
42
|
- - ">="
|
@@ -47,12 +45,12 @@ dependencies:
|
|
47
45
|
segments:
|
48
46
|
- 0
|
49
47
|
version: "0"
|
50
|
-
|
48
|
+
version_requirements: *id002
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
type: :development
|
53
|
-
|
54
|
-
prerelease: false
|
55
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
54
|
none: false
|
57
55
|
requirements:
|
58
56
|
- - ">="
|
@@ -61,12 +59,12 @@ dependencies:
|
|
61
59
|
segments:
|
62
60
|
- 0
|
63
61
|
version: "0"
|
64
|
-
|
62
|
+
version_requirements: *id003
|
63
|
+
name: rake
|
64
|
+
prerelease: false
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
type: :development
|
67
|
-
|
68
|
-
prerelease: false
|
69
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
68
|
none: false
|
71
69
|
requirements:
|
72
70
|
- - ">="
|
@@ -75,12 +73,12 @@ dependencies:
|
|
75
73
|
segments:
|
76
74
|
- 0
|
77
75
|
version: "0"
|
78
|
-
|
76
|
+
version_requirements: *id004
|
77
|
+
name: sqlite3
|
78
|
+
prerelease: false
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
80
|
type: :runtime
|
81
|
-
|
82
|
-
prerelease: false
|
83
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
82
|
none: false
|
85
83
|
requirements:
|
86
84
|
- - <=
|
@@ -91,7 +89,9 @@ dependencies:
|
|
91
89
|
- 8
|
92
90
|
- 0
|
93
91
|
version: 2.8.0
|
94
|
-
|
92
|
+
version_requirements: *id005
|
93
|
+
name: activerecord
|
94
|
+
prerelease: false
|
95
95
|
description: This plugin allows models to generate a unique "slug" (url-enabled name) from any regular attribute. Add friendly URLs to your models with one line.
|
96
96
|
email:
|
97
97
|
- ismaelct@gmail.com
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
requirements: []
|
158
158
|
|
159
159
|
rubyforge_project: sluggable_finder
|
160
|
-
rubygems_version: 1.3
|
160
|
+
rubygems_version: 1.5.3
|
161
161
|
signing_key:
|
162
162
|
specification_version: 3
|
163
163
|
summary: Easy friendly URLs for your ActiveRecord models
|