-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhandlebars-helpers.js
26 lines (22 loc) · 1.12 KB
/
handlebars-helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const Handlebars = require('handlebars')
Handlebars.registerHelper('getIcon', function (category, options) {
return category === '家居物業' ? `<i class="fas fa-home text-danger"></i>`
: category === '交通出行' ? `<i class="fas fa-shuttle-van text-primary"></i>`
: category === '休閒娛樂' ? `<i class="fas fa-grin-beam text-purple"></i>`
: category === '餐飲食品' ? `<i class="fas fa-utensils text-orange"></i>`
: `<i class="fas fa-pen text-success"></i>`
})
Handlebars.registerHelper('isSelected', function (selectedOption, thisOption, options) {
return (selectedOption === thisOption) ? 'selected' : ''
})
Handlebars.registerHelper('getDisplayDate', function (date, options) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return `${year}/${month}/${day}`
})
Handlebars.registerHelper('getInputDate', function (date, options) {
if (!date) { return '' }
const month = date.getMonth() === 11 ? 1 : date.getMonth() + 1
return `${date.getFullYear()}-${month.toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`
})