slugit 0.0.1 → 0.0.2
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/lib/slugit.rb +3 -19
- data/lib/slugit/slugit.rb +31 -0
- metadata +2 -1
data/lib/slugit.rb
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
def slugit(options = {})
|
|
3
|
-
options.symbolize_keys!
|
|
4
|
-
options.reverse_merge!({
|
|
5
|
-
:from => :title,
|
|
6
|
-
:to => :slug,
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
validates options[:to], :presence => true
|
|
10
|
-
|
|
11
|
-
before_save Proc.new {
|
|
12
|
-
if options[:from].to_s.in? changed
|
|
13
|
-
self.send("#{options[:to]}=", name.parameterize)
|
|
14
|
-
end
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
end
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'slugit', 'slugit')
|
|
18
2
|
|
|
3
|
+
if defined?(ActiveRecord)
|
|
4
|
+
ActiveRecord::Base.instance_eval { extend Slugit::ClassMethods }
|
|
19
5
|
end
|
|
20
|
-
|
|
21
|
-
ActiveRecord::Base.extend(Slugit)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Slugit
|
|
2
|
+
|
|
3
|
+
module ClassMethods
|
|
4
|
+
def slugit(options = {})
|
|
5
|
+
class_attribute :slugit_from, :slugit_to
|
|
6
|
+
include InstanceMethods
|
|
7
|
+
|
|
8
|
+
options.symbolize_keys!
|
|
9
|
+
options.reverse_merge!({
|
|
10
|
+
:from => :title,
|
|
11
|
+
:to => :slug,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
self.slugit_from = options[:from]
|
|
15
|
+
self.slugit_to = options[:to]
|
|
16
|
+
|
|
17
|
+
validates options[:to], :presence => true
|
|
18
|
+
|
|
19
|
+
before_validation :set_slug
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module InstanceMethods
|
|
24
|
+
def set_slug
|
|
25
|
+
if self.slugit_from.to_s.in? changed
|
|
26
|
+
self[self.slugit_to] = self.send(self.slugit_from).parameterize
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slugit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -18,6 +18,7 @@ extensions: []
|
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
20
|
- lib/slugit.rb
|
|
21
|
+
- lib/slugit/slugit.rb
|
|
21
22
|
homepage: https://github.com/gchaincl/slugit
|
|
22
23
|
licenses: []
|
|
23
24
|
post_install_message:
|