Skip to content

Commit 9daf53d

Browse files
committed
lean on Inflector transliteration
1 parent ecbaa45 commit 9daf53d

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

lib/slug.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ def self.for(string)
1111
str.gsub!(/^\s+|\s+$/, '')
1212
str.downcase!
1313

14-
from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;."
15-
to = "aaaaeeeeiiiioooouuuunc-------"
16-
17-
idx = 0
18-
from.each_char do |c|
19-
str.gsub!(c, to[idx])
20-
idx += 1
21-
end
14+
# The characters we want to replace with a hyphen
15+
str.tr!("·/_,:;.", "\-")
16+
17+
# Convert to ASCII or remove if transliteration is unknown.
18+
str = ActiveSupport::Inflector.transliterate(str, '')
2219

2320
str.gsub!(/[^a-z0-9 -]/, '')
2421
str.gsub!(/\s+/, '-')

spec/components/slug_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@
3535
Slug.for("...hello").should == "hello"
3636
end
3737

38+
it 'handles our initial transliteration' do
39+
from = "àáäâčďèéëěêìíïîľĺňòóöôŕřšťůùúüûýžñç"
40+
to = "aaaacdeeeeeiiiillnoooorrstuuuuuyznc"
41+
Slug.for(from).should == to
42+
end
43+
3844
end
3945

0 commit comments

Comments
 (0)