This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add templatetag and staticfiles storage for Django
- Loading branch information
Rocky Meza
committed
May 11, 2015
1 parent
7130408
commit 9c1ec07
Showing
9 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ | |
|
||
webpack.conf.settings.configure( | ||
**getattr(settings, 'WEBPACK', {}) | ||
) | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import absolute_import | ||
|
||
import logging | ||
|
||
from django.template import Library | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.contrib.staticfiles.storage import staticfiles_storage | ||
|
||
from ..conf import settings | ||
from ..compiler import webpack, WebpackBundle | ||
from ..exceptions import BundlingError | ||
|
||
register = Library() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@register.simple_tag(name='webpack') | ||
def do_webpack(path_to_config): | ||
""" | ||
A template tag that will output a webpack bundle. To be used in combination | ||
with the OfflineWebpackStorageMixin. | ||
Usage: | ||
{% load webpack %} | ||
{% webpack 'path/to/webpack.config.js' %} | ||
""" | ||
if settings.COMPILE_OFFLINE: | ||
if not hasattr(staticfiles_storage, 'load_webpack_bundle_stats'): | ||
raise ImproperlyConfigured( | ||
"Your STATICFILES_STORAGE is not a subclass of" | ||
" OfflineWebpackStorageMixin. Please make sure to use it or" | ||
" implement the load_bundle_stats method on your class." | ||
) | ||
elif path_to_config not in settings.OFFLINE_BUNDLES: | ||
raise ImproperlyConfigured( | ||
"'{}' was not found in the webpack bundle stats manifest, did" | ||
" you include it in WEBPACK_OFFLINE_BUNDLES?".format(path_to_config) | ||
) | ||
stats = staticfiles_storage.load_webpack_bundle_stats() | ||
if stats is None: | ||
raise ImproperlyConfigured( | ||
"Could not find the webpack bundle stats manifest, did you" | ||
" run collectstatic?" | ||
) | ||
elif path_to_config not in stats: | ||
raise BundlingError( | ||
"Could not find the webpack bundle stats manifest, I'm not" | ||
" sure what the error was. Please run collectstatic again," | ||
" if the problem persists, report a bug." | ||
) | ||
# Re-instantiate from the cache. | ||
bundle = WebpackBundle(stats[path_to_config]) | ||
else: | ||
bundle = webpack(path_to_config) | ||
|
||
return bundle.render() |