Add helper which convert singular and plural.

This commit is contained in:
takezoe
2013-07-04 08:57:43 +09:00
parent bf4bd6e319
commit a326e4b095
3 changed files with 9 additions and 11 deletions

View File

@@ -18,6 +18,13 @@ object helpers {
*/
def date(date: Date): String = new SimpleDateFormat("yyyy-MM-dd").format(date)
/**
* Returns singular if count is 1, otherwise plural.
* If plural is not specified, returns singular + "s" as plural.
*/
def plural(count: Int, singular: String, plural: String = ""): String =
if(count == 1) singular else if(plural.isEmpty) singular + "s" else plural
/**
* Converts Markdown of Wiki pages to HTML.
*/

View File

@@ -117,11 +117,7 @@
<span class="label label-success issue-status">Open</span>
}
<div class="small" style="text-align: center;">
@if(comments.size == 1){
<strong>1</strong> comment
} else {
<strong>@comments.size</strong> comments
}
<strong>@comments.size</strong> @plural(@comments.size, "comment")
</div>
<hr/>
<div style="margin-bottom: 8px;">

View File

@@ -176,12 +176,7 @@
<span class="pull-right muted">#@issue.issueId</span>
<div class="small muted">
Opened by <a href="@url(issue.openedUserName)" class="username">@issue.openedUserName</a> @datetime(issue.registeredDate)&nbsp;
@if(commentCount == 1){
<i class="icon-comment"></i><a href="@url(repository)/issues/@issue.issueId" class="issue-comment-count">1 comment</a>
}
@if(commentCount > 1){
<i class="icon-comment"></i><a href="@url(repository)/issues/@issue.issueId" class="issue-comment-count">@commentCount comments</a>
}
<i class="icon-comment"></i><a href="@url(repository)/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a>
</div>
</td>
</tr>