Guest User

Untitled

a guest
Feb 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. From 233020a2d01e9c4f0bfdd54657062312d2039a57 Mon Sep 17 00:00:00 2001
  2. From: Michael Koziarski <michael@koziarski.com>
  3. Date: Thu, 11 Sep 2008 16:03:38 +0200
  4. Subject: [PATCH] Flesh out the parameterize method to support non-ascii text and underscores.
  5.  
  6. ---
  7. activesupport/lib/active_support/inflector.rb | 2 +-
  8. activesupport/test/inflector_test_cases.rb | 5 ++++-
  9. 2 files changed, 5 insertions(+), 2 deletions(-)
  10.  
  11. diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
  12. index e5f0063..8a917a9 100644
  13. --- a/activesupport/lib/active_support/inflector.rb
  14. +++ b/activesupport/lib/active_support/inflector.rb
  15. @@ -257,7 +257,7 @@ module ActiveSupport
  16. # <%= link_to(@person.name, person_path %>
  17. # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
  18. def parameterize(string, sep = '-')
  19. - string.gsub(/[^a-z0-9]+/i, sep).downcase
  20. + string.chars.normalize(:kd).to_s.gsub(/[^\x00-\x7F]+/, '').gsub(/[^a-z0-9_\-]+/i, sep).downcase
  21. end
  22.  
  23. # Create the name of a table like Rails does for models to table names. This method
  24. diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
  25. index d399c90..8057809 100644
  26. --- a/activesupport/test/inflector_test_cases.rb
  27. +++ b/activesupport/test/inflector_test_cases.rb
  28. @@ -144,7 +144,10 @@ module InflectorTestCases
  29.  
  30. StringToParameterized = {
  31. "Donald E. Knuth" => "donald-e-knuth",
  32. - "Random text with *(bad)* characters" => "random-text-with-bad-characters"
  33. + "Random text with *(bad)* characters" => "random-text-with-bad-characters",
  34. + "Malmö" => "malmo",
  35. + "Garçons" => "garcons",
  36. + "Allow_Under_Scores" => "allow_under_scores"
  37. }
  38.  
  39. UnderscoreToHuman = {
  40. --
  41. 1.6.0.1
Add Comment
Please, Sign In to add comment