mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #569 from gotdibbs/Issue469
Strip whitespace on post titles
This commit is contained in:
commit
5a908bd3d3
4 changed files with 61 additions and 1 deletions
|
@ -284,7 +284,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'click .markdown-help': 'showHelp'
|
'click .markdown-help': 'showHelp',
|
||||||
|
'blur #entry-title': 'trimTitle'
|
||||||
},
|
},
|
||||||
|
|
||||||
syncScroll: _.debounce(function (e) {
|
syncScroll: _.debounce(function (e) {
|
||||||
|
@ -320,6 +321,16 @@
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
trimTitle: function () {
|
||||||
|
var $title = $('#entry-title'),
|
||||||
|
rawTitle = $title.val(),
|
||||||
|
trimmedTitle = $.trim(rawTitle);
|
||||||
|
|
||||||
|
if (rawTitle !== trimmedTitle) {
|
||||||
|
$title.val(trimmedTitle);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// This updates the editor preview panel.
|
// This updates the editor preview panel.
|
||||||
// Currently gets called on every key press.
|
// Currently gets called on every key press.
|
||||||
// Also trigger word count update
|
// Also trigger word count update
|
||||||
|
|
|
@ -50,6 +50,8 @@ Post = GhostBookshelf.Model.extend({
|
||||||
|
|
||||||
this.set('content', converter.makeHtml(this.get('content_raw')));
|
this.set('content', converter.makeHtml(this.get('content_raw')));
|
||||||
|
|
||||||
|
this.set('title', this.get('title').trim());
|
||||||
|
|
||||||
if (this.hasChanged('status') && this.get('status') === 'published') {
|
if (this.hasChanged('status') && this.get('status') === 'published') {
|
||||||
this.set('published_at', new Date());
|
this.set('published_at', new Date());
|
||||||
// This will need to go elsewhere in the API layer.
|
// This will need to go elsewhere in the API layer.
|
||||||
|
|
|
@ -128,6 +128,31 @@ casper.test.begin("Word count and plurality", 4, function suite(test) {
|
||||||
test.assertSelectorHasText('.entry-word-count', '2 words', 'count of 2 produces plural "words".');
|
test.assertSelectorHasText('.entry-word-count', '2 words', 'count of 2 produces plural "words".');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
casper.run(function () {
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.test.begin('Title Trimming', function suite(test) {
|
||||||
|
var untrimmedTitle = ' test title ',
|
||||||
|
trimmedTitle = 'test title';
|
||||||
|
|
||||||
|
test.filename = 'editor_title_trimming_test.png';
|
||||||
|
|
||||||
|
casper.start(url + 'ghost/editor/', function testTitleAndUrl() {
|
||||||
|
test.assertTitle('', 'Ghost admin has no title');
|
||||||
|
}).viewport(1280, 1024);
|
||||||
|
|
||||||
|
casper.then(function populateTitle() {
|
||||||
|
casper.sendKeys('#entry-title', untrimmedTitle);
|
||||||
|
|
||||||
|
test.assertEvalEquals(function () {
|
||||||
|
|
||||||
|
return $('#entry-title').val();
|
||||||
|
|
||||||
|
}, trimmedTitle, 'Entry title should match expected value.');
|
||||||
|
});
|
||||||
|
|
||||||
casper.run(function () {
|
casper.run(function () {
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|
|
@ -162,6 +162,28 @@ describe('Post Model', function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can trim title', function (done) {
|
||||||
|
var untrimmedCreateTitle = ' test trimmed create title ',
|
||||||
|
untrimmedUpdateTitle = ' test trimmed update title ',
|
||||||
|
newPost = {
|
||||||
|
title: untrimmedCreateTitle,
|
||||||
|
content_raw: 'Test Content'
|
||||||
|
};
|
||||||
|
|
||||||
|
PostModel.add(newPost).then(function (createdPost) {
|
||||||
|
return new PostModel({ id: createdPost.id }).fetch();
|
||||||
|
}).then(function (createdPost) {
|
||||||
|
should.exist(createdPost);
|
||||||
|
createdPost.get('title').should.equal(untrimmedCreateTitle.trim());
|
||||||
|
|
||||||
|
return createdPost.save({ title: untrimmedUpdateTitle });
|
||||||
|
}).then(function (updatedPost) {
|
||||||
|
updatedPost.get('title').should.equal(untrimmedUpdateTitle.trim());
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).otherwise(done);
|
||||||
|
});
|
||||||
|
|
||||||
it('can generate a non conflicting slug', function (done) {
|
it('can generate a non conflicting slug', function (done) {
|
||||||
var newPost = {
|
var newPost = {
|
||||||
title: 'Test Title',
|
title: 'Test Title',
|
||||||
|
|
Loading…
Add table
Reference in a new issue