hmpo-template-mixins
Advanced tools
Comparing version 5.2.0 to 6.0.0
@@ -493,5 +493,6 @@ 'use strict'; | ||
return function (txt) { | ||
txt = (txt || '').split('|'); | ||
var value = hoganRender(txt[0], this); | ||
return moment(value).format(txt[1] || 'D MMMM YYYY'); | ||
txt = hoganRender(txt, this).split('|'); | ||
let value = txt[0]; | ||
let format = txt[1] || 'D MMMM YYYY'; | ||
return moment(value).format(format); | ||
}; | ||
@@ -542,6 +543,18 @@ }; | ||
return function (txt) { | ||
txt = hoganRender(txt, this); | ||
txt = txt.replace(/12:00am/i, 'midnight').replace(/^midnight/, 'Midnight'); | ||
txt = txt.replace(/12:00pm/i, 'midday').replace(/^midday/, 'Midday'); | ||
return txt; | ||
txt = hoganRender(txt, this).split('|'); | ||
let value = txt[0]; | ||
let options = txt[1] || 'short,midnight,midday'; | ||
options = _.indexBy(options.split(/\s*,\s*/)); | ||
if (options.midnight) { | ||
value = value.replace(/12:00am/ig, 'midnight'); | ||
value = value.replace(/^midnight/, 'Midnight'); | ||
} | ||
if (options.midday) { | ||
value = value.replace(/12:00pm/ig, 'midday'); | ||
value = value.replace(/^midday/, 'Midday'); | ||
} | ||
if (options.short) { | ||
value = value.replace(/:00(am|pm)/ig, '$1'); | ||
} | ||
return value; | ||
}; | ||
@@ -548,0 +561,0 @@ }; |
{ | ||
"name": "hmpo-template-mixins", | ||
"version": "5.2.0", | ||
"version": "6.0.0", | ||
"description": "A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -66,9 +66,12 @@ # passports-template-mixins | ||
t | ||
time | ||
selected | ||
lowercase | ||
uppercase | ||
capscase | ||
hyphenate | ||
date | ||
time | ||
currency | ||
currencyOrFree | ||
url | ||
select | ||
@@ -107,1 +110,36 @@ input-text | ||
- `child`: Render a child partial beneath each option in an `optionGroup`. Accepts a custom mustache template string, a custom partial in the format `partials/{your-partial-name}` or a template mixin key which will be rendered within a panel element partial. | ||
## `date` mixin | ||
Dates should be provided to the date lambda in ISO format | ||
``` | ||
{{#date}}2017-06-03T12:34:56.000Z{/date} | ||
3 June 2017 | ||
``` | ||
A moment format can be supplied. The default format is D MMMM YYYY. | ||
``` | ||
{{#date}}2017-06-3T12:34:56.000Z|DD MMM YYYY HH:MMa{/date} | ||
03 Jun 2017 12:34pm | ||
``` | ||
## `time` mixin | ||
The time formatter wraps a formatted time to correct for GDS standard: | ||
``` | ||
{{#time}}3:00pm{{/time}} | ||
3pm | ||
{{#time}}11 May 2017 at 12:00pm{{/time}} | ||
11 May 2017 at midday | ||
{{#time}}12:00am{{/time}} | ||
Midnight | ||
``` | ||
Comma separated options can be provided to only do transforms for midday, midnight, or shortened time: | ||
``` | ||
{{#time}}12:00pm|short,midnight{{/time}} | ||
12pm | ||
``` | ||
Sorry, the diff of this file is too big to display
124213
2421
144