-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathhtml-document.ts
44 lines (40 loc) · 1.52 KB
/
html-document.ts
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
// A HTML document concrete class of AbstractDocument
import { Document, AbstractDocument } from './abstract-document'
export default class HTMLDocument extends AbstractDocument {
title(document: Document): void {
document['title'] = 'New HTML Document'
}
text(document: Document, text: string): void {
// Putting multiple lines into there own p tags
const lines = text.split('\n')
let markup = ''
lines.forEach((line) => {
markup = markup + ' <p>' + line + '</p>\n'
document['text'] = markup.substring(0, markup.length - 1)
})
}
print(document: Document): void {
// overriding print to output with html tags
console.log('<html>')
console.log(' <head>')
Object.keys(document).forEach((attribute: string) => {
if (['title', 'description', 'author'].indexOf(attribute) > -1) {
console.log(
` <${attribute}>${document[attribute]}</${attribute}>`
)
}
if (attribute === 'bg-col') {
console.log(' <style>')
console.log(' body {')
console.log(` background-color: ${document[attribute]};`)
console.log(' }')
console.log(' </style>')
}
})
console.log(' </head>')
console.log(' <body>')
console.log(`${document['text']}`)
console.log(' </body>')
console.log('</html>')
}
}