sluggable_jake 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sluggable_jake.rb +30 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0516668c7214359a6327d8459e698a97731a94f6
|
4
|
+
data.tar.gz: fddb2ec7fcfb674f53cf4c983a656d37b6122545
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6a3a4ac549782acfbac9b5c3018355c7f25c046ed35ae2aa8119822b422a5b38441f4baeda2b6266aa7a4e0a3ddbb56e8e79efc9d3822aa475177b535d8398f
|
7
|
+
data.tar.gz: b883dbbc9db736c3267e89006afa6d4643d572d8bad383bec76a3138dd3c91edfa2c0b7a22e8106714cebaef11493fe0e3df49fab4ee3b3ac90b617c11d58979
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Sluggable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
after_validation :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
|
+
alt_title = self.send(self.class.slug_column.to_sym).strip.gsub(/\W/,'-').downcase
|
15
|
+
alt_title.gsub!(/-+/, '-')
|
16
|
+
slug = alt_title
|
17
|
+
num = 0
|
18
|
+
while !!self.class.find_by(slug: slug)
|
19
|
+
num += 1
|
20
|
+
slug = alt_title + '-' + num.to_s
|
21
|
+
end
|
22
|
+
self.slug = slug
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
def sluggable_column(column_name)
|
27
|
+
self.slug_column = column_name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sluggable_jake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jake Gavin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a slugging gem I made for the Tealeaf Academy
|
14
|
+
email: jakegavin@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/sluggable_jake.rb
|
20
|
+
homepage: https://github.com/jakegavin/sluggable_jake
|
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.2.1
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: A simple slugging gem
|
43
|
+
test_files: []
|