Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions .github/workflows/plone-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ jobs:
fail-fast: false
matrix:
plone-version:
- "Plone52"
- "Plone60"
- "Plone61"
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
- "Plone62"
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

exclude:
- plone-version: "Plone52"
python-version: 3.9
- plone-version: "Plone52"
python-version: 3.10
- plone-version: "Plone52"
python-version: 3.11
- plone-version: "Plone52"
python-version: 3.12
- plone-version: "Plone52"
python-version: 3.13
- plone-version: "Plone60"
python-version: 3.8
python-version: "3.12"
- plone-version: "Plone60"
python-version: "3.13"
- plone-version: "Plone60"
python-version: "3.14"
- plone-version: "Plone61"
python-version: 3.8
python-version: "3.9"
- plone-version: "Plone61"
python-version: 3.9
python-version: "3.14"
- plone-version: "Plone62"
python-version: "3.9"

steps:
- uses: actions/setup-python@v4
Expand Down Expand Up @@ -68,12 +64,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Black-Check
run: |
tox -r -e black-check
- name: Test with tox
run: |
tox -r
tox
env:
PLONE-VERSION: ${{ matrix.plone-version }}
PYTHON-VERSION: ${{ matrix.python-version }}
41 changes: 38 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@
cs.srcset
=========

Backport of the `srcset` method added to the `@@images` view in plone.namedfile 7.1.0 to be able to use it in older Plone versions
Backport of the `srcset` method added to the `@@images` view in plone.namedfile 7.1.0 to be able to use it in older Plone versions.
It also includes an optimized `@@image_helper` view for Plone 6+ that uses catalog metadata to avoid N+1 performance issues in listings.

Features
--------

It adds a view called `@@images-srcset` that has a single method called `srcset` to be able to create an `img` tag with the `srcset` and `sizes`
attributes to render responsive images.
- Adds a view called `@@images-srcset` for older Plone versions (backport).
- Adds a view called `@@image_helper` optimized for Plone 6+ catalog metadata.

Read more about responsive images and its use in the `MDN documentation`_


Documentation
-------------

@@images-srcset
~~~~~~~~~~~~~~~

You should use this view like this ::

<img tal:define="images context/@@images-srcset;"
Expand All @@ -60,6 +64,37 @@ The meaning of each parameter is the following:
- additional attributes: any aditional attribute that will be rendered in the img tag, useful to add the title, alt, loading, fetchpriority, id, and other attributes.


@@image_helper
~~~~~~~~~~~~~~

This view is designed for high-performance listings in Plone 6.
It attempts to generate the ``<img>`` tag using only catalog metadata (``image_scales`` attribute in brains), avoiding expensive ``getObject()`` calls.
If metadata is missing, it gracefully falls back to the standard ``@@images`` view logic.

You should use this view like this ::

<tal:block tal:define="helper context/@@image_helper">
<div tal:replace="structure python:helper.srcset(item, fieldname='image', sizes='25vw', css_class='my-img')" />
</tal:block>

Available methods:

- ``srcset(item, fieldname='image', **kwargs)``: Returns a responsive ``<img>`` tag with the ``srcset`` attribute.
- ``tag(item, fieldname='image', scale=None, **kwargs)``: Returns a fixed ``<img>`` tag (optionally for a specific scale).

Parameters:

- ``item``: Either a catalog brain (recommended for performance) or a Plone object.
- ``fieldname``: The name of the image field (default: ``image``).
- ``scale_in_src``: (Only for the ``srcset`` method) The name of the scale to use for the ``src`` attribute (default: ``huge``).
- ``scale``: (Only for the ``tag`` method) The name of the scale to use for the ``src``.
- ``**kwargs``: Any other HTML attributes (``alt``, ``title``, ``loading``, ``css_class``, etc.).

Note: Unlike standard Plone views, this helper does **not** provide default values for ``alt`` or ``loading`` attributes.
Developers must provide them explicitly in the template if needed.
However, it **does** automatically provide ``width`` and ``height`` based on the rendered scale to prevent layout shifts.





Expand Down
3 changes: 2 additions & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ extends =
# test_plone50.cfg
# test_plone51.cfg
# test_plone52.cfg
test_plone60.cfg
# test_plone60.cfg
# test_plone61.cfg
test_plone62.cfg
2 changes: 1 addition & 1 deletion constraints.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-c constraints_plone60.txt
-c constraints_plone62.txt
9 changes: 0 additions & 9 deletions constraints_plone52.txt

This file was deleted.

4 changes: 2 additions & 2 deletions constraints_plone60.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
#certifi ; platform_system == 'Windows'
tox==4.11.3
isort>=5.12.0
black==22.8.0
flake8==5.0.4
black>=24.4.2
flake8>=7.0.0
4 changes: 2 additions & 2 deletions constraints_plone61.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
#certifi ; platform_system == 'Windows'
tox==4.11.3
isort>=5.12.0
black==22.8.0
flake8==5.0.4
black>=24.4.2
flake8>=7.0.0
16 changes: 16 additions & 0 deletions constraints_plone62.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-c https://dist.plone.org/release/6.2-latest/constraints.txt

#setuptools==54.0.0
#zc.buildout==3.0.0b2
#pip==21.0.1
#
## Windows specific down here (has to be installed here, fails in buildout)
## Dependency of zope.sendmail:
#pywin32 ; platform_system == 'Windows'
#
## SSL Certs on windows, because Python is missing them otherwise:
#certifi ; platform_system == 'Windows'
tox==4.11.3
isort>=5.12.0
black>=24.4.2
flake8>=7.0.0
Loading
Loading