slugtastic 1.1.0 → 1.2.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.
- data/Gemfile.lock +12 -12
- data/lib/slugtastic.rb +6 -2
- data/lib/slugtastic/model_additions.rb +1 -1
- data/lib/slugtastic/version.rb +1 -1
- data/spec/slugtastic/model_additions_spec.rb +7 -1
- data/spec/slugtastic_spec.rb +4 -0
- metadata +2 -8
data/Gemfile.lock
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slugtastic (1.
|
4
|
+
slugtastic (1.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (3.0.
|
10
|
-
activesupport (= 3.0.
|
9
|
+
activemodel (3.0.20)
|
10
|
+
activesupport (= 3.0.20)
|
11
11
|
builder (~> 2.1.2)
|
12
12
|
i18n (~> 0.5.0)
|
13
|
-
activesupport (3.0.
|
13
|
+
activesupport (3.0.20)
|
14
14
|
builder (2.1.2)
|
15
15
|
diff-lcs (1.1.3)
|
16
16
|
i18n (0.5.0)
|
17
|
-
rake (0.
|
18
|
-
rspec (2.
|
19
|
-
rspec-core (~> 2.
|
20
|
-
rspec-expectations (~> 2.
|
21
|
-
rspec-mocks (~> 2.
|
22
|
-
rspec-core (2.
|
23
|
-
rspec-expectations (2.
|
17
|
+
rake (10.0.3)
|
18
|
+
rspec (2.12.0)
|
19
|
+
rspec-core (~> 2.12.0)
|
20
|
+
rspec-expectations (~> 2.12.0)
|
21
|
+
rspec-mocks (~> 2.12.0)
|
22
|
+
rspec-core (2.12.2)
|
23
|
+
rspec-expectations (2.12.1)
|
24
24
|
diff-lcs (~> 1.1.3)
|
25
|
-
rspec-mocks (2.
|
25
|
+
rspec-mocks (2.12.2)
|
26
26
|
supermodel (0.1.6)
|
27
27
|
activemodel (~> 3.0.0)
|
28
28
|
|
data/lib/slugtastic.rb
CHANGED
@@ -3,8 +3,12 @@ require "slugtastic/model_additions"
|
|
3
3
|
require "slugtastic/railtie" if defined? Rails
|
4
4
|
|
5
5
|
module Slugtastic
|
6
|
-
def self.generate_slug(string)
|
6
|
+
def self.generate_slug(string, delimiter = nil)
|
7
7
|
return if string.nil?
|
8
|
-
string.parameterize
|
8
|
+
slug = string.parameterize
|
9
|
+
if delimiter
|
10
|
+
slug.gsub!("-", delimiter)
|
11
|
+
end
|
12
|
+
slug
|
9
13
|
end
|
10
14
|
end
|
@@ -11,7 +11,7 @@ module Slugtastic
|
|
11
11
|
# end
|
12
12
|
def has_slug name, options = { :from => :title }
|
13
13
|
before_validation do |record|
|
14
|
-
send("#{name}=", Slugtastic.generate_slug(send(options[:from]))) if send(name).nil? or send(name).blank?
|
14
|
+
send("#{name}=", Slugtastic.generate_slug(send(options[:from]), options[:delimiter])) if send(name).nil? or send(name).blank?
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/lib/slugtastic/version.rb
CHANGED
@@ -4,8 +4,9 @@ require 'spec_helper'
|
|
4
4
|
class Model < SuperModel::Base
|
5
5
|
include ActiveModel::Validations::Callbacks
|
6
6
|
extend Slugtastic::ModelAdditions
|
7
|
-
attr_accessor :slug, :title
|
7
|
+
attr_accessor :slug, :slug_2, :title
|
8
8
|
has_slug :slug, from: :title
|
9
|
+
has_slug :slug_2, from: :title, delimiter: "_"
|
9
10
|
end
|
10
11
|
|
11
12
|
describe Slugtastic::ModelAdditions do
|
@@ -13,6 +14,10 @@ describe Slugtastic::ModelAdditions do
|
|
13
14
|
Model.create!(:title => "A Simple Title").slug.should eq "a-simple-title"
|
14
15
|
end
|
15
16
|
|
17
|
+
it "generates a slug from the title with delimiter substitutions" do
|
18
|
+
Model.create!(:title => "A Simple Title").slug_2.should eq "a_simple_title"
|
19
|
+
end
|
20
|
+
|
16
21
|
it "doesn't regenerate the slug if it already exists" do
|
17
22
|
model = Model.create!(:title => "A Simple Title")
|
18
23
|
model.slug.should eq "a-simple-title"
|
@@ -20,5 +25,6 @@ describe Slugtastic::ModelAdditions do
|
|
20
25
|
model.title = "A new title"
|
21
26
|
model.save
|
22
27
|
model.slug.should eq "a-simple-title"
|
28
|
+
model.slug_2.should eq "a_simple_title"
|
23
29
|
end
|
24
30
|
end
|
data/spec/slugtastic_spec.rb
CHANGED
@@ -11,6 +11,10 @@ describe Slugtastic do
|
|
11
11
|
Slugtastic.generate_slug("A simple string.").should eq "a-simple-string"
|
12
12
|
end
|
13
13
|
|
14
|
+
it "substitutes hyphens for delimiter if specified" do
|
15
|
+
Slugtastic.generate_slug("A simple string.", "_").should eq "a_simple_string"
|
16
|
+
end
|
17
|
+
|
14
18
|
it "generates a slug from a string with numbers" do
|
15
19
|
Slugtastic.generate_slug("Slugtastic was built in 2012.").should eq "slugtastic-was-built-in-2012"
|
16
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -96,18 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- - ! '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
hash: -120995727452376200
|
102
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
100
|
none: false
|
104
101
|
requirements:
|
105
102
|
- - ! '>='
|
106
103
|
- !ruby/object:Gem::Version
|
107
104
|
version: '0'
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
hash: -120995727452376200
|
111
105
|
requirements: []
|
112
106
|
rubyforge_project:
|
113
107
|
rubygems_version: 1.8.23
|