mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Thread title fixer should ignore special cases like iLetter
This commit is contained in:
parent
8e8d9af2bf
commit
8bc4264c98
2 changed files with 5 additions and 2 deletions
|
@ -28,8 +28,8 @@ class TextCleaner
|
|||
text.gsub!(/\?+/, '?') if opts[:deduplicate_question_marks]
|
||||
# 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)
|
||||
# Capitalize first letter
|
||||
text.sub!(/\A([a-z])/) { |first| first.capitalize } if opts[:capitalize_first_letter]
|
||||
# Capitalize first letter, but only when entire first word is lowercase
|
||||
text.sub!(/\A([a-z]*)\b/) { |first| first.capitalize } if opts[:capitalize_first_letter]
|
||||
# Remove unnecessary periods at the end
|
||||
text.sub!(/([^.])\.+(\s*)\z/, '\1\2') if opts[:remove_all_periods_from_the_end]
|
||||
# Remove extraneous space before the end punctuation
|
||||
|
|
|
@ -57,15 +57,18 @@ describe TextCleaner do
|
|||
|
||||
let(:lowercased) { "this is awesome" }
|
||||
let(:capitalized) { "This is awesome" }
|
||||
let(:iletter) { "iLetter" }
|
||||
|
||||
it "ignores first letter case by default" do
|
||||
TextCleaner.clean(lowercased).should == lowercased
|
||||
TextCleaner.clean(capitalized).should == capitalized
|
||||
TextCleaner.clean(iletter).should == iletter
|
||||
end
|
||||
|
||||
it "capitalizes first letter when enabled" do
|
||||
TextCleaner.clean(lowercased, 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
|
||||
|
|
Loading…
Reference in a new issue