-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8-3-renderPerson.js
49 lines (40 loc) Β· 1.04 KB
/
8-3-renderPerson.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* p297 μμ
*/
function renderPerson(outStream, person) {
const result = [];
result.push(`<p>${person.name}</p>`);
result.push(renderPhoto(person.photo));
result.push(emitPhotoData(person.photo));
return result.join('\n');
}
function photoDiv(p) {
return ['<div>', emitPhotoData(p), '</div>'].join('\n');
}
function emitPhotoData(p) {
return [
`<p>μ λͺ©: ${p.title}</p>`,
`<p>μμΉ: ${p.location}</p>`,
`<p>λ μ§: ${p.date.toString()}</p>`,
].join('\n');
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
function renderPhoto(photo) {
const result = [];
result.push(`<img src="${photo.src}" alt="${photo.alt}" />`);
return result.join('\n');
}
const rawPersonData = {
name: 'λ§ν΄ νμΈλ¬',
photo: {
src: 'https://commons.wikimedia.org/wiki/File:Webysther_20150414193208_-_Martin_Fowler.jpg',
alt: 'Martin Fowler.jpg',
title: '리ν©ν°λ§ μ μ',
location: 'μκ΅',
date: new Date('2022-11-19'),
},
};
const person = renderPerson('_', rawPersonData);
console.log(person);