2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-06-06 05:18:03 +04:00
|
|
|
import counter from 'ghost/utils/word-count';
|
2014-03-02 18:30:35 +04:00
|
|
|
|
2015-02-09 18:57:50 +03:00
|
|
|
var countWords = Ember.HTMLBars.makeBoundHelper(function (arr /* hashParams */) {
|
|
|
|
if (!arr || !arr.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var markdown,
|
|
|
|
count;
|
|
|
|
|
|
|
|
markdown = arr[0] || '';
|
|
|
|
|
2014-06-06 05:18:03 +04:00
|
|
|
if (/^\s*$/.test(markdown)) {
|
|
|
|
return '0 words';
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:57:50 +03:00
|
|
|
count = counter(markdown);
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-06-06 05:18:03 +04:00
|
|
|
return count + (count === 1 ? ' word' : ' words');
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
export default countWords;
|