mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Merge pull request #569 from gotdibbs/Issue469
Strip whitespace on post titles
This commit is contained in:
commit
5a908bd3d3
@ -284,7 +284,8 @@
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .markdown-help': 'showHelp'
|
||||
'click .markdown-help': 'showHelp',
|
||||
'blur #entry-title': 'trimTitle'
|
||||
},
|
||||
|
||||
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.
|
||||
// Currently gets called on every key press.
|
||||
// Also trigger word count update
|
||||
|
@ -50,6 +50,8 @@ Post = GhostBookshelf.Model.extend({
|
||||
|
||||
this.set('content', converter.makeHtml(this.get('content_raw')));
|
||||
|
||||
this.set('title', this.get('title').trim());
|
||||
|
||||
if (this.hasChanged('status') && this.get('status') === 'published') {
|
||||
this.set('published_at', new Date());
|
||||
// This will need to go elsewhere in the API layer.
|
||||
|
@ -132,3 +132,28 @@ casper.test.begin("Word count and plurality", 4, function suite(test) {
|
||||
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 () {
|
||||
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) {
|
||||
var newPost = {
|
||||
title: 'Test Title',
|
||||
|
Loading…
Reference in New Issue
Block a user