diff --git a/lib/slug.rb b/lib/slug.rb index c4fe8fdfb..13dc53033 100644 --- a/lib/slug.rb +++ b/lib/slug.rb @@ -11,14 +11,11 @@ module Slug str.gsub!(/^\s+|\s+$/, '') str.downcase! - from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;." - to = "aaaaeeeeiiiioooouuuunc-------" + # The characters we want to replace with a hyphen + str.tr!("·/_,:;.", "\-") - idx = 0 - from.each_char do |c| - str.gsub!(c, to[idx]) - idx += 1 - end + # Convert to ASCII or remove if transliteration is unknown. + str = ActiveSupport::Inflector.transliterate(str, '') str.gsub!(/[^a-z0-9 -]/, '') str.gsub!(/\s+/, '-') diff --git a/spec/components/slug_spec.rb b/spec/components/slug_spec.rb index fde5ebd8e..1390103cd 100644 --- a/spec/components/slug_spec.rb +++ b/spec/components/slug_spec.rb @@ -35,5 +35,11 @@ describe Slug do Slug.for("...hello").should == "hello" end + it 'handles our initial transliteration' do + from = "àáäâčďèéëěêìíïîľĺňòóöôŕřšťůùúüûýžñç" + to = "aaaacdeeeeeiiiillnoooorrstuuuuuyznc" + Slug.for(from).should == to + end + end