Utils.slugify: Don't create new objects when gsubbing

This commit is contained in:
Parker Moore 2014-10-12 16:17:23 -07:00
parent b62415019b
commit 9f5835871b
1 changed files with 7 additions and 5 deletions

View File

@ -111,11 +111,13 @@ module Jekyll
# hyphen.
def slugify(string)
unless string.nil?
# Replace each non-alphanumeric character sequence with a hyphen
slug = string.gsub(/[^a-z0-9]+/i, '-')
# Remove leading/trailing hyphen
slug.gsub!(/^\-|\-$/i, '')
slug.downcase
string \
# Replace each non-alphanumeric character sequence with a hyphen
.gsub(/[^a-z0-9]+/i, '-') \
# Remove leading/trailing hyphen
.gsub(/^\-|\-$/i, '') \
# Downcase it
.downcase
end
end