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