Explorar el Código

Commit 13-3: Added pluralize helper to format text better.

Frederic G. MARAND hace 9 años
padre
commit
ed916cdce8
Se han modificado 2 ficheros con 10 adiciones y 2 borrados
  1. 8 0
      client/helpers/spacebars.js
  2. 2 2
      client/templates/posts/post_item.html

+ 8 - 0
client/helpers/spacebars.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';
+  }
+});

+ 2 - 2
client/templates/posts/post_item.html

@@ -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>