mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Fixed word count grammar
Closes #349 - Added utility function to pluralize when appropriate.
This commit is contained in:
parent
94155039ee
commit
b92980ce6d
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'));
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -80,6 +80,49 @@ casper.test.begin("Haunted markdown in editor works", 3, function suite(test) {
|
||||
test.assertSelectorHasText('.entry-preview .rendered-markdown', 'Add image of some text', 'Editor value is correct');
|
||||
});
|
||||
|
||||
casper.run(function () {
|
||||
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