mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
lean on Inflector transliteration
This commit is contained in:
parent
ecbaa45736
commit
9daf53df73
2 changed files with 10 additions and 7 deletions
11
lib/slug.rb
11
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+/, '-')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue