Generalize Utils#slugify for any scripts
It replaces any non alphanumeric glyphs by an hyphen.
This commit is contained in:
parent
81f4abdbcd
commit
f9e249ae20
|
@ -113,7 +113,7 @@ module Jekyll
|
|||
unless string.nil?
|
||||
string \
|
||||
# Replace each non-alphanumeric character sequence with a hyphen
|
||||
.gsub(/[^a-z0-9]+/i, '-') \
|
||||
.gsub(/[^[:alnum:]]+/i, '-') \
|
||||
# Remove leading/trailing hyphen
|
||||
.gsub(/^\-|\-$/i, '') \
|
||||
# Downcase it
|
||||
|
|
|
@ -120,6 +120,7 @@ class TestUtils < Test::Unit::TestCase
|
|||
|
||||
should "drop trailing punctuation" do
|
||||
assert_equal "so-what-is-jekyll-exactly", Utils.slugify("So what is Jekyll, exactly?")
|
||||
assert_equal "كيف-حالك", Utils.slugify("كيف حالك؟")
|
||||
end
|
||||
|
||||
should "ignore hyphens" do
|
||||
|
@ -134,6 +135,10 @@ class TestUtils < Test::Unit::TestCase
|
|||
assert_equal "customizing-git-git-hooks", Utils.slugify("Customizing Git - Git Hooks")
|
||||
end
|
||||
|
||||
should "replace punctuation in any scripts by hyphens" do
|
||||
assert_equal "5時-6時-三-一四", Utils.slugify("5時〜6時 三・一四")
|
||||
end
|
||||
|
||||
should "not modify the original string" do
|
||||
title = "Quick-start guide"
|
||||
Utils.slugify(title)
|
||||
|
|
Loading…
Reference in New Issue