Базовый handlebars
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-02-18 02:47:00 +03:00
parent 425843c5ad
commit 1c7d4cc74e
11 changed files with 189 additions and 42 deletions

39
output/index.js Normal file
View File

@@ -0,0 +1,39 @@
const fs = require('fs')
const Handlebars = require('handlebars')
const OutputItem = require('./OutputItem')
class Output {
constructor () {
this.items = []
this.timestamp = null
}
addItem (...p) {
this.items.push(new OutputItem(...p))
}
async compileTemplate () {
const templateFile = await fs.readFileSync('./output/template.hbs', 'utf8')
const template = Handlebars.compile(templateFile)
return template(this)
}
async writeToFile (content) {
const filename = 'index.html'
try {
await fs.unlinkSync(filename)
} catch {
console.log('File probably doesnt exist')
}
fs.writeFileSync(filename, content, 'utf-8')
}
async submit () {
this.timestamp = new Date()
const content = await this.compileTemplate()
await this.writeToFile(content)
}
}
module.exports = new Output()