@@ -17,9 +17,9 @@ settings:
1717 ' app_dir' : ' static_templates' , # search this directory in apps for templates
1818 ' loaders' : [
1919 # search apps for templates
20- ' render_static.loaders.StaticAppDirectoriesLoader ' ,
20+ ' render_static.loaders.StaticAppDirectoriesBatchLoader ' ,
2121 # search DIRS for templates
22- ' render_static.loaders.StaticFilesystemLoader '
22+ ' render_static.loaders.StaticFilesystemBatchLoader '
2323 ],
2424 ' builtins' : [' render_static.templatetags.render_static' ]
2525 },
@@ -41,12 +41,14 @@ The ``STATIC_TEMPLATES`` setting closely mirrors the ``TEMPLATES`` setting by de
4141template backends should be used. It extends the standard setting with a few options needed by the
4242static engine including a global context available to all static templates and a set of template
4343specific 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.
4547
4648Minimal Configuration
4749---------------------
4850
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
5052dictionary (or None):
5153
5254.. code-block :: python
@@ -59,14 +61,13 @@ then the default engine and loaders will be used which is equivalent to:
5961.. code-block :: python
6062
6163 STATIC_TEMPALTES = {
62- ' ENGINES' : [
64+ ' ENGINES' : [{
6365 ' BACKEND' : ' render_static.backends.StaticDjangoTemplates' ,
64- ' DIRS' : [],
6566 ' OPTIONS' : {
66- ' loaders' : [' render_static.loaders.StaticAppDirectoriesLoader ' ],
67+ ' loaders' : [' render_static.loaders.StaticAppDirectoriesBatchLoader ' ],
6768 ' builtins' : [' render_static.templatetags.render_static' ]
6869 },
69- ]
70+ } ]
7071 }
7172
7273
@@ -100,18 +101,42 @@ A list of configuration parameters to pass to the backend during initialization.
100101parameters are inherited from the standard Django template backends. One additional parameter
101102``app_dir `` can be used to change the default search path for static templates within apps.
102103
104+ .. _loaders :
105+
103106``loaders ``
104107***********
105108
106109Works the same way as the ``loaders `` parameter on ``TEMPLATES ``. Except when using the standard
107110template backend the loaders have been extended and static specific loaders should be used instead:
108111
109112- ``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:
113134
114- The normal Jinja2 loaders are used for the ``StaticJinja2Templates `` backend.
135+ .. code-block :: python
136+
137+ ' templates' : {
138+ ' js/*.js' : {}
139+ }
115140
116141 ``context ``
117142-----------
@@ -126,31 +151,58 @@ there is no request object to build context off of. Dynamic templates are also o
126151contextual data built from the database but static templates are only rendered at deployment time,
127152so stuffing dynamic database information in static template contexts is not advisable.
128153
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+
129178 ``templates ``
130179-------------
131180
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
133182run with no arguments. If specific configuration directives including rendered path and context are
134183needed for a template they must be specified here.
135184
136185.. note ::
137186
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.
140190
141191``dest ``
142192~~~~~~~~
143193
144194Override 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.
148199
149200``context ``
150201~~~~~~~~~~~
151202
152203Provide 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.
154206
155207
156208``RENDER_STATIC_REVERSAL_LIMIT ``
0 commit comments