mm-sluggable 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -5
- data/Rakefile +1 -1
- data/lib/mm-sluggable.rb +19 -20
- metadata +46 -44
data/README.rdoc
CHANGED
@@ -15,22 +15,22 @@ Either load it into all models, or individual models:
|
|
15
15
|
Then call sluggable to configure it
|
16
16
|
|
17
17
|
sluggable :title, :scope => :account_id
|
18
|
-
|
18
|
+
|
19
19
|
== Options
|
20
20
|
|
21
21
|
Available options are:
|
22
22
|
|
23
23
|
* :scope - scope to a specific field (default - nil)
|
24
24
|
* :key - what the slug key is called (default - :slug)
|
25
|
-
* :index - whether to add an index for the slug (default - true)
|
26
25
|
* :method - what method to call on the field to sluggify it (default - :parameterize)
|
27
26
|
* :callback - when to trigger the slugging (default - :before_validation_on_create)
|
27
|
+
* :start - what number to start the version numbers (default - 2)
|
28
28
|
|
29
29
|
Eg.
|
30
30
|
|
31
|
-
sluggable :title, :scope => :account_id, :key => :title_slug, :method => :to_url, :
|
32
|
-
|
33
|
-
This will slug the title to the title_slug key, scoped to the account, will use String#to_url to slug it and
|
31
|
+
sluggable :title, :scope => :account_id, :key => :title_slug, :method => :to_url, :start => 42
|
32
|
+
|
33
|
+
This will slug the title to the title_slug key, scoped to the account, will use String#to_url to slug it and start the versions at 42
|
34
34
|
|
35
35
|
== Versioning
|
36
36
|
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
# Change these as appropriate
|
17
17
|
s.name = "mm-sluggable"
|
18
|
-
s.version = "0.
|
18
|
+
s.version = "0.3.0"
|
19
19
|
s.summary = "Tiny plugin for MongoMapper to cache a slugged version of a field"
|
20
20
|
s.author = "Richard Livsey"
|
21
21
|
s.email = "richard@livsey.org"
|
data/lib/mm-sluggable.rb
CHANGED
@@ -12,14 +12,14 @@ module MongoMapper
|
|
12
12
|
self.slug_options = {
|
13
13
|
:to_slug => to_slug,
|
14
14
|
:key => :slug,
|
15
|
-
:index => true,
|
16
15
|
:method => :parameterize,
|
17
16
|
:scope => nil,
|
18
17
|
:max_length => 256,
|
18
|
+
:start => 2,
|
19
19
|
:callback => [:before_validation, {:on => :create}]
|
20
20
|
}.merge(options)
|
21
21
|
|
22
|
-
key slug_options[:key], String
|
22
|
+
key slug_options[:key], String
|
23
23
|
|
24
24
|
if slug_options[:callback].is_a?(Array)
|
25
25
|
self.send(slug_options[:callback][0], :set_slug, slug_options[:callback][1])
|
@@ -29,30 +29,29 @@ module MongoMapper
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
return unless self.send(options[:key]).blank?
|
32
|
+
def set_slug
|
33
|
+
options = self.class.slug_options
|
34
|
+
return unless self.send(options[:key]).blank?
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
to_slug = self[options[:to_slug]]
|
37
|
+
return if to_slug.blank?
|
39
38
|
|
40
|
-
|
39
|
+
the_slug = raw_slug = to_slug.send(options[:method]).to_s[0...options[:max_length]]
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
conds = {}
|
42
|
+
conds[options[:key]] = the_slug
|
43
|
+
conds[options[:scope]] = self.send(options[:scope]) if options[:scope]
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
self.send(:"#{options[:key]}=", the_slug)
|
45
|
+
# todo - remove the loop and use regex instead so we can do it in one query
|
46
|
+
i = options[:start]
|
47
|
+
while self.class.first(conds)
|
48
|
+
conds[options[:key]] = the_slug = "#{raw_slug}-#{i}"
|
49
|
+
i += 1
|
54
50
|
end
|
51
|
+
|
52
|
+
self.send(:"#{options[:key]}=", the_slug)
|
55
53
|
end
|
54
|
+
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
metadata
CHANGED
@@ -1,81 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm-sluggable
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Richard Livsey
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-05-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: mongo_mapper
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
24
21
|
version: 0.9.0
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
25
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
36
38
|
type: :development
|
37
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
38
46
|
description:
|
39
47
|
email: richard@livsey.org
|
40
48
|
executables: []
|
41
|
-
|
42
49
|
extensions: []
|
43
|
-
|
44
|
-
extra_rdoc_files:
|
50
|
+
extra_rdoc_files:
|
45
51
|
- README.rdoc
|
46
|
-
files:
|
52
|
+
files:
|
47
53
|
- LICENSE
|
48
54
|
- Rakefile
|
49
55
|
- README.rdoc
|
50
56
|
- lib/mm-sluggable.rb
|
51
|
-
has_rdoc: true
|
52
57
|
homepage: http://github.com/rlivsey/mm-sluggable
|
53
58
|
licenses: []
|
54
|
-
|
55
59
|
post_install_message:
|
56
|
-
rdoc_options:
|
60
|
+
rdoc_options:
|
57
61
|
- --main
|
58
62
|
- README.rdoc
|
59
|
-
require_paths:
|
63
|
+
require_paths:
|
60
64
|
- lib
|
61
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
66
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
72
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version:
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
73
77
|
requirements: []
|
74
|
-
|
75
78
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.23
|
77
80
|
signing_key:
|
78
81
|
specification_version: 3
|
79
82
|
summary: Tiny plugin for MongoMapper to cache a slugged version of a field
|
80
83
|
test_files: []
|
81
|
-
|