to_slug 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/to_slug.rb +4 -3
- data/lib/to_slug/version.rb +1 -1
- data/spec/to_slug_spec.rb +4 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/to_slug.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
class String # This reopns the string class
|
4
4
|
# Define a new method to convert the string to be url friendly
|
5
|
-
def to_slug
|
5
|
+
def to_slug(options={})
|
6
6
|
# This is the input as there are no arguments passed.
|
7
7
|
string = self
|
8
|
-
|
8
|
+
|
9
|
+
delimiter = options[:delimiter].nil? ? "-" : options[:delimiter]
|
9
10
|
|
10
11
|
# Define which accents map to which ascii characters
|
11
12
|
accents = {
|
@@ -111,7 +112,7 @@ class String # This reopns the string class
|
|
111
112
|
string.strip!
|
112
113
|
|
113
114
|
# Replace single spaces with a URL friendly dash (-)
|
114
|
-
string = string.gsub(/ /,"
|
115
|
+
string = string.gsub(/ /,"#{delimiter}")
|
115
116
|
|
116
117
|
# Do a greedy replace on multiple dashes
|
117
118
|
string = string.gsub(/-+/,"-")
|
data/lib/to_slug/version.rb
CHANGED
data/spec/to_slug_spec.rb
CHANGED
@@ -4,6 +4,10 @@ require 'to_slug'
|
|
4
4
|
|
5
5
|
describe String, "to_slug" do
|
6
6
|
|
7
|
+
it " does not replace spaces with dashes" do
|
8
|
+
"This is a string".to_slug(:delimiter=>" ").should == "this is a string"
|
9
|
+
end
|
10
|
+
|
7
11
|
it "replaces spaces with dashes" do
|
8
12
|
"This is a string".to_slug.should == "this-is-a-string"
|
9
13
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: to_slug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Eric Boehs
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-17 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|