-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move badge templates from doT โ Template literals #2428
Comments
Thanks for opening this. I'm marking this "good first issue." This is not the most straightforward task, though for someone who is comfortable with JavaScript and unit testing, they probably would be able to accomplish this without a lot of knowledge of Shields. It'd be a good introduction to the project, and also very high value. And, of course it's a great thing for an existing contributor or maintainer to take on, too. ๐ |
I've made an example here using the converted templates: Convert the doT template files to template strings: template.replace('<svg', 'return `<svg')
.replace(/\{\{=(.+?)\}\}/g, "${$1 ? `$2` : ''}")
.replace(/\{\{\?(.+?)\}\}(.+?)\{\{\?\}\}/g, "${$1}")
.replace(/\{\{\?(.+?)\}\}\r?\n(\s+)/g, "${$1 ?\n$2`")
.replace(/\r?\n(\s+)\{\{\?\}\}/g, "`\n$1: ''}")
.replace('</svg>', '</svg>`;'); Not sure how to go about it in shields though, will look into it tomorrow (hopefully) |
What do you think about this approach? Placeholder logic, though it conveys the ideaโฆ const hasLeftText = text[0].length > 0
const [leftWidth, rightWidth] = ...
const leftPadding = ...
const totalWidth = leftWidth + leftPadding + leftWidth
return `
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${totalWidth}" height="20">
...
` |
I've updated the CodePen using a similar approach, Not sure how to tidy it up more though: |
Looks like progress! Do you feel like playing with it further? I suppose the next things I'd suggest are destructuring |
I've done some initial investigation into the possible performance improvements. From what I can tell there is not much to be gained here. https://codepen.io/mbarkhau/pen/xMvvRd?editors=0010 Of course I may be doing an unfair comparison, but even if that is the case, I doubt that performance would be the main justification for this change vs the other objectives. |
Thanks for looking into that! I think improving readability, DRY, and eliminating the mental overhead of another library are good reasons to do it. |
Hey @RedSparr0w, mind if I pick this up? |
While working on #2428 I found myself wanting to reload the server frequently. This is working great and reducing my iteration time significantly. I should have tackled this way sooner! :P Iโve left verbose on which seems useful, at least in the short term while weโre tuning the configuration. Close #2426
While working on #2428 I found myself wanting to reload the server frequently. This is working great and reducing my iteration time significantly. I should have tackled this way sooner! :P Iโve left verbose on which seems useful, at least in the short term while weโre tuning the configuration. Close #2426
I'm making good progress on this. I should have a PR up sometime in the next couple of days. It doesn't have exact parity right now, or run through the optimizer, so there is a bit of testing that needs to be done to make sure nothing is broken. |
While working on #2428 I found myself wanting to reload the server frequently. This is working great and reducing my iteration time significantly. I should have tackled this way sooner! ๐ Iโve left `verbose` on which seems useful, at least in the short term while weโre tuning the configuration. Close #2426
๐ Description
#2394 (comment)
Rewrite the badge templates to use template literals.
๐ฏ Objective
โ๏ธ TODO
The text was updated successfully, but these errors were encountered: