lib/active_support/inflector.rb in activesupport-2.3.6.pre vs lib/active_support/inflector.rb in activesupport-2.3.6

- old
+ new

@@ -1,8 +1,9 @@ # encoding: utf-8 require 'singleton' require 'iconv' +require 'kconv' module ActiveSupport # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without, # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept # in inflections.rb. @@ -155,11 +156,11 @@ # "word".singularize # => "word" # "CamelOctopi".singularize # => "CamelOctopus" def singularize(word) result = word.to_s.dup - if inflections.uncountables.include?(result.downcase) + if inflections.uncountables.any? { |inflection| result =~ /#{inflection}\Z/i } result else inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) } result end @@ -255,9 +256,11 @@ # # => #<Person id: 1, name: "Donald E. Knuth"> # # <%= link_to(@person.name, person_path(@person)) %> # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a> def parameterize(string, sep = '-') + # remove malformed utf8 characters + string = string.toutf8 unless string.is_utf8? # replace accented chars with ther ascii equivalents parameterized_string = transliterate(string) # Turn unwanted chars into the seperator parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep) unless sep.blank?