Comparing version 1.0.9 to 1.0.10
{ | ||
"name": "uldu", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Ultra lightweight utility to create DOM nodes.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/chriskr/uldu", |
152
README.md
@@ -123,33 +123,35 @@ # uldu | ||
static calendar(year, today, holidays) { | ||
return [ | ||
'div', | ||
{'class': 'calendar'}, | ||
this.today(today), | ||
this.year(year, today, holidays), | ||
]; | ||
return ( | ||
['div', {'class': 'calendar'}, | ||
this.today(today), | ||
this.year(year, today, holidays), | ||
] | ||
); | ||
} | ||
static today(today) { | ||
return [ | ||
'header', | ||
['span', {'data-handler': 'previous-year'}, | ||
['i', {class: 'material-icons'}, 'chevron_left'], | ||
], | ||
[ | ||
'h1', | ||
`${WEEK_DAYS_LONG[today.day]}` + | ||
` ${MONTH_NAMES[today.month]} ${today.date}` | ||
], | ||
['span', {'data-handler': 'next-year'}, | ||
['i', {class: 'material-icons'}, 'chevron_right'], | ||
], | ||
]; | ||
const todayStr = [ | ||
WEEK_DAYS_LONG[today.day], | ||
MONTH_NAMES[today.month], | ||
String(today.date) | ||
].join(' '); | ||
return ( | ||
['header', | ||
['span', {'data-handler': 'previous-year'}, | ||
['i', {class: 'material-icons'}, 'chevron_left'], | ||
], | ||
['h1', todayStr], | ||
['span', {'data-handler': 'next-year'}, | ||
['i', {class: 'material-icons'}, 'chevron_right'], | ||
], | ||
] | ||
); | ||
} | ||
static year(year, today, holidays) { | ||
return [ | ||
'section', | ||
...Array.from(range(12)) | ||
.map(month => this.month(year, month, today, holidays)) | ||
]; | ||
const tables = Array.from(range(12)) | ||
.map(month => this.month(year, month, today, holidays)); | ||
return ['section', ...tables]; | ||
} | ||
@@ -159,44 +161,49 @@ | ||
const weeksOfMonth = getWeeksOfMonth(year, month); | ||
const table = ['table']; | ||
table.push([ | ||
'caption', | ||
['span', {'class': 'month-name'}, MONTH_NAMES[month]], | ||
['span', {'class': 'year-number'}, String(year)], | ||
]); | ||
const headRow = []; | ||
if (withWeekNubers) { | ||
headRow.push(['th', 'Week']); | ||
} | ||
const weekDays = rotate(WEEK_DAYS_SHORT, 1); | ||
headRow.push(...weekDays.map(wday => ['th', wday])); | ||
table.push(['thead', ['tr', ...headRow]]); | ||
const weekLabels = weekDays.map(wday => ['th', wday]); | ||
const weekRows = | ||
weeksOfMonth.map(week => this.week(year, month, week, today, holidays)); | ||
const holidaysList = this.holidays(year, month, holidays); | ||
table.push([ | ||
'tbody', | ||
...weeksOfMonth.map( | ||
week => this.week(year, month, week, today, holidays)) | ||
]); | ||
table.push(this.holidays(year, month, holidays)); | ||
return table; | ||
return ( | ||
['table', | ||
['caption', | ||
['span', {'class': 'month-name'}, MONTH_NAMES[month]], | ||
['span', {'class': 'year-number'}, String(year)], | ||
], | ||
['thead', | ||
['tr', | ||
['th', 'Week'], | ||
...weekLabels, | ||
] | ||
], | ||
['tbody', ...weekRows], | ||
holidaysList.length === 0 ? | ||
[] : | ||
['tfoot', | ||
['tr', | ||
['td', {'colspan': withWeekNubers ? '8' : '7'}, holidaysList] | ||
] | ||
] | ||
] | ||
); | ||
} | ||
static week(year, month, week, today, holidays, withWeekNubers = true) { | ||
static week(year, month, week, today, holidays) { | ||
const [weekNumber, weekDays] = week; | ||
const tr = ['tr']; | ||
if (withWeekNubers) { | ||
tr.push(['td', ['span', {'class': 'week-number'}, String(weekNumber)]]); | ||
} | ||
tr.push(...weekDays.map((day, index) => { | ||
const isToday = | ||
today.year === year && today.month === month && today.date === day; | ||
const isHoliday = isSunday(index) || | ||
holidays.isHoliday(year, month, day); | ||
const className = classes(isToday && 'today', isHoliday && 'holiday'); | ||
const weekRow = weekDays.map((day, index) => { | ||
const className = classes( | ||
isToday(today, year, month, day) && 'today', | ||
isHoliday(index, holidays, year, month, day) && 'holiday'); | ||
return ['td', {'class': className}, day > 0 ? String(day) : '']; | ||
})); | ||
return tr; | ||
}); | ||
return ( | ||
['tr', | ||
['td', | ||
['span', {'class': 'week-number'}, String(weekNumber)] | ||
], | ||
...weekRow | ||
] | ||
); | ||
} | ||
@@ -206,21 +213,12 @@ | ||
const holidaysOfMonth = holidays.getHolidays(year, month); | ||
if (holidaysOfMonth.length === 0) { | ||
return []; | ||
} | ||
return [ | ||
'tfoot', | ||
[ | ||
'tr', | ||
[ | ||
'td', {'colspan': withWeekNubers ? '8' : '7'}, | ||
[ | ||
'ul', {'class': 'holidays'}, | ||
...holidaysOfMonth.map(([day, name]) => ['li', `${day}. ${name}`]) | ||
] | ||
] | ||
return (holidaysOfMonth.length === 0 ? | ||
[] : | ||
['ul', {'class': 'holidays'}, | ||
...holidaysOfMonth.map(([day, name]) => ['li', `${day}. ${name}`]) | ||
] | ||
]; | ||
); | ||
} | ||
}; | ||
} | ||
``` | ||
28770
222