Skip to content
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

Template literal templates #4459

Merged
merged 32 commits into from
Jan 9, 2020
Merged

Conversation

chris48s
Copy link
Member

@chris48s chris48s commented Dec 23, 2019

This turned into an absolute beast, but I think we're finally good for review. I suspect the review process for this one is going to be pretty involved too. I'll mark up the diff with a couple of specific comments, but here's some high level notes:

  • The core purpose of this PR is to remove use of the doT template library and move to generating SVG output using javascript template literals. The rendered SVG should be unchanged in all cases.
  • Paul started this work in Template literal templates #3637 and then it stalled. I've pretty much squashed all the work from that PR into 058fa48 (apart from the bit we already merged in Generate JSON badges without using a template [GithubSearch] #3395) and then iterated from there.
  • This PR targets the v3-dev branch, not master. Getting this merged will unblock the rest of the work we need to do on V3 so hopefully we'll be able to get the rest of the breaking changes done and merged to master once we can draw a line under this.
  • A secondary consequence of this work is we needed to re-consider our approach to SVG optimisation. Roughly in line with Paul's comments in Template literal templates #3637 (comment) I decided to drop SVGO at the library layer and mostly manually implement the optimisations (running SVGO won't be an exact no-op). See 286636d , 8e62a86 , b877bc9 and 2f62ab7 . The exception to this is that sometimes SVGO replaces a <rect> with a <path> element if the <path> takes up less characters. I haven't bothered implementing this optimisation. This does mean that we'll serve a few extra characters for every badge (the re-generated snapshots in ed24253 give an idea of the impact of this), but I think the tradeoff is OK.
  • I decided that flat, flat-square and plastic are all sufficiently similar that they are best thought of as slight variations of the same thing so they are implemented as child classes of a base class. This allows most of the implementation to be shared. for-the-badge and social styles were so different that they don't really shoehorn into that pattern, so those two are just implemented as completely bespoke render functions, as opposed to as subclasses of Badge.
  • Given this PR is really ripping out the guts of the core rendering logic and starting again, this PR could use review from more than one of the core maintainers.
  • There's a staging deploy at https://shields-staging-pr-4459.herokuapp.com/
  • Things that would be particularly useful to get feedback on:
    • Are we escaping all the things that need escaping - have I missed any calls to escapeXml()?
    • Are there any cases or situations I've forgotten to test?

Closes #2428
Refs #3587

@shields-ci
Copy link

shields-ci commented Dec 23, 2019

Warnings
⚠️

This PR targets v3-dev - It is likely that the target branch should be master

Messages
📖 ✨ Thanks for your contribution to Shields, @chris48s!

Generated by 🚫 dangerJS against 34db0f2

@lgtm-com
Copy link

lgtm-com bot commented Dec 23, 2019

This pull request introduces 3 alerts when merging 4e7c4d7 into c05394d - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class
  • 1 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Dec 28, 2019

This pull request introduces 2 alerts when merging 7eae7df into c05394d - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable
  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Dec 29, 2019

This pull request introduces 1 alert when merging c2bf4fd into c05394d - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Dec 30, 2019

This pull request introduces 1 alert when merging 5bba06f into c05394d - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@shields-cd shields-cd temporarily deployed to shields-staging-pr-4459 December 30, 2019 20:15 Inactive
@chris48s chris48s added blocker PRs and epics which block other work npm-package Badge generation and badge templates labels Dec 30, 2019
labelColor is always true anyway now we've given the param a default
at this layer of the application, a logo
should already be a base64 encoded string.

`logo: 'javascript'` renders
<image x="5" y="3" width="14" height="14" xlink:href="javascript"/>
which isn't really what we want to test

Passing logoColor to makeBadge() is completely meaningless
@shields-cd shields-cd temporarily deployed to shields-staging-pr-4459 January 5, 2020 15:18 Inactive
@shields-cd shields-cd temporarily deployed to shields-staging-pr-4459 January 5, 2020 18:59 Inactive
paulmelnikow
paulmelnikow previously approved these changes Jan 8, 2020
rightWidth++
const methodName = camelcase(template)
if (!(methodName in badgeRenderers)) {
throw new Error(`Unknown template: '${template}'`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, though at some point this should be consolidated with the style validation logicin gh-badges/lib/index.js.

@paulmelnikow
Copy link
Member

This is looking good!

@chris48s
Copy link
Member Author

chris48s commented Jan 8, 2020

Something I haven't done is look at a bunch of badges. What do you think about restoring the test page

Yep. Good call - that's now at https://shields-staging-pr-4459.herokuapp.com/dev/styles

Having looked at all those, I spotted another issue which I've fixed in 34db0f2

Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@chris48s chris48s merged commit 198aeaf into badges:v3-dev Jan 9, 2020
@chris48s chris48s deleted the template-literals2 branch January 9, 2020 19:59
@chris48s
Copy link
Member Author

chris48s commented Jan 9, 2020

Cheers for review all :)

I've merged this onto the v3-dev branch. Over the weekend I'll review where I got to with the v3 roadmap: what else needs to go into v3.0/what can wait till v3.1 and pick up the rest of this. I'd like to get to a stage where we can ship this sooner rather than later.

chris48s added a commit that referenced this pull request Jan 12, 2020
- Remove use of the doT template library and move to generating SVG output using javascript template literals.
- Drop SVGO and mostly manually implement the optimisations.
- Add a bunch more tests

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
chris48s added a commit that referenced this pull request Mar 8, 2020
- Remove use of the doT template library and move to generating SVG output using javascript template literals.
- Drop SVGO and mostly manually implement the optimisations.
- Add a bunch more tests

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
@chris48s chris48s mentioned this pull request Mar 8, 2020
chris48s added a commit that referenced this pull request Apr 23, 2020
* Validate input to BadgeFactory.create() (#3875)

* validate input to create()

* remove deprecated properties (#3881)

* remove BadgeFactory class (#3884)

* Template literal templates (#4459)

- Remove use of the doT template library and move to generating SVG output using javascript template literals.
- Drop SVGO and mostly manually implement the optimisations.
- Add a bunch more tests

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>

* drop raster support in package CLI (#4523)

* drop raster support in package CLI
* update docs

* rename gh-badges package to badge-maker

* rename gh-badges dir to badge-maker

* update relative imports and other refs to in parent dir

'gh-badges' --> 'badge-maker'

* update snyk service tests

This change is only tangentially related

We've used the shields repo as an example for these tests so
moving files around in our repo has a knock-on effect on them

* add missing type hints to dev style page

* write the changelog/migration guide for v3

* use extension in README CLI example

* update CLI help

whoops - missed this in #4523

* bump version

* update for self-hosting users

* README updates

* drop .format param from CLI, always output SVG

* Change text[] to label and message, Remove JSON output

- Change text[] to label and message
- Fix message only badge
- Remove JSON output format
- Update the docs

* update package-lock

* rename 'template' to 'style'

* handle invalid styles in coalesceBadge

* ensure makeBadge is passed a string for template in coalesceBadge()

issue #4925

* fix (logo/no label text/label color specified) case

issue #4926

* add example of (logo/no label text/label color specified) to style debug page

* update type defs

* padding fix for FTB style

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker PRs and epics which block other work npm-package Badge generation and badge templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants