Environment API¶
The QuartAssets class is the main entry point for integrating webassets with your Quart application.
QuartAssets¶
quart_assets.QuartAssets
¶
Bases: BaseEnvironment
This object is used to hold a collection of bundles and configuration.
If initialized with a Quart app instance then a webassets Jinja2 extension is automatically registered.
Source code in src/quart_assets/extension.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
directory
property
writable
¶
The base directory to which all paths will be relative.
url
property
writable
¶
The base url to which all static urls will be relative.
from_module(path)
¶
Register bundles from a Python module.
Source code in src/quart_assets/extension.py
351 352 353 | |
from_yaml(path)
¶
Register bundles from a YAML configuration file.
Source code in src/quart_assets/extension.py
347 348 349 | |
Configuration Storage¶
The configuration storage classes handle how webassets configuration is stored and accessed within Quart applications.
QuartConfigStorage¶
quart_assets.extension.QuartConfigStorage
¶
Bases: ConfigStorage
Uses the config object of a Quart app as the backend: either the app instance bound to the extension directly, or the current Quart app on the stack. Also provides per-application defaults for some values.
Source code in src/quart_assets/extension.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
setdefault(key, value)
¶
We may not always be connected to an app, but we still need to provide a way to the base environment to set its defaults.
Source code in src/quart_assets/extension.py
119 120 121 122 123 124 125 126 | |
Resolvers¶
Resolvers handle how asset files are located and how URLs are generated for them.
QuartResolver¶
quart_assets.extension.QuartResolver
¶
Bases: Resolver
Adds support for Quart blueprints.
This resolver is designed to use the Quart staticfile system to
locate files, by looking at directory prefixes. (foo/bar.png
looks in the static folder of the foo blueprint. url_for
is used to generate urls to these files.)
This default behaviour changes when you start setting certain standard webassets path and url configuration values:
If a :attr:Environment.directory is set, output files will
always be written there, while source files still use the Quart
system.
If a :attr:Environment.load_path is set, it is used to look
up source files, replacing the Quart system. Blueprint prefixes
are no longer resolved.
Source code in src/quart_assets/extension.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
convert_item_to_quart_url(ctx, item, filepath=None)
¶
Build a Quart URL for an asset reference.
Resolves blueprint prefixes via :meth:split_prefix and asks the
app's URL map to construct the URL for the matching static endpoint.
Works both inside a request context (via :func:quart.url_for) and
outside one (e.g. during quart assets build), correctly honouring
blueprint static_url_path values and any custom URL routing.
If filepath is provided it overrides the relative path returned by
:meth:split_prefix; this is needed when item is a glob that was
resolved to multiple files.
Source code in src/quart_assets/extension.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
split_prefix(ctx, item)
¶
Split a blueprint-prefixed asset path.
Returns (directory, relative_path, endpoint). If item has a
blueprint_name/... prefix that matches a registered blueprint with
a static folder, the blueprint's static folder and endpoint are used.
Otherwise the app's static folder is used and item is returned
unchanged.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If the matched blueprint, or the app, has no static folder. |
Source code in src/quart_assets/extension.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
Jinja2 Integration¶
Custom filters and extensions for Jinja2 template integration.
Jinja2Filter¶
quart_assets.extension.Jinja2Filter
¶
Bases: Filter
Compiles all source files as Jinja2 templates using Quart contexts.
Source code in src/quart_assets/extension.py
89 90 91 92 93 94 95 96 97 98 99 100 | |
AsyncAssetsExtension¶
quart_assets.extension.AsyncAssetsExtension
¶
Bases: AssetsExtension
Async-aware webassets Jinja2 extension for Quart's async Jinja environment.
Source code in src/quart_assets/extension.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
Utility Functions¶
get_static_folder¶
quart_assets.extension.get_static_folder(app_or_blueprint)
¶
Return the static folder of the given Quart app instance, or module/blueprint.
Source code in src/quart_assets/extension.py
23 24 25 26 27 28 29 | |