mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
Merge pull request #388 from gotdibbs/Fixed-word-count-grammar
Fixed word count grammar
This commit is contained in:
commit
0e5277c6ad
13
core/client/assets/lib/jquery-utils.js
vendored
13
core/client/assets/lib/jquery-utils.js
vendored
@ -82,4 +82,17 @@
|
||||
|
||||
$('.overlay').hideAway(); // TODO: Move to a more sensible global file.
|
||||
|
||||
/**
|
||||
* Adds appropriate inflection for pluralizing the singular form of a word when appropriate.
|
||||
* This is an overly simplistic implementation that does not handle irregular plurals.
|
||||
* @param {Number} count
|
||||
* @param {String} singularWord
|
||||
* @returns {String}
|
||||
*/
|
||||
$.pluralize = function inflect(count, singularWord) {
|
||||
var base = [count, ' ', singularWord];
|
||||
|
||||
return (count === 1) ? base.join('') : base.concat('s').join('');
|
||||
};
|
||||
|
||||
}());
|
@ -305,9 +305,9 @@
|
||||
preview.innerHTML = this.converter.makeHtml(this.editor.getValue());
|
||||
view.$('.js-drop-zone').upload({editor: true});
|
||||
Countable.once(preview, function (counter) {
|
||||
view.$('.entry-word-count').text(counter.words + ' words');
|
||||
view.$('.entry-character-count').text(counter.characters + ' characters');
|
||||
view.$('.entry-paragraph-count').text(counter.paragraphs + ' paragraphs');
|
||||
view.$('.entry-word-count').text($.pluralize(counter.words, 'word'));
|
||||
view.$('.entry-character-count').text($.pluralize(counter.characters, 'character'));
|
||||
view.$('.entry-paragraph-count').text($.pluralize(counter.paragraphs, 'paragraph'));
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -84,3 +84,46 @@ casper.test.begin("Haunted markdown in editor works", 3, function suite(test) {
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
|
||||
casper.test.begin("Word count and plurality", 4, function suite(test) {
|
||||
|
||||
casper.test.filename = "editor_plurality_test.png";
|
||||
|
||||
casper.start(url + "ghost/editor", function testTitleAndUrl() {
|
||||
test.assertTitle("", "Ghost admin has no title");
|
||||
}).viewport(1280, 1024);
|
||||
|
||||
casper.then(function checkZeroPlural() {
|
||||
test.assertSelectorHasText('.entry-word-count', '0 words', 'count of 0 produces plural "words".');
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.writeContentToCodeMirror('test');
|
||||
});
|
||||
|
||||
// We must wait after sending keys to CodeMirror
|
||||
casper.wait(1000, function doneWait() {
|
||||
this.echo('I\'ve waited for 1 seconds.');
|
||||
});
|
||||
|
||||
casper.then(function checkSinglular() {
|
||||
test.assertSelectorHasText('.entry-word-count', '1 word', 'count of 1 produces singular "word".');
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.writeContentToCodeMirror('test'); // append another word, assumes newline
|
||||
});
|
||||
|
||||
// We must wait after sending keys to CodeMirror
|
||||
casper.wait(1000, function doneWait() {
|
||||
this.echo('I\'ve waited for 1 seconds.');
|
||||
});
|
||||
|
||||
casper.then(function checkPlural() {
|
||||
test.assertSelectorHasText('.entry-word-count', '2 words', 'count of 2 produces plural "words".');
|
||||
});
|
||||
|
||||
casper.run(function () {
|
||||
test.done();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user