Extract _scale_url() for overridable scale URL generation#200
Conversation
Refactor hardcoded @@images URL building into an overridable _scale_url(uid, extension, base_url=None) method on both ImageScale and ImageScaling classes. This allows custom image backends (e.g. Thumbor) to generate direct URLs without copying entire methods. Refs #199
|
@jensens thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment: To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
|
@jenkins-plone-org please run jobs |
|
Additional: I first was thinking about using a ZCA utility, but its some overhead to override 3loc in 2 places and IMO not worth the effort. |
erral
left a comment
There was a problem hiding this comment.
I think it makes total sense to have a method to create such urls
Summary
@@imagesURL building into an overridable_scale_url(uid, extension, base_url=None)method on bothImageScaleandImageScaling__init__,srcset_attribute(), andsrcset()now delegates to_scale_url()@@imagesredirectsMotivation
Currently, scale URLs are hardcoded inline in multiple places as
f"{base_url}/@@images/{uid}.{extension}". Custom scaling backends that want to produce different URLs (e.g. direct CDN/Thumbor URLs) must copy entire methods. This refactor provides a clean override point.See #199 for the original proposal.
Example usage
Test plan
TestScaleUrlcovering default behavior, custom base URL, subclass override on both classes, and srcset integrationCloses #199