1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

code gardening in transliterate.rb

Saw this while doing a review of a patch:

* Normalize case and punctuation across comments.
* ascii -> ASCII
* Since I was on it, some blank lines that visually
  add some clarity IMO.
This commit is contained in:
Xavier Noria 2015-10-07 23:43:58 +02:00
parent fef1064052
commit eaa0cb7924

View file

@ -69,10 +69,12 @@ module ActiveSupport
# parameterize("Donald E. Knuth") # => "donald-e-knuth"
# parameterize("^trés|Jolie-- ") # => "tres-jolie"
def parameterize(string, sep = '-')
# replace accented chars with their ascii equivalents
# Replace accented chars with their ASCII equivalents.
parameterized_string = transliterate(string)
# Turn unwanted chars into the separator
# Turn unwanted chars into the separator.
parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep)
unless sep.nil? || sep.empty?
if sep == "-".freeze
re_duplicate_separator = /-{2,}/
@ -87,6 +89,7 @@ module ActiveSupport
# Remove leading/trailing separator.
parameterized_string.gsub!(re_leading_trailing_separator, ''.freeze)
end
parameterized_string.downcase!
parameterized_string
end