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

Allow bundles to be rendered after "theme" and "custom" bundles. #4054

Closed
wants to merge 2 commits into from

Conversation

thet
Copy link
Member

@thet thet commented Nov 8, 2024

JS and CSS resources can now be rendered after all other resources in their
resource group including the theme (e.g. the Barceloneta theme CSS).

There is a exception for custom CSS which can be defined in the theming
controlpanel. This one is always rendered as last style resource.

To render a resource after all other give it the "depends" value of "all". This
indicates that the resource depends on all other being rendered before. The
resource is then rendered as last resource of it's resource group.

This allows to override a theme with custom CSS from a bundle instead of having
to add the CSS customizations to the registry via the "custom_css" settings.
As a consequence, theme customization can now be done in the filesystem in
ordinary CSS files instead of being bound to a time consuming workflow which
involces upgrading the custom_css registry after every change.

Docs

plone/documentation#1802
plone/documentation#1803

@thet thet requested a review from petschki November 8, 2024 18:49
@mister-roboto
Copy link

@thet thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

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!

@thet thet requested review from jensens and ale-rt November 8, 2024 18:50
# Allow bundles to have "theme" resp. "theme" and "custom" as dependency
# so that bundles can be rendered after theme and custom resources.
js_names += ["theme"]
css_names += ["theme", "custom"]
Copy link
Member Author

Choose a reason for hiding this comment

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

See below in https://github.com/plone/Products.CMFPlone/pull/4054/files#diff-9e095767a08db89a248c84c46d31c75898eed2d7dc40b0757a835bb2af0ed95bR143 and https://github.com/plone/Products.CMFPlone/pull/4054/files#diff-9e095767a08db89a248c84c46d31c75898eed2d7dc40b0757a835bb2af0ed95bR165

If "theme" or "custom" does not exist (both added in line 192+) the bundle dependency cannot be resolved and the bundle is not included in the rendered output.

@thet
Copy link
Member Author

thet commented Nov 8, 2024

@jenkins-plone-org please run jobs

@stevepiercy
Copy link
Contributor

This needs to be documented, but I'm not sure where. Perhaps in Theming of Classic UI? That section is so sad.

Copy link
Member

@jensens jensens left a comment

Choose a reason for hiding this comment

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

I think this is a good enhancement. Anyway, this needs some documentation, since it is not obvious.

@jensens
Copy link
Member

jensens commented Nov 9, 2024

This needs to be documented, but I'm not sure where. Perhaps in Theming of Classic UI? That section is so sad.

I think this should go into https://6.docs.plone.org/classic-ui/static-resources.html

Copy link
Member

@petschki petschki left a comment

Choose a reason for hiding this comment

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

Somehow I could not get this to work correctly. I checked out your branch and tested it with the plone-fullscreen bundle:

  1. I added custom to depends, but the CSS was not added... also the .js is missing (because custom is only defined for CSS but the bundle has JS also)
  2. I added theme to depends and get the following traceback:
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 181, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 391, in publish_module
  Module ZPublisher.WSGIPublisher, line 285, in publish
  Module ZPublisher.mapply, line 98, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module zope.browserpage.simpleviewclass, line 44, in __call__
  Module Products.Five.browser.pagetemplatefile, line 127, in __call__
  Module Products.Five.browser.pagetemplatefile, line 59, in __call__
  Module zope.pagetemplate.pagetemplate, line 134, in pt_render
  Module Products.PageTemplates.engine, line 368, in __call__
  Module z3c.pt.pagetemplate, line 198, in render
  Module chameleon.zpt.template, line 328, in render
  Module chameleon.template, line 229, in render
  Module chameleon.utils, line 20, in raise_with_traceback
  Module chameleon.template, line 200, in render
  Module 1ac8f88237956af17a352f1fc406ccdd, line 1880, in render
  Module 985090d925cc459bf0e69fde89f3e030, line 903, in render_master
  Module 615bdf9739ecd0ffd4d4eee8b7a6ebd5, line 498, in render_master
  Module zope.contentprovider.tales, line 76, in __call__
  Module zope.viewlet.manager, line 157, in update
  Module zope.viewlet.manager, line 163, in _updateViewlets
  Module Products.CMFPlone.resources.browser.resource, line 260, in update
  Module webresource._api, line 719, in render
  Module webresource._api, line 678, in resolve
webresource._api.ResourceMissingDependencyError: webresource._api.ResourceMissingDependencyError: Resource defines missing dependency: <PloneScriptResource name="plone-fullscreen", depends="['theme']">

what am I missing here?

@ale-rt
Copy link
Member

ale-rt commented Nov 11, 2024

IMO custom should stay the last one.

@petschki
Copy link
Member

IMO custom should stay the last one.

+1 I think that would be the expected behavior. If I change something TTW it should override everything else (without using !important all the time)

@jensens
Copy link
Member

jensens commented Nov 11, 2024

IMO custom should stay the last one.

+1 I think that would be the expected behavior. If I change something TTW it should override everything else (without using !important all the time)

I too agree

@thet
Copy link
Member Author

thet commented Dec 3, 2024

@jenkins-plone-org please run jobs

@thet thet force-pushed the thet-bundle-after-theme branch from 758e21f to d2c378f Compare December 3, 2024 16:36
@thet
Copy link
Member Author

thet commented Dec 3, 2024

@jenkins-plone-org please run jobs

Bundles can now depend on the automatically added "theme" and "custom" bundles
from plone.app.theming and be rendered after those (e.g. after the
plonetheme.barceloneta CSS).

This allows to override a theme with custom CSS from a bundle instead of having
to add the CSS customizations to the registry via the "custom_css" settings.
As a consequence, theme customization can now be done in the filesystem in
ordinary CSS files instead of being bound to a time consuming workflow which
involces upgrading the registry after every change.
@thet thet force-pushed the thet-bundle-after-theme branch from d2c378f to ce0815c Compare December 3, 2024 21:17
@thet
Copy link
Member Author

thet commented Dec 3, 2024

@jenkins-plone-org please run jobs

@stevepiercy
Copy link
Contributor

Should I use the news item as the documentation for this new feature?

https://github.com/plone/Products.CMFPlone/pull/4054/files#diff-b79fc648ba65de1bd4da45d2bd3181b51ec6ff5b95fcb0cc91125609d52ad0fc

Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

While working on the documentation, I found a bug in the control panel that should be corrected either in this PR or a related one in the correct repository, if not this one.

The correct link and label are Theming of Classic UI.

Screenshot 2024-12-03 at 7 35 42 PM

@stevepiercy
Copy link
Contributor

PR created to address the bug in the control panel UI at plone/plone.app.theming#248.

While I'm in there, should I update any other control panel message?

bundle.jscompilation = f"http://foo.bar/{name}.js"
bundle.csscompilation = f"http://foo.bar/{name}.css"
bundle.depends = depends
return bundle
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason to move this code outside of the class?

Copy link
Member Author

Choose a reason for hiding this comment

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

because it's used in two different classes.
Keep it as it is or better move it back in?

Copy link
Member

Choose a reason for hiding this comment

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

But in the other class it is defined as a method... https://github.com/plone/Products.CMFPlone/pull/4054/files#diff-8ef40cff64bf27605c753443d198309a61a480a09ec62d66fed8152c607cb600R264

IMO leave it like it was or make the test classes inherit from a common class.

Comment on lines +264 to +272
# Fix "all" dependencies to be rendered after the last known non-all resource.
for resource in depends_all_js:
# Change all "all" to last known JS resource
dependencies = map(
lambda dep: dep if dep != "all" else last_js_bundle, resource.depends
)
# Remove None values, e.g. if no known JS resource was found
dependencies = filter(lambda dep: dep is not None, dependencies)
resource.depends = list(dependencies)
Copy link
Member

Choose a reason for hiding this comment

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

I think that use map and filter with two custom lambdas and then casting to a list can be replaced with a much more clear for cycle and probably performant for cycle.

thet added a commit to plone/documentation that referenced this pull request Dec 4, 2024
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Dec 4, 2024
Branch: refs/heads/master
Date: 2024-12-03T19:42:58-08:00
Author: Steve Piercy (stevepiercy) <[email protected]>
Commit: plone/plone.app.theming@1933dd8

Update link and label to Theming of Classic UI documentation

See plone/Products.CMFPlone#4054

Files changed:
M src/plone/app/theming/browser/controlpanel.pt
Repository: plone.app.theming

Branch: refs/heads/master
Date: 2024-12-03T20:09:51-08:00
Author: Steve Piercy (stevepiercy) <[email protected]>
Commit: plone/plone.app.theming@dc15462

Create 248.bugfix

Files changed:
A news/248.bugfix
Repository: plone.app.theming

Branch: refs/heads/master
Date: 2024-12-04T06:32:57-08:00
Author: Steve Piercy (stevepiercy) <[email protected]>
Commit: plone/plone.app.theming@907d61d

Merge pull request #248 from plone/docs-classic-ui-theming

Update link and label to Theming of Classic UI documentation

Files changed:
A news/248.bugfix
M src/plone/app/theming/browser/controlpanel.pt
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Dec 4, 2024
Branch: refs/heads/master
Date: 2024-12-03T19:42:58-08:00
Author: Steve Piercy (stevepiercy) <[email protected]>
Commit: plone/plone.app.theming@1933dd8

Update link and label to Theming of Classic UI documentation

See plone/Products.CMFPlone#4054

Files changed:
M src/plone/app/theming/browser/controlpanel.pt
Repository: plone.app.theming

Branch: refs/heads/master
Date: 2024-12-03T20:09:51-08:00
Author: Steve Piercy (stevepiercy) <[email protected]>
Commit: plone/plone.app.theming@dc15462

Create 248.bugfix

Files changed:
A news/248.bugfix
Repository: plone.app.theming

Branch: refs/heads/master
Date: 2024-12-04T06:32:57-08:00
Author: Steve Piercy (stevepiercy) <[email protected]>
Commit: plone/plone.app.theming@907d61d

Merge pull request #248 from plone/docs-classic-ui-theming

Update link and label to Theming of Classic UI documentation

Files changed:
A news/248.bugfix
M src/plone/app/theming/browser/controlpanel.pt
Copy link
Member

@petschki petschki left a comment

Choose a reason for hiding this comment

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

@thet I think we should rethink this and use the grouping api of webresource. If we move the resources with depends="all" to a new "deferred" ResourceGroup which gets resolved after the "theming" bundles then webresource does our work. See my experimental commit here: 92a82ec ...

dependencies = map(
lambda dep: dep if dep != "all" else last_css_bundle, resource.depends
)
# Remove None values, e.g. if no known JS resource was found
Copy link
Member

Choose a reason for hiding this comment

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

Remove None values, e.g. if no known JS resource was found

This is for CSS right?
The code in this cycle and in the one above looks the same.
If the treatment for the resources is equal maybe it is better to move it to a method?

@petschki
Copy link
Member

petschki commented Dec 6, 2024

Closed this in favor of #4076

@thet thet deleted the thet-bundle-after-theme branch December 6, 2024 09:23
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.

6 participants