mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:32:46 +08:00
Thread title fixer should ignore special cases like iLetter
This commit is contained in:
parent
8e8d9af2bf
commit
8bc4264c98
|
@ -28,8 +28,8 @@ class TextCleaner
|
||||||
text.gsub!(/\?+/, '?') if opts[:deduplicate_question_marks]
|
text.gsub!(/\?+/, '?') if opts[:deduplicate_question_marks]
|
||||||
# Replace all-caps text with regular case letters
|
# Replace all-caps text with regular case letters
|
||||||
text.tr!('A-Z', 'a-z') if opts[:replace_all_upper_case] && (text =~ /[A-Z]+/) && (text == text.upcase)
|
text.tr!('A-Z', 'a-z') if opts[:replace_all_upper_case] && (text =~ /[A-Z]+/) && (text == text.upcase)
|
||||||
# Capitalize first letter
|
# Capitalize first letter, but only when entire first word is lowercase
|
||||||
text.sub!(/\A([a-z])/) { |first| first.capitalize } if opts[:capitalize_first_letter]
|
text.sub!(/\A([a-z]*)\b/) { |first| first.capitalize } if opts[:capitalize_first_letter]
|
||||||
# Remove unnecessary periods at the end
|
# Remove unnecessary periods at the end
|
||||||
text.sub!(/([^.])\.+(\s*)\z/, '\1\2') if opts[:remove_all_periods_from_the_end]
|
text.sub!(/([^.])\.+(\s*)\z/, '\1\2') if opts[:remove_all_periods_from_the_end]
|
||||||
# Remove extraneous space before the end punctuation
|
# Remove extraneous space before the end punctuation
|
||||||
|
|
|
@ -57,15 +57,18 @@ describe TextCleaner do
|
||||||
|
|
||||||
let(:lowercased) { "this is awesome" }
|
let(:lowercased) { "this is awesome" }
|
||||||
let(:capitalized) { "This is awesome" }
|
let(:capitalized) { "This is awesome" }
|
||||||
|
let(:iletter) { "iLetter" }
|
||||||
|
|
||||||
it "ignores first letter case by default" do
|
it "ignores first letter case by default" do
|
||||||
TextCleaner.clean(lowercased).should == lowercased
|
TextCleaner.clean(lowercased).should == lowercased
|
||||||
TextCleaner.clean(capitalized).should == capitalized
|
TextCleaner.clean(capitalized).should == capitalized
|
||||||
|
TextCleaner.clean(iletter).should == iletter
|
||||||
end
|
end
|
||||||
|
|
||||||
it "capitalizes first letter when enabled" do
|
it "capitalizes first letter when enabled" do
|
||||||
TextCleaner.clean(lowercased, capitalize_first_letter: true).should == capitalized
|
TextCleaner.clean(lowercased, capitalize_first_letter: true).should == capitalized
|
||||||
TextCleaner.clean(capitalized, capitalize_first_letter: true).should == capitalized
|
TextCleaner.clean(capitalized, capitalize_first_letter: true).should == capitalized
|
||||||
|
TextCleaner.clean(iletter, capitalize_first_letter: true).should == iletter
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user