@@ -17,9 +17,9 @@ settings:
17
17
' app_dir' : ' static_templates' , # search this directory in apps for templates
18
18
' loaders' : [
19
19
# search apps for templates
20
- ' render_static.loaders.StaticAppDirectoriesLoader ' ,
20
+ ' render_static.loaders.StaticAppDirectoriesBatchLoader ' ,
21
21
# search DIRS for templates
22
- ' render_static.loaders.StaticFilesystemLoader '
22
+ ' render_static.loaders.StaticFilesystemBatchLoader '
23
23
],
24
24
' builtins' : [' render_static.templatetags.render_static' ]
25
25
},
@@ -41,12 +41,14 @@ The ``STATIC_TEMPLATES`` setting closely mirrors the ``TEMPLATES`` setting by de
41
41
template backends should be used. It extends the standard setting with a few options needed by the
42
42
static engine including a global context available to all static templates and a set of template
43
43
specific configuration parameters. It's advisable to first read about Django's ``TEMPLATES ``
44
- setting.
44
+ setting. The main difference with ``STATIC_TEMPLATES `` is that it supports batch rendering.
45
+ Glob-like patterns can be used to select multiple templates for rendering. See :ref: `loaders ` for
46
+ more details.
45
47
46
48
Minimal Configuration
47
49
---------------------
48
50
49
- To run render_static , ``STATIC_TEMPLATES `` must be defined in settings. If it's an empty
51
+ To run ` renderstatic ` , ``STATIC_TEMPLATES `` must be defined in settings. If it's an empty
50
52
dictionary (or None):
51
53
52
54
.. code-block :: python
@@ -59,14 +61,13 @@ then the default engine and loaders will be used which is equivalent to:
59
61
.. code-block :: python
60
62
61
63
STATIC_TEMPALTES = {
62
- ' ENGINES' : [
64
+ ' ENGINES' : [{
63
65
' BACKEND' : ' render_static.backends.StaticDjangoTemplates' ,
64
- ' DIRS' : [],
65
66
' OPTIONS' : {
66
- ' loaders' : [' render_static.loaders.StaticAppDirectoriesLoader ' ],
67
+ ' loaders' : [' render_static.loaders.StaticAppDirectoriesBatchLoader ' ],
67
68
' builtins' : [' render_static.templatetags.render_static' ]
68
69
},
69
- ]
70
+ } ]
70
71
}
71
72
72
73
@@ -100,18 +101,42 @@ A list of configuration parameters to pass to the backend during initialization.
100
101
parameters are inherited from the standard Django template backends. One additional parameter
101
102
``app_dir `` can be used to change the default search path for static templates within apps.
102
103
104
+ .. _loaders :
105
+
103
106
``loaders ``
104
107
***********
105
108
106
109
Works the same way as the ``loaders `` parameter on ``TEMPLATES ``. Except when using the standard
107
110
template backend the loaders have been extended and static specific loaders should be used instead:
108
111
109
112
- ``render_static.backends.StaticDjangoTemplates ``
110
- - ``render_static.loaders.StaticAppDirectoriesLoader ``
111
- - ``render_static.loaders.StaticFilesystemLoader ``
112
- - ``render_static.loaders.StaticLocMemLoader ``
113
+ - ``render_static.loaders.django.StaticAppDirectoriesBatchLoader `` **default **
114
+ - ``render_static.loaders.django.StaticFilesystemBatchLoader ``
115
+ - ``render_static.loaders.django.StaticAppDirectoriesLoader ``
116
+ - ``render_static.loaders.django.StaticFilesystemLoader ``
117
+ - ``render_static.loaders.django.StaticLocMemLoader ``
118
+
119
+ - ``render_static.backends.StaticJinja2Templates ``
120
+ - ``render_static.loaders.jinja2.StaticFileSystemBatchLoader `` **default **
121
+ - ``render_static.loaders.jinja2.StaticFileSystemLoader ``
122
+ - ``render_static.loaders.jinja2.StaticPackageLoader ``
123
+ - ``render_static.loaders.jinja2.StaticPrefixLoader ``
124
+ - ``render_static.loaders.jinja2.StaticFunctionLoader ``
125
+ - ``render_static.loaders.jinja2.StaticDictLoader ``
126
+ - ``render_static.loaders.jinja2.StaticChoiceLoader ``
127
+ - ``render_static.loaders.jinja2.StaticModuleLoader ``
128
+
129
+ .. note ::
130
+ The static template engine supports batch rendering. All loaders that have ``Batch `` in the name
131
+ support wild cards and glob-like patterns when loading templates. By default, if no loaders are
132
+ specified these loaders are used. For instance, if I wanted to render every .js file in a
133
+ directory called static_templates/js I could configure templates like so:
113
134
114
- The normal Jinja2 loaders are used for the ``StaticJinja2Templates `` backend.
135
+ .. code-block :: python
136
+
137
+ ' templates' : {
138
+ ' js/*.js' : {}
139
+ }
115
140
116
141
``context ``
117
142
-----------
@@ -126,31 +151,58 @@ there is no request object to build context off of. Dynamic templates are also o
126
151
contextual data built from the database but static templates are only rendered at deployment time,
127
152
so stuffing dynamic database information in static template contexts is not advisable.
128
153
154
+ Context configuration parameters may be any of the following:
155
+
156
+ - **dictionary **: Simply specify context dictionary inline
157
+ - **callable **: That returns a dictionary. This allows lazy context initialization to take
158
+ place after Django bootstrapping
159
+ - **json **: A path to a JSON file
160
+ - **yaml **: A path to a YAML file (yaml supports comments!)
161
+ - **pickle **: A path to a python pickled dictionary
162
+ - **python **: A path to a python file. The locals defined in the file will
163
+ comprise the context.
164
+ - **a packaged resource **: Any of the above files imported as a packaged resource via
165
+ :ref: `resource ` to any of the above files.
166
+ - **import string **: to any of the above.
167
+
168
+ For example:
169
+
170
+ .. code-block :: python
171
+
172
+ from render_static import resource
173
+ STATIC_TEMPLATES = {
174
+ ' context' : resource(' package.module' , ' context.yaml' )
175
+ }
176
+
177
+
129
178
``templates ``
130
179
-------------
131
180
132
- The ``templates `` dictionary lists all templates that should be generated when `render_static ` is
181
+ The ``templates `` dictionary lists all templates that should be generated when `renderstatic ` is
133
182
run with no arguments. If specific configuration directives including rendered path and context are
134
183
needed for a template they must be specified here.
135
184
136
185
.. note ::
137
186
138
- `render_static ` will be able to generate templates not listed in ``templates ``, but only if
139
- supplied by name on the command line. Only the default context will be available to them.
187
+ `renderstatic ` will be able to generate templates not listed in ``templates ``, but only if
188
+ supplied by name on the command line. Contexts may also be augmented/overridden via the command
189
+ line.
140
190
141
191
``dest ``
142
192
~~~~~~~~
143
193
144
194
Override the default destination where a template will be rendered. Templates loaded from ``DIRS ``
145
- instead of apps do not have a default destination and must be provided one here. The ``dest ``
146
- parameter must contain the full path where the template will be rendered including the file name.
147
-
195
+ instead of apps do not have a default destination and must be provided one here. When rendering a
196
+ single template, if the ``dest `` parameter is not an existing directory, it will be assumed to be
197
+ the full path including the file name where the template will be rendered. When rendering in batch
198
+ mode, ``dest `` will be treated as a directory and created if it does not exist.
148
199
149
200
``context ``
150
201
~~~~~~~~~~~
151
202
152
203
Provide additional parameters for each template in the ``context `` dictionary. Any context variables
153
- specified here that clash with global context variables will override them.
204
+ specified here that clash with global context variables will override them. May be specified using
205
+ any of the same context specifiers that work for the global context.
154
206
155
207
156
208
``RENDER_STATIC_REVERSAL_LIMIT ``
0 commit comments