mirror of
https://github.com/discourse/discourse.git
synced 2025-01-22 16:50:45 +08:00
Merge pull request #727 from ZogStriP/update-text-cleaner-to-remove-all-periods-from-the-end
Text Cleaner now removes all periods from the end of the title
This commit is contained in:
commit
9add8a74aa
|
@ -317,7 +317,14 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
|
||||||
categoryName: newCategoryName
|
categoryName: newCategoryName
|
||||||
});
|
});
|
||||||
// save the modifications
|
// save the modifications
|
||||||
topic.save();
|
topic.save().then(function(result){
|
||||||
|
// update the title if it has been changed (cleaned up) server-side
|
||||||
|
var title = result.basic_topic.fancy_title;
|
||||||
|
topic.setProperties({
|
||||||
|
title: title,
|
||||||
|
fancy_title: title
|
||||||
|
});
|
||||||
|
});
|
||||||
// close editing mode
|
// close editing mode
|
||||||
this.set('editingTopic', false);
|
this.set('editingTopic', false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class TextCleaner
|
||||||
deduplicate_question_marks: SiteSetting.title_prettify,
|
deduplicate_question_marks: SiteSetting.title_prettify,
|
||||||
replace_all_upper_case: SiteSetting.title_prettify,
|
replace_all_upper_case: SiteSetting.title_prettify,
|
||||||
capitalize_first_letter: SiteSetting.title_prettify,
|
capitalize_first_letter: SiteSetting.title_prettify,
|
||||||
remove_unnecessary_period: SiteSetting.title_prettify,
|
remove_all_periods_from_the_end: SiteSetting.title_prettify,
|
||||||
remove_extraneous_space: SiteSetting.title_prettify && SiteSetting.default_locale == "en",
|
remove_extraneous_space: SiteSetting.title_prettify && SiteSetting.default_locale == "en",
|
||||||
fixes_interior_spaces: true,
|
fixes_interior_spaces: true,
|
||||||
strip_whitespaces: true
|
strip_whitespaces: true
|
||||||
|
@ -30,8 +30,8 @@ class TextCleaner
|
||||||
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
|
||||||
text.sub!(/\A([a-z])/) { |first| first.capitalize } if opts[:capitalize_first_letter]
|
text.sub!(/\A([a-z])/) { |first| first.capitalize } if opts[:capitalize_first_letter]
|
||||||
# Remove unnecessary period at the end
|
# Remove unnecessary periods at the end
|
||||||
text.sub!(/([^.])\.(\s*)\z/, '\1\2') if opts[:remove_unnecessary_period]
|
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
|
||||||
text.sub!(/\s+([!?]\s*)\z/, '\1') if opts[:remove_extraneous_space]
|
text.sub!(/\s+([!?]\s*)\z/, '\1') if opts[:remove_extraneous_space]
|
||||||
# Fixes interior spaces
|
# Fixes interior spaces
|
||||||
|
|
|
@ -70,26 +70,24 @@ describe TextCleaner do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "period at the end" do
|
context "periods at the end" do
|
||||||
|
|
||||||
let(:with_period) { "oops." }
|
let(:with_one_period) { "oops." }
|
||||||
let(:with_periods) { "oops..." }
|
let(:with_several_periods) { "oops..." }
|
||||||
let(:without_period) { "oops" }
|
let(:without_period) { "oops" }
|
||||||
|
|
||||||
it "ignores unnecessary period at the end by default" do
|
it "ignores unnecessary periods at the end by default" do
|
||||||
TextCleaner.clean(with_period).should == with_period
|
TextCleaner.clean(with_one_period).should == with_one_period
|
||||||
|
TextCleaner.clean(with_several_periods).should == with_several_periods
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes unnecessary period at the end when enabled" do
|
it "removes unnecessary periods at the end when enabled" do
|
||||||
TextCleaner.clean(with_period, remove_unnecessary_period: true).should == without_period
|
TextCleaner.clean(with_one_period, remove_all_periods_from_the_end: true).should == without_period
|
||||||
end
|
TextCleaner.clean(with_several_periods, remove_all_periods_from_the_end: true).should == without_period
|
||||||
|
|
||||||
it "keeps ellipsis when enabled" do
|
|
||||||
TextCleaner.clean(with_periods, remove_unnecessary_period: true).should == with_periods
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "keeps trailing whitespaces when enabled" do
|
it "keeps trailing whitespaces when enabled" do
|
||||||
TextCleaner.clean(with_periods + " ", remove_unnecessary_period: true).should == with_periods + " "
|
TextCleaner.clean(with_several_periods + " ", remove_all_periods_from_the_end: true).should == without_period + " "
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user