lean on Inflector transliteration

This commit is contained in:
Dan Neumann 2013-02-11 20:34:38 -06:00
parent ecbaa45736
commit 9daf53df73
2 changed files with 10 additions and 7 deletions

View file

@ -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+/, '-')

View file

@ -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