Add a view helper for date formatting

This commit is contained in:
Rowan Manning
2013-09-16 10:26:21 +01:00
parent 188852129a
commit a7aad37ea0
5 changed files with 31 additions and 6 deletions

20
view/helper/date.js Normal file
View File

@@ -0,0 +1,20 @@
'use strict';
var moment = require('moment');
module.exports = helper;
function helper (register) {
// Format a date with Moment
register('date-format', function (context, block) {
var format = block.hash.format || 'YYYY-MM-DD HH:mm:ss';
return moment(context).format(format);
});
// Get a relative date
register('date-relative', function (context) {
return moment(context).fromNow();
});
};

View File

@@ -2,10 +2,10 @@
<ul>
{{#results}}
<li>
<b>Date:</b> {{date}}<br/>
<b>Errors:</b> {{count.error}}<br/>
<b>Warnings:</b> {{count.warning}}<br/>
<b>Notices:</b> {{count.notice}}
<b>Date:</b> {{date-format date format="DD MMM YYYY"}}<br/>
<b>Errors:</b> {{count.error}}<br/>
<b>Warnings:</b> {{count.warning}}<br/>
<b>Notices:</b> {{count.notice}}
</li>
{{/results}}
</ul>

View File

@@ -7,8 +7,9 @@
{{url}} ({{standard}})
{{#last_result}}
<br/>Last run: {{date}}
<br/>Errors: {{count.error}}
<br/>
Last run: {{date-format date format="DD MMM YYYY"}}<br/>
Errors: {{count.error}}
{{/last_result}}
</a>