slugtastic 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -0
- data/README.md +22 -0
- data/Rakefile +14 -0
- data/lib/slugtastic.rb +23 -0
- data/slugtastic.gemspec +29 -0
- metadata +59 -0
data/Manifest
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Slugtastic
|
2
|
+
==========
|
3
|
+
|
4
|
+
Simple gem for autogenerating permalink style slugs for your ActiveRecord models.
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
Add this to your Gemfile:
|
9
|
+
|
10
|
+
gem "slugtastic"
|
11
|
+
|
12
|
+
And run `bundle install`
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Usage is very simple. Just add the following to your model:
|
17
|
+
|
18
|
+
has_slug :slug, :from => :title
|
19
|
+
|
20
|
+
This will generate a slug string from the title atrribute and store it in the slug attribute unless the slug already contains a string. The slug is generated pre-validation so you can still use `validates_presence_of :slug`.
|
21
|
+
|
22
|
+
There are no extra options at present.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('slugtastic', '0.1.1') do |p|
|
6
|
+
p.description = "A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute."
|
7
|
+
p.url = "http://github.com/danbee/slugtastic"
|
8
|
+
p.author = "Dan Barber"
|
9
|
+
p.email = "danbee@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/lib/slugtastic.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Slugtastic
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
def generate_slug(string)
|
7
|
+
string.downcase.gsub(/ /, '_').gsub(/[^a-z0-9\-_]/, '')
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def has_slug(name, options = { :from => :title })
|
13
|
+
before_validation do |record|
|
14
|
+
self[name] = generate_slug(self[options[:from]]) if self[name].nil? or self[name].empty?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActiveRecord::Base
|
22
|
+
include Slugtastic
|
23
|
+
end
|
data/slugtastic.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{slugtastic}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = [%q{Dan Barber}]
|
9
|
+
s.date = %q{2011-10-04}
|
10
|
+
s.description = %q{A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute.}
|
11
|
+
s.email = %q{danbee@gmail.com}
|
12
|
+
s.extra_rdoc_files = [%q{README.md}, %q{lib/slugtastic.rb}]
|
13
|
+
s.files = [%q{README.md}, %q{Rakefile}, %q{lib/slugtastic.rb}, %q{Manifest}, %q{slugtastic.gemspec}]
|
14
|
+
s.homepage = %q{http://github.com/danbee/slugtastic}
|
15
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Slugtastic}, %q{--main}, %q{README.md}]
|
16
|
+
s.require_paths = [%q{lib}]
|
17
|
+
s.rubyforge_project = %q{slugtastic}
|
18
|
+
s.rubygems_version = %q{1.8.6}
|
19
|
+
s.summary = %q{A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slugtastic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Barber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-04 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple slug string generator for ActiveRecord. Will populate a slug
|
15
|
+
attribute from another attribute.
|
16
|
+
email: danbee@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- lib/slugtastic.rb
|
22
|
+
files:
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/slugtastic.rb
|
26
|
+
- Manifest
|
27
|
+
- slugtastic.gemspec
|
28
|
+
homepage: http://github.com/danbee/slugtastic
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options:
|
32
|
+
- --line-numbers
|
33
|
+
- --inline-source
|
34
|
+
- --title
|
35
|
+
- Slugtastic
|
36
|
+
- --main
|
37
|
+
- README.md
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '1.2'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project: slugtastic
|
54
|
+
rubygems_version: 1.8.6
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: A simple slug string generator for ActiveRecord. Will populate a slug attribute
|
58
|
+
from another attribute.
|
59
|
+
test_files: []
|