Merge pull request #148 from danneu/slug-simplify

replace reinvention of #parameterize
This commit is contained in:
Robin Ward 2013-02-13 07:23:26 -08:00
commit a9da9c5fde
2 changed files with 3 additions and 23 deletions

View File

@ -6,27 +6,7 @@
module Slug module Slug
def self.for(string) def self.for(string)
str = string.dup.strip.downcase string.parameterize
# The characters we want to replace with a hyphen
str.tr!("·/_,:;.", "\-")
# Convert to ASCII or remove if transliteration is unknown.
str = ActiveSupport::Inflector.transliterate(str, '')
# Remove everything except alphanumberic, space, and hyphen characters.
str.gsub!(/[^a-z0-9 -]/, '')
# Replace multiple spaces with one hyphen.
str.gsub!(/\s+/, '-')
# Replace multiple hyphens with one hyphen.
str.gsub!(/\-+/, '-')
# Remove leading and trailing hyphens
str.gsub!(/^-|-$/, '')
str
end end
end end

View File

@ -13,8 +13,8 @@ describe Slug do
Slug.for('àllo').should == 'allo' Slug.for('àllo').should == 'allo'
end end
it 'removes symbols' do it 'replaces symbols' do
Slug.for('evil#trout').should == 'eviltrout' Slug.for('evil#trout').should == 'evil-trout'
end end
it 'handles a.b.c properly' do it 'handles a.b.c properly' do