Базовый 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

9
output/OutputItem.js Normal file
View File

@@ -0,0 +1,9 @@
module.exports = class OutputItem {
constructor (name, parts, set) {
this.name = name + ' prime'
this.parts = parts
this.set = set
this.difference = set - parts
}
}

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()

41
output/template.hbs Normal file
View File

@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Warframe Market Gaps</title>
<style>
* {
font-family: sans-serif;
}
ul li b {
text-transform: capitalize;
}
.timestamp {
font-size: small;
}
</style>
</head>
<body>
<h1>Warframe Market Gaps</h1>
<ul>
{{#each items}}
<li>
<b>{{this.name}}</b>
Parts price: {{this.parts}}
Set price: {{this.set}}
Difference: {{this.difference}}
</li>
{{/each}}
</ul>
<div class="timestamp">
Generated at {{timestamp}}
</div>
</body>
</html>