Fix guide anchor generation logic.

This could use in any translation because it's not limited to `[^a-z0-9]`.

Verify after this change, all guides still have same anchors.

[Robin Dupret & Juanito Fatas]
This commit is contained in:
Juanito Fatas 2014-08-24 11:58:01 +08:00
parent 33c05363e2
commit 2735b9cf97
1 changed files with 6 additions and 1 deletions

View File

@ -47,7 +47,12 @@ module RailsGuides
end
def dom_id_text(text)
text.downcase.gsub(/\?/, '-questionmark').gsub(/!/, '-bang').gsub(/[^a-z0-9]+/, ' ').strip.gsub(/\s+/, '-')
escaped_chars = Regexp.escape('\\/`*_{}[]()#+-.!:,;|&<>^~=\'"')
text.downcase.gsub(/\?/, '-questionmark')
.gsub(/!/, '-bang')
.gsub(/[#{escaped_chars}]+/, ' ').strip
.gsub(/\s+/, '-')
end
def engine