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