Skip to content

Instantly share code, notes, and snippets.

@buroz
Last active July 15, 2019 07:15
Show Gist options
  • Save buroz/63010a90e690068a41bc7fdc300bbcd9 to your computer and use it in GitHub Desktop.
Save buroz/63010a90e690068a41bc7fdc300bbcd9 to your computer and use it in GitHub Desktop.
template engine
<!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>
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