sluggable-ams 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_ams.rb +39 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3c6ff26fc5bc611d5b1cb8d31f48c49c661af8ba
|
|
4
|
+
data.tar.gz: 5cf448a87019e283acf981c51cac27d00a839de9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 81816d4d1b13213a73be03d73cf5ce9b106286f8ef575bdd3ff41572cace0f6432a61935878c2d4893cfbc7037ec12bd73348ed5335d723de28fd822ac24b4a7
|
|
7
|
+
data.tar.gz: 6d7400bea5e5cb45ede3166784022b0aa3ced3b97f4c36345acee80e808e2f0beb8327e240b9977d13e6dee689e72c275a6170c830c5b2dbcae328b8fb5e72b6
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module SluggableAms
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
before_create :generate_slug
|
|
6
|
+
class_attribute :sluggable_column
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Makes sure that the slug is unique, if it's not it appends a number to it.
|
|
10
|
+
def generate_slug
|
|
11
|
+
slug = sluggify(self.send(self.class.sluggable_column))
|
|
12
|
+
count = 2
|
|
13
|
+
old_slugs = self.class.all.map(&:slug)
|
|
14
|
+
new_slug = slug
|
|
15
|
+
loop do
|
|
16
|
+
if old_slugs.include?(new_slug)
|
|
17
|
+
new_slug = "#{slug}-#{count}"
|
|
18
|
+
count += 1
|
|
19
|
+
else
|
|
20
|
+
self.slug = new_slug
|
|
21
|
+
break
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def sluggify(str)
|
|
27
|
+
str.gsub(' ', '-').gsub(/[^0-9a-z\-]/i, '').downcase
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_param
|
|
31
|
+
slug
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module ClassMethods
|
|
35
|
+
def is_slugged_on(column)
|
|
36
|
+
self.sluggable_column = column
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sluggable-ams
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Aleksander Madland Stapnes
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Basic slugging functionality
|
|
14
|
+
email: aleksander_m_stapnes@hotmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/sluggable_ams.rb
|
|
20
|
+
homepage: https://github.com/madstap/voteable-gem
|
|
21
|
+
licenses: []
|
|
22
|
+
metadata: {}
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '0'
|
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
requirements: []
|
|
38
|
+
rubyforge_project:
|
|
39
|
+
rubygems_version: 2.4.3
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Basic slugging for rails resources, made for the Tealeaf Academy Rapid Prototyping
|
|
43
|
+
with Ruby on Rails course
|
|
44
|
+
test_files: []
|