sluggable-tom 0.0.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.
- checksums.yaml +7 -0
- data/lib/sluggable_tom.rb +31 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adc896562ec95d976da7e1820b6549c65ce9ad60
|
4
|
+
data.tar.gz: 8d407cedef51b0449849ac8b5bef035dd8301bd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fac041c883ea69227f803b657e6aa4bd857422a3163be9fa5cafa37c58be966b6d4706dc062220eade37029d0a81f7853288a5dfec5ad560f490471e3b94414c
|
7
|
+
data.tar.gz: 393945c99859e05e7e65f731a1db32393a87ad48609168ca9d853d338eb7b97353cfa96536d2be21d90aca498b26cc24c15b2acd95c4b51c44242f01c8332d84
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SluggableGem
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
before_save :generate_slug!
|
6
|
+
class_attribute :slug_column
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_param
|
10
|
+
self.slug
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_slug!
|
14
|
+
the_slug = self.send(self.class.slug_column.to_sym).parameterize
|
15
|
+
|
16
|
+
while self.class.where(slug: the_slug).exists?
|
17
|
+
if the_slug.split('-').last.to_i != 0
|
18
|
+
the_slug = "#{the_slug.split('-').slice(0...-1).join('-')}-#{the_slug.split('-').last.to_i + 1}"
|
19
|
+
else
|
20
|
+
the_slug += "-2"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
self.slug = the_slug
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def sluggable_column(col_name)
|
28
|
+
self.slug_column = col_name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sluggable-tom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Tomecek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Sluggable module exposed in lib directly and available to be mixedin
|
14
|
+
to your model
|
15
|
+
email: tomas.tomecek@hotmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/sluggable_tom.rb
|
21
|
+
homepage: http://github.com
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A gem for optimizing URLs - SEO friendly
|
44
|
+
test_files: []
|