ckb-sluggable 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.rb +24 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21bca849df38a82e4c7d99113d19757c75b772e4
|
4
|
+
data.tar.gz: be7d477b63e21e404eb4c0e99cf288a175d92b9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4619b78a49e2e7615889f4923424bb0b73d950d5030f90cffbcebf4c195c4cc11d0422cda5dd70c6b998a28b1cc23e670795386193270880b0c9cdbe0c3b262a
|
7
|
+
data.tar.gz: 4b4d3aff7185a5b1725d450b269cf52cc1c8419bfc6116620216b0f9a7b9908e60df7ef8aad815210a63168b4d8f319d79bdac2b2aaeee5ccb828a0544df86fb
|
data/lib/sluggable.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Sluggable
|
2
|
+
def to_slug(text)
|
3
|
+
text.strip.downcase.gsub(/\s+/, "-").gsub(/[^\w-]/, "")
|
4
|
+
end
|
5
|
+
|
6
|
+
def generate_slug!(attribute)
|
7
|
+
temp_slug = to_slug(self[attribute])
|
8
|
+
|
9
|
+
counter = 0
|
10
|
+
while self.class.find_by(slug: temp_slug)
|
11
|
+
counter += 1
|
12
|
+
|
13
|
+
# if conditional makes sure we only remove a number we added
|
14
|
+
temp_slug.gsub!(/-\d\z/, "") if counter > 1
|
15
|
+
temp_slug = "#{temp_slug}-#{counter}"
|
16
|
+
end
|
17
|
+
|
18
|
+
self.slug = temp_slug
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_param
|
22
|
+
slug
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ckb-sluggable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Conrad Beach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem gives you the ability to create clean, unique slugs for Rails
|
14
|
+
models.
|
15
|
+
email: conradbeach@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/sluggable.rb
|
21
|
+
homepage: http://conradcodes.com
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Create slugs for models in Rails.
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|