[question] [discussion] why use pug
I was going through the code and I was wondering why do we use pug? Yeah, there are the includes but that can easily be done with simple javascript. We don't use it's more complex features.
i was wondering that as well
I'm not sure exactly, but we are also using the templating features of pug. I think this is a pretty good reason to use it, since every poll response and results page needs to have different options.
Personally, I prefer it to client side javascript tomfoolery but that's just my opinion
right that footer thing would be harder to implant with out it.
but why pug in particular?
@ShawKai91, watch this:
let resp = await fetch("http://url.to/the/footer/will?be=here");
resp = await resp.text();
document.querySelector(div.replace#footer).outerHTML = resp;
you can maybe do this for each one, but there is also this more elegant solution I use for my github pages:
let data = document.querySelector("script[src=\"http://url.to/exactly/this=javascript?file&goes=here"]")
.attributes["data-includes"].value
.split("|");
let includes = [];
data = data.map(el=>el.split(","));
includes.forEach(async i=>{
let raw = await fetch(i[1]);
let text = await raw.text();
let remove = document.querySelectorAll(`i.incl-${i[0]}`)
remove.forEach(r=>r.outerHTML = text);
})
and to use it we simply have to put this in the
of each page:<script src="http://url.to/exactly/this=javascript?file&goes=here" data-includes="header,http://url.to/the/header/will?be=here|footer,http://url.to/the/footer/will?be=here"></script>
and then put these in where we want the replacement to happen
<i class="incl-header"></i>
<i class="incl-footer"></i>
Implement this if you want, I won't because someone probs has a reason to use pug.
EDIT: Forgot to say this in the original comment, but 2 things to add:
- If you are worried about how this approach requires the client to do
n+1additional requests for every include, we can do this on the server side, by replacing it before even sending a response to the client. - I will go through the commit history and see who added pug and personaly ask him why.