Last active
July 15, 2019 07:15
-
-
Save buroz/63010a90e690068a41bc7fdc300bbcd9 to your computer and use it in GitHub Desktop.
template engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
* { | |
box-sizing: border-box; | |
} | |
html { | |
margin: 0; | |
padding: 0; | |
} | |
body { | |
font-size: 14px; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-direction: column; | |
background-color: black; | |
color: white; | |
} | |
p { | |
font-size: 0.9rem; | |
} | |
h1 { | |
font-size: 2.5rem; | |
} | |
</style> | |
</head> | |
<body> | |
<p><strong style="color:red">METHOD: </strong>[<method>]</p> | |
<p><strong style="color:red">URL: </strong>[<url>]</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const render = (str, o) => { | |
const keys = Object.keys(o); | |
keys.forEach(c => { | |
let field = "[<" + c + ">]"; | |
let changedOne = field.replace(field, o[c]); | |
str = str.replace(field, changedOne); | |
}); | |
return str; | |
}; | |
const fileStr = readFileSync(join(process.cwd(), "index.html"), "utf-8"); | |
const rendered = render(fileStr, { | |
method: "bleep bloop", | |
url: "hebele hübele", | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment