Skip to content

Commit 9f62ef9

Browse files
author
quantra
committed
Documentation updated.
1 parent b8500ed commit 9f62ef9

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

README.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
Django Lazy srcset
1515
==================
1616

17-
Lazy srcset and image generation for Django. Minimum effort required. No database required.
17+
Lazy srcset and responsive image generation for Django. Minimum effort required. No database required.
1818

19-
Django Lazy srcset will create all the markup and images you need to provide responsive images via the srcset attribute. All you need to do is install it, configure your breakpoints and use the ``{% srcset %}`` template tag.
19+
Django Lazy srcset will create the markup and generate the images you need to provide responsive images via the `srcset and sizes attributes for the img tag <https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#resolution_switching_different_sizes>`_. All you need to do is install it, configure your breakpoints and use the ``{% srcset %}`` template tag.
2020

2121
All of the hard work (image generation and cacheing) is done by django-imagekit, by default this means images are generated just in time - lazily. Please see the `django-imagekit docs <https://django-imagekit.readthedocs.io>`_ for more info and configuration options.
2222

@@ -44,7 +44,7 @@ Add ``"imagekit"`` and ``"lazy_srcset"`` to ``INSTALLED_APPS``:
4444
# ...
4545
]
4646
47-
Configure your breakpoints and stuff:
47+
Configure your breakpoints and stuff (most/all of this is optional):
4848

4949
.. code-block:: python
5050
@@ -93,14 +93,32 @@ Use the ``{% srcset %}`` template tag:
9393
9494
Whilst not required it is advisable to take a nap at this stage.
9595

96-
For further documentation and examples of all the options please read the docstrings in the source code for `lazy_srcset/templatetags/lazy_srcset.py <https://github.com/Quantra/django-lazy-srcset/blob/master/lazy_srcset/templatetags/lazy_srcset.py>`_.
96+
For further documentation and examples of all the options please see the huge and obvious docstring in the source code for `lazy_srcset/templatetags/lazy_srcset.py <https://github.com/Quantra/django-lazy-srcset/blob/master/lazy_srcset/templatetags/lazy_srcset.py>`_.
9797

98-
Due to the awesomeness of imagekit it's possible to configure django-lazy-srcset to use any image generator you have registered on a per config basis. Take a look at `lazy_srcset/conf.py <https://github.com/Quantra/django-lazy-srcset/blob/master/lazy_srcset/conf.py>`_ to see how to change the ``generator_id`` setting. For an example image generator look at `lazy_srcset/imagegenerators.py <https://github.com/Quantra/django-lazy-srcset/blob/master/lazy_srcset/imagegenerators.py>`_. This is completely optional but I thought I'd mention it as there are potential artistic uses here; for example you could use a generator to add filters to images.
98+
Advanced
99+
--------
100+
101+
Due to the awesomeness of django-imagekit it's possible to configure django-lazy-srcset to use any image generator you have registered on a per config basis. Take a look at `lazy_srcset/conf.py <https://github.com/Quantra/django-lazy-srcset/blob/master/lazy_srcset/conf.py>`_ to see how to change the ``generator_id`` setting. For an example image generator look at `lazy_srcset/imagegenerators.py <https://github.com/Quantra/django-lazy-srcset/blob/master/lazy_srcset/imagegenerators.py>`_. This is completely optional but I thought I'd mention it as there are potential artistic uses here; for example you could use a generator to add filters to some images.
99102

100103
Currently imagekit ``SourceGroup`` has not been implemented therefore the imagekit ``generateimages`` management command will not generate images for django-lazy-srcset. If you want to pre-generate images you can ``render_to_string()`` your templates in an appropriate save method or signal. If you are using `django-content-blocks <https://github.com/Quantra/django-content-blocks>`_ this happens on publish anyway.
101104

102105
Clean up of old, unused files created by django-lazy-srcset is down to you, if you require it at all.
103106

107+
Development Status & Roadmap
108+
----------------------------
109+
110+
Django lazy srcset is in beta. There are currently no plans for further development.
111+
112+
Dependencies & Thank You
113+
------------------------
114+
115+
* https://github.com/matthewwithanm/django-imagekit/
116+
117+
Other Packages to Consider
118+
--------------------------
119+
120+
* https://github.com/codingjoe/django-pictures
121+
104122
.. shields.io badges
105123
106124
.. |package version| image:: https://img.shields.io/pypi/v/django-lazy-srcset

lazy_srcset/templatetags/lazy_srcset.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def sanitize_size(size):
8989

9090
try:
9191
size, units = int(size[:-2]), size[-2:]
92-
except IndexError:
92+
except (IndexError, ValueError):
9393
raise TemplateSyntaxError(
9494
"Invalid size: %s\nBreakpoints must be integers.\nSizes must specify vw or px units or be integers."
9595
% size
@@ -137,7 +137,7 @@ def srcset(*args, **kwargs):
137137
integers which are used to calculate generated image sizes. They must have units of vw or px only. If no units
138138
are supplied then vw is assumed.
139139
140-
kwargs can be used to provide break points and the relative width for each break point directly (ignoring the
140+
kwargs can be used to provide break points and the relative size for each break point directly (ignoring the
141141
config break points and args if you set them for some reason).
142142
143143
The config with the key ``default`` is used unless you provide the config kwarg to specify another config to use.
@@ -183,8 +183,9 @@ def srcset(*args, **kwargs):
183183
<!-- You can set the default size with units in the same way as the sizes args -->
184184
<img {% srcset image default_size='300px' %} />
185185
186-
<!-- You can mix and match all of the above -->
186+
<!-- You can mix and match all of the above E.g. -->
187187
<img {% srcset image 25 33 50 config='custom_breakpoints' max_width=1920 image_quality=50 threshold=100 %} />
188+
<img {% srcset image 1920=25 1024=50 default_size=50 image_quality=50 %} />
188189
"""
189190
# INIT
190191
args = list(args)
@@ -269,7 +270,7 @@ def srcset(*args, **kwargs):
269270

270271
# GO!
271272

272-
# Loop through the sizes_dict to create the widths list used for image generation.
273+
# Loop through the sizes_dict to create the widths_dict used for image generation.
273274
for breakpoint_width, (width, units) in sizes_dict.items():
274275
if units == "px":
275276
# When px units are defined always generate an image with that width
@@ -287,7 +288,7 @@ def srcset(*args, **kwargs):
287288
images = []
288289
for width in reversed(sorted(widths_dict.keys())):
289290
if not widths_dict[width] and (current_width - width) < threshold:
290-
# Only generate required images, images defined with px and images outside our threshold
291+
# Only generate required images and images outside our threshold
291292
continue
292293

293294
current_width = width

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
[metadata]
33
name = django-lazy-srcset
44
version = 0.2.2
5-
description = Lazy srcset and image generation for Django. Minimum effort required. No database required.
5+
description = Lazy srcset and responsive image generation for Django. Minimum effort required. No database required.
66
long_description = file:README.rst
77
long_description_content_type = text/x-rst
8+
url = https://github.com/Quantra/django-lazy-srcset
89
author = Vince Coleman
910
author_email = [email protected]
1011
license = MIT

0 commit comments

Comments
 (0)