slugorize 0.0.1 → 0.0.2
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/lib/slugorize.rb +4 -3
- data/lib/slugorize/version.rb +1 -1
- data/spec/slugorize_spec.rb +16 -12
- metadata +4 -4
data/lib/slugorize.rb
CHANGED
@@ -4,10 +4,11 @@ module Slugorize
|
|
4
4
|
def slugorize
|
5
5
|
result = self.downcase
|
6
6
|
result.gsub!(/&(#?[0-9a-z])+;/, '') # Ditch Entities
|
7
|
-
result.gsub!(/[^a-z0-9\_]/, '
|
7
|
+
result.gsub!(/[^a-z0-9\_]/, ' ') # Get rid of anything we don't like
|
8
|
+
result.gsub!(/\ +$/, '') # trim trailing spaces
|
9
|
+
result.gsub!(/^\ +/, '') # trim leading spaces
|
10
|
+
result.gsub!(/\ /, '_') # underscore!
|
8
11
|
result.gsub!(/_+/, '_') # collapse underscores
|
9
|
-
result.gsub!(/_$/, '') # trim underscores
|
10
|
-
result.gsub!(/^_/, '') # trim underscores
|
11
12
|
result
|
12
13
|
end
|
13
14
|
|
data/lib/slugorize/version.rb
CHANGED
data/spec/slugorize_spec.rb
CHANGED
@@ -2,36 +2,40 @@ require 'slugorize'
|
|
2
2
|
|
3
3
|
describe String do
|
4
4
|
describe "#slugorize" do
|
5
|
-
it "
|
5
|
+
it "lowercases everything" do
|
6
6
|
"FANTASTIC".slugorize.should == "fantastic"
|
7
7
|
end
|
8
8
|
|
9
|
-
it "
|
9
|
+
it "leaves alphanumerics and underscores alone" do
|
10
10
|
"abc_123".slugorize.should == "abc_123"
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "ditches entities" do
|
14
14
|
"abcæ_bxyz".slugorize.should == "abc_xyz"
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
'abc\'""!@#$%^*()/=+|\[],.<&>123'.slugorize.should == "abc_123"
|
17
|
+
it "strips all non_alphanumeric characters except _" do
|
18
|
+
'#$%^&*abc\'""!@#$%^*()/=+|\[],.<&>123#$%^&*'.slugorize.should == "abc_123"
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "replaces whitespace with an underscore" do
|
22
22
|
"abc\n\t xyz".slugorize.should == "abc_xyz"
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
26
|
-
"
|
25
|
+
it "trims spaces at the tail" do
|
26
|
+
"abc ".slugorize.should == "abc"
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
30
|
-
"
|
29
|
+
it "trims spaces at the head" do
|
30
|
+
" abc".slugorize.should == "abc"
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
34
|
-
"
|
33
|
+
it "allows an underscore at the head" do
|
34
|
+
"_abc".slugorize.should == "_abc"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "collapses multiple underscores" do
|
38
|
+
"___abc___xyz___".slugorize.should == "_abc_xyz_"
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugorize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164685060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164685060
|
25
25
|
description: Small string extension which normalizes strings making them suitable
|
26
26
|
for usage as a slug in a url. Based on code from Xavier Shay's Enki.
|
27
27
|
email:
|