Skip to content

Commit

Permalink
Added pluralize helper to format text better.
Browse files Browse the repository at this point in the history
chapter13-3
  • Loading branch information
tmeasday committed Oct 19, 2015
1 parent a694341 commit 1480289
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions client/helpers/handlebars.js
@@ -0,0 +1,8 @@
Template.registerHelper('pluralize', function(n, thing) {
// fairly stupid pluralizer
if (n === 1) {
return '1 ' + thing;
} else {
return n + ' ' + thing + 's';
}
});
4 changes: 2 additions & 2 deletions client/templates/posts/post_item.html
Expand Up @@ -4,9 +4,9 @@
<div class="post-content">
<h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3>
<p>
{{votes}} Votes,
{{pluralize votes "Vote"}},
submitted by {{author}},
<a href="{{pathFor 'postPage'}}">{{commentsCount}} comments</a>
<a href="{{pathFor 'postPage'}}">{{pluralize commentsCount "comment"}}</a>
{{#if ownPost}}<a href="{{pathFor 'postEdit'}}">Edit</a>{{/if}}
</p>
</div>
Expand Down

0 comments on commit 1480289

Please sign in to comment.