Skip to content

Commit f10e510

Browse files
committed
fix #187
1 parent 47f87ce commit f10e510

27 files changed

+1394
-1323
lines changed

doc/source/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Change Log
33
==========
44

5+
v3.3.1 (2025-07-16)
6+
===================
7+
8+
* Added `Convert docs to intersphinx references. <https://github.com/bckohan/django-render-static/issues/187>`_
9+
10+
511
v3.3.0 (2025-03-12)
612
====================
713

doc/source/commands.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
Commands
55
========
66

7-
.. _renderstatic:
8-
97
renderstatic
108
------------
119

10+
.. django-admin:: renderstatic
11+
1212
.. automodule:: render_static.management.commands.renderstatic
1313

1414
Usage
@@ -22,16 +22,16 @@ Usage
2222
Example
2323
~~~~~~~
2424

25-
To generate all templates configured in ``STATIC_TEMPLATES`` settings:
25+
To generate all templates configured in :setting:`STATIC_TEMPLATES` settings:
2626

27-
.. code::
27+
.. code-block:: bash
2828
2929
$ manage.py renderstatic
3030
31-
Alternatively individual templates can be generated, regardless of their presence
32-
in ``STATIC_TEMPLATES``. They will be given the global context with any overriding context
31+
Alternatively individual templates can be generated, regardless of their presence in
32+
:setting:`STATIC_TEMPLATES`. They will be given the global context with any overriding context
3333
parameters supplied on the command line:
3434

35-
.. code::
35+
.. code-block:: bash
3636
3737
$ manage.py renderstatic path/*.js -c ./js_context.yaml -d outputdir

doc/source/conf.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828

2929

3030
# -- Project information -----------------------------------------------------
31-
32-
project = 'django-render-static'
33-
copyright = f'2020-{datetime.now().year}, Brian Kohan'
34-
author = 'Brian Kohan'
35-
36-
# The full version, including alpha/beta/rc tags
31+
project = render_static.__title__
32+
copyright = render_static.__copyright__
33+
author = render_static.__author__
3734
release = render_static.__version__
3835

39-
4036
# -- General configuration ---------------------------------------------------
4137

4238
# Add any Sphinx extension module names here, as strings. They can be
@@ -46,7 +42,9 @@
4642
'sphinx.ext.autodoc',
4743
'sphinx.ext.viewcode',
4844
'sphinx.ext.todo',
49-
'sphinxcontrib.typer'
45+
'sphinxcontrib.typer',
46+
'sphinx.ext.intersphinx',
47+
'sphinxcontrib_django'
5048
# 'sphinx_js'
5149
]
5250

@@ -82,3 +80,36 @@
8280
# str(Path(__file__).parent.parent.parent / 'render_static' / 'tests' /
8381
# 'examples' / 'static' / 'examples'
8482
# )
83+
84+
autodoc_default_options = {
85+
'show-inheritance': True,
86+
# Add other autodoc options here if desired, e.g.:
87+
# 'members': True,
88+
# 'inherited-members': True,
89+
}
90+
91+
intersphinx_mapping = {
92+
"django": (
93+
"https://docs.djangoproject.com/en/stable",
94+
"https://docs.djangoproject.com/en/stable/_objects/",
95+
),
96+
"django-typer": ("https://django-typer.readthedocs.io/en/stable", None),
97+
"enum-properties": ("https://enum-properties.readthedocs.io/en/stable", None),
98+
"django-enum": ("https://django-enum.readthedocs.io/en/stable", None),
99+
"jinja": ("https://jinja.palletsprojects.com/en/stable", None),
100+
"python": ('https://docs.python.org/3', None)
101+
}
102+
103+
def pypi_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
104+
from docutils import nodes
105+
url = f"https://pypi.org/project/{text}/"
106+
node = nodes.reference(rawtext, text, refuri=url, **options)
107+
return [node], []
108+
109+
def setup(app):
110+
# Register a sphinx.ext.autodoc.between listener to ignore everything
111+
# between lines that contain the word IGNORE
112+
from docutils.parsers.rst import roles
113+
app.add_crossref_type(directivename="django-admin", rolename="django-admin")
114+
roles.register_local_role('pypi', pypi_role)
115+
return app

doc/source/configuration.rst

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Configuration
55
=============
66

7-
`django-render-static` settings are set in the ``STATIC_TEMPLATES`` dictionary in your site
8-
settings:
7+
:pypi:`django-render-static` settings are set in the :setting:`STATIC_TEMPLATES` dictionary in your
8+
site settings:
99

1010
.. code-block:: python
1111
@@ -37,19 +37,20 @@ settings:
3737
]
3838
}
3939
40-
The ``STATIC_TEMPLATES`` setting closely mirrors the ``TEMPLATES`` setting by defining which
41-
template backends should be used. It extends the standard setting with a few options needed by the
42-
static engine including a global context available to all static templates and a set of template
43-
specific configuration parameters. It's advisable to first read about Django's ``TEMPLATES``
44-
setting. The main difference with ``STATIC_TEMPLATES`` is that it supports batch rendering.
40+
The :setting:`STATIC_TEMPLATES` setting closely mirrors the :setting:`TEMPLATES` setting by defining
41+
which template backends should be used. It extends the standard setting with a few options needed by
42+
the static engine including a global context available to all static templates and a set of template
43+
specific configuration parameters. It's advisable to first read about Django's :setting:`TEMPLATES`
44+
setting. The main difference with :setting:`STATIC_TEMPLATES` is that it supports batch rendering.
4545
Glob-like patterns can be used to select multiple templates for rendering. See :ref:`loaders` for
4646
more details.
4747

4848
Minimal Configuration
4949
---------------------
5050

51-
To run `renderstatic`, If ``STATIC_TEMPLATES`` is not defined in settings. Or, if it's an empty
52-
dictionary (or None) then the default engine and loaders will be used which is equivalent to:
51+
To run :django-admin:`renderstatic`, If :setting:`STATIC_TEMPLATES` is not defined in settings. Or,
52+
if it's an empty dictionary (or None) then the default engine and loaders will be used which is
53+
equivalent to:
5354

5455
.. code-block:: python
5556
@@ -69,17 +70,17 @@ dictionary (or None) then the default engine and loaders will be used which is e
6970
-----------
7071

7172
A prioritized list of backend template engines and their parameters. The engines at the front of the
72-
list have precedence over engines further down the list. The ``ENGINES`` parameters are
73-
inherited from the standard Django ``TEMPLATES`` configuration.
73+
list have precedence over engines further down the list. The ``ENGINES`` parameters are inherited
74+
from the standard Django :setting:`TEMPLATES` configuration.
7475

7576
``BACKEND``
7677
~~~~~~~~~~~
77-
The backend classes that render templates. The standard ``TEMPLATES`` engines should not be used
78-
here, instead use the two engines provided by `django-render-static`:
78+
The backend classes that render templates. The standard :setting:`TEMPLATES` engines should not be
79+
used here, instead use the two engines provided by :pypi:`django-render-static`:
7980

80-
- ``render_static.backends.StaticDjangoTemplates``
81-
- default app directory: ``static_templates``
82-
- ``render_static.backends.jinja2.StaticJinja2Templates``
81+
- :class:`render_static.backends.StaticDjangoTemplates`
82+
- default app directory: :setting:`STATIC_TEMPLATES`
83+
- :class:`render_static.backends.jinja2.StaticJinja2Templates`
8384
- default app directory: ``static_jinja2``
8485

8586
If ``APP_DIRS`` is true, or if an app directories loader is used such that templates are searched
@@ -93,55 +94,57 @@ parameter into ``OPTIONS``.
9394
A list of configuration parameters to pass to the backend during initialization. Most of these
9495
parameters are inherited from the standard Django template backends. One additional parameter
9596
``app_dir`` can be used to change the default search path for static templates within apps. The
96-
`options available to the StaticDjangoTemplates backend <https://docs.djangoproject.com/en/stable/topics/templates/#django.template.backends.django.DjangoTemplates>`_
97-
differ slightly from the `options available to the StaticJinja2Templates backend <https://docs.djangoproject.com/en/stable/topics/templates/#django.template.backends.jinja2.Jinja2>`_.
97+
:class:`options available to the StaticDjangoTemplates backend <django.template.backends.django.DjangoTemplates>`
98+
differ slightly from the :class:`options available to the StaticJinja2Templates backend <django.template.backends.jinja2.Jinja2>`.
9899

99100
.. _loaders:
100101

101102
``loader(s)``
102103
*************
103104

104-
Works the same way as the ``loaders`` parameter on ``TEMPLATES``. Except when using the standard
105-
template backend the loaders have been extended and static specific loaders should be used instead:
105+
Works the same way as the ``loaders`` parameter on :setting:`TEMPLATES`. Except when using the
106+
standard template backend the loaders have been extended and static specific loaders should be used
107+
instead:
106108

107-
- ``render_static.backends.StaticDjangoTemplates``
108-
- ``render_static.loaders.django.StaticAppDirectoriesBatchLoader`` **default**
109-
- ``render_static.loaders.django.StaticFilesystemBatchLoader``
110-
- ``render_static.loaders.django.StaticAppDirectoriesLoader``
111-
- ``render_static.loaders.django.StaticFilesystemLoader``
112-
- ``render_static.loaders.django.StaticLocMemLoader``
109+
- :class:`render_static.backends.StaticDjangoTemplates <render_static.backends.django.StaticDjangoTemplates>`
110+
- :class:`render_static.loaders.django.StaticAppDirectoriesBatchLoader` **default**
111+
- :class:`render_static.loaders.django.StaticFilesystemBatchLoader`
112+
- :class:`render_static.loaders.django.StaticAppDirectoriesLoader`
113+
- :class:`render_static.loaders.django.StaticFilesystemLoader`
114+
- :class:`render_static.loaders.django.StaticLocMemLoader`
113115

114-
- ``render_static.backends.jinja2.StaticJinja2Templates``
115-
- ``render_static.loaders.jinja2.StaticFileSystemBatchLoader`` **default**
116-
- ``render_static.loaders.jinja2.StaticFileSystemLoader``
117-
- ``render_static.loaders.jinja2.StaticPackageLoader``
118-
- ``render_static.loaders.jinja2.StaticPrefixLoader``
119-
- ``render_static.loaders.jinja2.StaticFunctionLoader``
120-
- ``render_static.loaders.jinja2.StaticDictLoader``
121-
- ``render_static.loaders.jinja2.StaticChoiceLoader``
122-
- ``render_static.loaders.jinja2.StaticModuleLoader``
116+
- :class:`render_static.backends.jinja2.StaticJinja2Templates`
117+
- :class:`render_static.loaders.jinja2.StaticFileSystemBatchLoader` **default**
118+
- :class:`render_static.loaders.jinja2.StaticFileSystemLoader`
119+
- :class:`render_static.loaders.jinja2.StaticPackageLoader`
120+
- :class:`render_static.loaders.jinja2.StaticPrefixLoader`
121+
- :class:`render_static.loaders.jinja2.StaticFunctionLoader`
122+
- :class:`render_static.loaders.jinja2.StaticDictLoader`
123+
- :class:`render_static.loaders.jinja2.StaticChoiceLoader`
124+
- :class:`render_static.loaders.jinja2.StaticModuleLoader`
123125

124126

125127
.. note::
126-
The ``StaticJinja2Templates engine`` is configurable with only one loader
127-
and the parameter is called ``loader``. The ``StaticDjangoTemplates``
128-
engine is configurable with more than one loader that are specified as a
129-
list under the ``loaders`` parameter.
128+
129+
The :class:`~render_static.backends.jinja2.StaticJinja2Templates` engine is configurable with
130+
only one loader and the parameter is called ``loader``. The
131+
:class:`~render_static.backends.django.StaticDjangoTemplates` engine is configurable with more
132+
than one loader that are specified as a list under the ``loaders`` parameter.
130133

131134

132135
The static template engine supports batch rendering. All loaders that have ``Batch`` in the name
133136
support wild cards and glob-like patterns when loading templates. By default, if no loaders are
134-
specified these loaders are used. For instance, if I wanted to render every .js file in a
135-
directory called static_templates/js I could configure templates like so:
137+
specified these loaders are used. For instance, if I wanted to render every .js file in a directory
138+
called static_templates/js I could configure templates like so:
136139

137140
.. code-block:: python
138141
139142
'templates': ['js/*.js']
140143
141144
``context``
142145
-----------
143-
Specify a dictionary containing the context to pass to any static templates as they render. This
144-
is the global context that will be applied to all templates. Specific templates can override
146+
Specify a dictionary containing the context to pass to any static templates as they render. This is
147+
the global context that will be applied to all templates. Specific templates can override
145148
individual context parameters, but not the whole dictionary. By default all contexts will have the
146149
Django settings in them, keyed by ``settings``.
147150

@@ -177,15 +180,18 @@ For example:
177180
}
178181
179182
180-
``templates``
181-
-------------
183+
``STATIC_TEMPLATES``
184+
--------------------
185+
186+
.. setting:: STATIC_TEMPLATES
182187

183-
The ``templates`` dictionary lists all templates that should be generated when `renderstatic` is
184-
run with no arguments. If specific configuration directives including rendered path and context are
185-
needed for a template they must be specified here. ``templates`` may also be a list containing
186-
template names or 2-tuples of template names and configurations. By specifying ``templates`` this
187-
way, a single template may be rendered multiple times using different contexts to different
188-
locations. For example, the following would render one template three times:
188+
The :setting:`STATIC_TEMPLATES` dictionary lists all templates that should be generated when
189+
:django-admin:`renderstatic` is run with no arguments. If specific configuration directives
190+
including rendered path and context are needed for a template they must be specified here.
191+
:setting:`STATIC_TEMPLATES` may also be a list containing template names or 2-tuples of template
192+
names and configurations. By specifying :setting:`STATIC_TEMPLATES` this way, a single template may
193+
be rendered multiple times using different contexts to different locations. For example, the
194+
following would render one template three times:
189195

190196
.. code-block:: python
191197
@@ -198,9 +204,9 @@ locations. For example, the following would render one template three times:
198204
199205
.. note::
200206

201-
`renderstatic` will be able to generate templates not listed in ``templates``, but only if
202-
supplied by name on the command line. Contexts may also be augmented/overridden via the command
203-
line.
207+
:django-admin:`renderstatic` will be able to generate templates not listed in
208+
:setting:`STATIC_TEMPLATES`, but only if supplied by name on the command line. Contexts may
209+
also be augmented/overridden via the command line.
204210

205211
``dest``
206212
~~~~~~~~
@@ -226,27 +232,30 @@ any of the same context specifiers that work for the global context.
226232
``RENDER_STATIC_REVERSAL_LIMIT``
227233
--------------------------------
228234

229-
The guess and check reversal mechanism used to ensure that `urls_to_js` produces the same reversals
230-
as Django's `reverse` is an **O(n^p)** operation where **n** is the number of placeholder candidates
231-
to try and **p** is the number of arguments in the url. Its possible for this to produce a
232-
complexity explosion for rare cases where the URL has a large number of arguments with unregistered
233-
placeholders. A limit on the number of tries is enforced to guard against this. User's may adjust
234-
the limit via the ``RENDER_STATIC_REVERSAL_LIMIT`` settings parameter. By default it is 2**14 tries
235-
which runs in ~seconds per URL.
235+
.. setting:: RENDER_STATIC_REVERSAL_LIMIT
236+
237+
The guess and check reversal mechanism used to ensure that :templatetag:`urls_to_js` produces the
238+
same reversals as Django's :func:`~django.urls.reverse` is an **O(n^p)** operation where **n** is
239+
the number of placeholder candidates to try and **p** is the number of arguments in the url. Its
240+
possible for this to produce a complexity explosion for rare cases where the URL has a large number
241+
of arguments with unregistered placeholders. A limit on the number of tries is enforced to guard
242+
against this. User's may adjust the limit via the :setting:`RENDER_STATIC_REVERSAL_LIMIT`` settings
243+
parameter. By default it is 2**14 tries which runs in ~seconds per URL.
236244

237245
The solution if this limit is hit, is to provide more specific placeholders as placeholders are
238-
attempted in order of specificity where specificity is defined by url name, variable name,
239-
app name and/or converter type.
246+
attempted in order of specificity where specificity is defined by url name, variable name, app name
247+
and/or converter type.
240248

241249

242-
``StaticJinja2Templates`` Example
243-
---------------------------------
250+
:class:`~render_static.backends.jinja2.StaticJinja2Templates` Example
251+
---------------------------------------------------------------------
244252

245-
Using the ``StaticJinja2Template`` engine requires a slightly different configuration. By
246-
default the ``render_static.loaders.jinja2.StaticFileSystemBatchLoader`` loader is used
247-
and its ``app_dir`` setting will expect to find templates in static_jinja2 sub directories.
248-
For example to render all urls except our admin urls to javascript using (:ref:`urls_to_js`)
249-
we might have the following app tree::
253+
Using the :class:`~render_static.backends.jinja2.StaticJinja2Templates` engine requires a slightly
254+
different configuration. By default the
255+
:class:`render_static.loaders.jinja2.StaticFileSystemBatchLoader` loader is used and its
256+
``app_dir`` setting will expect to find templates in static_jinja2 sub directories. For example to
257+
render all urls except our admin urls to javascript using :templatetag:`urls_to_js` we might have
258+
the following app tree::
250259

251260
.
252261
└── my_app
@@ -255,8 +264,8 @@ we might have the following app tree::
255264
├── defines.py
256265
├── models.py
257266
├── static_jinja2
258-
   └── my_app
259-
   └── urls.js
267+
└── my_app
268+
└── urls.js
260269
└── urls.py
261270

262271
Where our urls.js file might look like:

0 commit comments

Comments
 (0)