Resolves issue #78 #98

Closed
wants to merge 4 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+8 −1
Split
View
@@ -8,7 +8,7 @@ def meta_def name, &blk
class String
def slugize
- self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
+ self.downcase.gsub(/&/, '-and-').gsub(/[\s.,!?_+=]+/, '-').gsub(/^-+|[^a-z0-9-]+|-+$/, '').squeeze('-')
end
def humanize
View
@@ -279,6 +279,13 @@ def readme() "#{self[:name]}'s README" end
context "extensions to the core Ruby library" do
should("respond to iso8601") { Date.today }.respond_to?(:iso8601)
+
+ context "String#slugize" do
+ should("replace separators with -") { "a b,c.d!e?f_g+h=i".slugize }.equals "a-b-c-d-e-f-g-h-i"
+ should("replace `&` with `-and-`") { "a&b".slugize }.equals "a-and-b"
+ should("remove non-alphanumeric") { "a^b".slugize }.equals "ab"
+ should("squeeze multiple dashes") { "a-^-^-b".slugize }.equals "a-b"
+ end
end
end