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

Refactor: svg group fix and blur #36

Merged
merged 2 commits into from
Apr 29, 2018
Merged

Conversation

axe312ger
Copy link
Owner

@axe312ger axe312ger commented Apr 17, 2018

This is my first attempt to change the inner code logic of sqip on the road to a plugin based system (See #30)

It does the following:

  • Split up svg fix and group + blur injection. Basically making blur the first "plugin" (Still lacking plugin conf ofc)
  • Replace the regex group injection with cheerio which should be way more flexible. This may allow using non-primitive svgs for the plugins later on.

@axe312ger axe312ger self-assigned this Apr 17, 2018
@axe312ger axe312ger requested a review from efegurkan April 17, 2018 17:31
"files": [
"src",
"vendor"
],
Copy link
Owner Author

Choose a reason for hiding this comment

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

Prettier 🤷‍♂️

@@ -1,4 +1,5 @@
#! /usr/bin/env node
#!/usr/bin/env node

Copy link
Owner Author

Choose a reason for hiding this comment

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

Recommendation from eslint-plugin-node :)

}

// Remove x and y attributes since they default to 0
// @todo test in rare browsers
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is because there is no need to have a background rectangle which contains the exact width of the svg. The engine can calculate this on its own. So a 0 0 100% 100% sizing should be totally fine.

@codecov-io
Copy link

codecov-io commented Apr 17, 2018

Codecov Report

Merging #36 into next will increase coverage by 1.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##            next      #36      +/-   ##
=========================================
+ Coverage   93.4%   94.59%   +1.18%     
=========================================
  Files          6        6              
  Lines         91      111      +20     
  Branches      11       13       +2     
=========================================
+ Hits          85      105      +20     
  Misses         5        5              
  Partials       1        1
Impacted Files Coverage Δ
src/cli.js 0% <ø> (ø) ⬆️
src/index.js 92.85% <100%> (ø) ⬆️
src/utils/svg.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1521ed...6f50b3d. Read the comment docs.


exports[`replaceSVGAttrs svg with group, config with dimensions only 1`] = `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 1024 640\\"><filter id=\\"b\\"><feGaussianBlur stdDeviation=\\"12\\" /></filter><path fill=\\"#bada55\\" d=\\"M0 0h1024v640H0z\\"/><g filter=\\"url(#b)\\"><path fill=\\"#C0FFEE\\" d=\\"M51.5 17.5l4 18 15 1z\\"/></g></svg>"`;
exports[`applies blur filter svg with group and blur 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><filter id=\\"b\\"><feGaussianBlur stdDeviation=\\"5\\"/></filter><rect fill=\\"#bada55\\"/><g filter=\\"url(#b)\\"><g><path fill=\\"#C0FFEE\\" d=\\"M51.5 17.5l4 18 15 1z\\"/></g></g></svg>"`;
Copy link
Owner Author

Choose a reason for hiding this comment

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

I wonder if the xmlns attribute should be required by us. AFAIK svgo adds it, but as we do already ensure there is a viewbox we could do more optimizations to ensure the svg will render properly in all browsers ❓

@axe312ger
Copy link
Owner Author

I have to admit that the test names are not that ideal, I might change it before merging 🙈

@axe312ger axe312ger mentioned this pull request Apr 17, 2018
7 tasks
@axe312ger
Copy link
Owner Author

@efegurkan While this is still slightly in progress (mostly the tests), I'd love to get some feedback :)

@efegurkan
Copy link
Collaborator

This seems good.

For the tests, since you are changing the API a lot, I will suggest not to care too much on Unit tests until you feel good about the plugin. When we did first implementation with @technopagan I made the code as much as "pipeline-ish" sense. In theory all of this parts can be moved to separate modules as you did in this PR. And most of them can be written side-effect free. 🎉

You may want to move svg templates to folder like fixtures maybe to make the tests more readable for future cases.

And I will suggest separating the default plugins to three part as:

  • Generating SVG
  • Modifiying/Altering SVG
  • Optimization

Feel free to name them as you like ofc :)

Very nice PR 👍

@axe312ger axe312ger merged commit 00c550c into next Apr 29, 2018
@axe312ger axe312ger deleted the refactor/svg-group-fix-and-blur branch April 29, 2018 11:50
@axe312ger
Copy link
Owner Author

Great and thanks for your nice words.

So, I will do clean up and proper naming later on, I like that very much.

Merged it, next step is async API 🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants