Releases: django-components/django-components
0.126
What's Changed
Refactor
- Improved render time ~5x by replacing BeautifulSoup4 with own Rust HTML parser implementation.
- The heuristic for inserting JS and CSS dependenies into the default place has changed.
- JS is still inserted at the end of the
<body>
, and CSS at the end of<head>
. - However, we find end of
<body>
by searching for last occurrence of</body>
- And for the end of
<head>
we search for the first occurrence of</head>
- JS is still inserted at the end of the
Full Changelog: 0.125...0.126
0.125
What's Changed
EmilStenstrom/django-components
to django-components/django-components
.
Repo name and documentation URL changed. Package name remains the same.
If you see any broken links or other issues, please report them in #922.
Feat
-
@template_tag
andBaseNode
- A decorator and a class that allow you to define
custom template tags that will behave similarly to django-components' own template tags.Read more on Template tags.
Template tags defined with
@template_tag
andBaseNode
will have the following features:-
Accepting args, kwargs, and flags.
-
Allowing literal lists and dicts as inputs as:
key=[1, 2, 3]
orkey={"a": 1, "b": 2}
-
Using template tags tag inputs as:
{% my_tag key="{% lorem 3 w %}" / %}
-
Supporting the flat dictionary definition:
attr:key=value
-
Spreading args and kwargs with
...
:{% my_tag ...args ...kwargs / %}
-
Being able to call the template tag as:
{% my_tag %} ... {% endmy_tag %}
or{% my_tag / %}
-
Refactor
-
Refactored template tag input validation. When you now call template tags like
{% slot %}
,{% fill %}
,{% html_attrs %}
, and others, their inputs are now
validated the same way as Python function inputs are.So, for example
{% slot "my_slot" name="content" / %}
will raise an error, because the positional argument
name
is given twice.NOTE: Special kwargs whose keys are not valid Python variable names are not affected by this change.
So when you define:{% component data-id=123 / %}
The
data-id
will still be accepted as a valid kwarg, assuming that yourget_context_data()
accepts**kwargs
:def get_context_data(self, **kwargs): return { "data_id": kwargs["data-id"], }
Full Changelog: 0.124...0.125
0.124
What's Changed
Feat
-
Instead of inlining the JS and CSS under
Component.js
andComponent.css
, you can move
them to their own files, and link the JS/CSS files withComponent.js_file
andComponent.css_file
.Even when you specify the JS/CSS with
Component.js_file
orComponent.css_file
, then you can still
access the content underComponent.js
orComponent.css
- behind the scenes, the content of the JS/CSS files
will be set toComponent.js
/Component.css
upon first access.The same applies to
Component.template_file
, which will populateComponent.template
upon first access.With this change, the role of
Component.js/css
and the JS/CSS inComponent.Media
has changed:- The JS/CSS defined in
Component.js/css
orComponent.js/css_file
is the "main" JS/CSS - The JS/CSS defined in
Component.Media.js/css
are secondary or additional
See the updated "Getting Started" tutorial
- The JS/CSS defined in
Refactor
-
The canonical way to define a template file was changed from
template_name
totemplate_file
, to align with the rest of the API.template_name
remains for backwards compatibility. When you get / settemplate_name
,
internally this is proxied totemplate_file
. -
The undocumented
Component.component_id
was removed. Instead, useComponent.id
. Changes:- While
component_id
was unique every time you instantiatedComponent
, the newid
is unique
every time you render the component (e.g. withComponent.render()
) - The new
id
is available only during render, so e.g. from withinget_context_data()
- While
-
Component's HTML / CSS / JS are now resolved and loaded lazily. That is, if you specify
template_name
/template_file
,
js_file
,css_file
, orMedia.js/css
, the file paths will be resolved only once you:- Try to access component's HTML / CSS / JS, or
- Render the component.
Read more on Accessing component's HTML / JS / CSS.
-
Component inheritance:
- When you subclass a component, the JS and CSS defined on parent's
Media
class is now inherited by the child component. - You can disable or customize Media inheritance by setting
extend
attribute on theComponent.Media
nested class. This work similarly to Django'sMedia.extend
. - When child component defines either
template
ortemplate_file
, both of parent'stemplate
andtemplate_file
are ignored. The same applies tojs_file
andcss_file
.
- When you subclass a component, the JS and CSS defined on parent's
-
Autodiscovery now ignores files and directories that start with an underscore (
_
), except__init__.py
-
The Signals emitted by or during the use of django-components are now documented, together the
template_rendered
signal.
Full Changelog: 0.123...0.124
0.123
What's Changed
Fix
- Fix edge cases around rendering components whose templates used the
{% extends %}
template tag (#859) (thanks @ldurey)
Full Changelog: 0.122...0.123
0.122
What's Changed
Feat
- Add support for HTML fragments. HTML fragments can be rendered by passing
type="fragment"
toComponent.render()
orComponent.render_to_response()
. Read more on how to use HTML fragments with HTMX, AlpineJS, or vanillaJS.
Full Changelog: 0.121...0.122
0.121
What's Changed
Fix
- Fix the use of Django template filters (
|lower:"etc"
) with component inputs #855.
Docs
- docs: fix links in README and "overview" section, add tutorial in #842
Full Changelog: 0.120...0.121
0.120
What's Changed
Fix
- Fix the use of translation strings
_("bla")
as inputs to components #849.
Full Changelog: 0.119...0.120
0.119
What's Changed
Fix
-
Fix compatibility with custom subclasses of Django's
Template
that need to access
origin
or other initialization arguments. (#828) -
Fix compatibility with
django-debug-toolbar-template-profiler
- Monkeypatching of Django'sTemplate
now happens up-front atAppConfig.ready()
(#825)
Refactor
- Internal parsing of template tags tag was updated. No API change. (#827)
Full Changelog: 0.118...0.119
0.118
What's Changed
Feat
-
Add support for
context_processors
andRenderContext
inside component templates (by @lhole in #817)Component.render()
andComponent.render_to_response()
now accept an extra kwargrequest
.def my_view(request) return MyTable.render_to_response( request=request )
-
When you pass in
request
, the component will useRenderContext
instead ofContext
.
Thus the context processors will be applied to the context. -
NOTE: When you pass in both
request
andcontext
toComponent.render()
, andcontext
is already an instance ofContext
, therequest
kwarg will be ignored.
-
Refactor
- Fix sampleproject component-relative (#833)
Docs
- Fix link to license in README (#834)
New Contributors
Full Changelog: 0.117...0.118
0.117
What's Changed
Fix
- The HTML parser no longer erronously inserts
<html><head><body>
on some occasions, and
no longer tries to close unclosed HTML tags (#793)
Refactor
- Replaced Selectolax with BeautifulSoup4 as project dependencies.
Full Changelog: 0.116...0.117