-
Notifications
You must be signed in to change notification settings - Fork 342
Adding skip_common_chunks option to the get_files() template tag
#386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+234
−67
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fdc79ec
Adding `skip_common_chunks` option to the `get_files()` template tag
karolyi a75c9c1
Improve get_files support for skip_common_chunks, avoid changing publ...
fjsj 17c3543
Drop generated test stats file
fjsj 9b97987
Fix tests
fjsj f409a2a
Fix get_as_tags to return a list and fix get_files on Jinja2
fjsj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Adding
skip_common_chunks option to the get_files() template tag
- Loading branch information
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
webpack_loader/__init__.py
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| __author__ = "Vinta Software" | ||
| __version__ = "3.0.0" | ||
| __version__ = "3.0.1" | ||
|
|
||
| import django | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| 'You have specified skip_common_chunks=True but the passed context ' | ||
| 'doesn\'t have a request. django_webpack_loader needs a request object to ' | ||
| 'filter out duplicate chunks. Please see https://github.com/django-webpack' | ||
| '/django-webpack-loader#skipping-the-generation-of-multiple-common-chunks') | ||
| '/django-webpack-loader#use-skip_common_chunks-on-render_bundle') | ||
|
|
||
|
|
||
| @register.simple_tag(takes_context=True) | ||
|
|
@@ -26,33 +26,51 @@ def render_bundle( | |
| if request is None: | ||
| if skip_common_chunks: | ||
| warn(message=_WARNING_MESSAGE, category=RuntimeWarning) | ||
| return mark_safe('\n'.join(tags)) | ||
| used_tags = getattr(request, '_webpack_loader_used_tags', None) | ||
| if not used_tags: | ||
| used_tags = request._webpack_loader_used_tags = set() | ||
| return mark_safe('\n'.join(tags.values())) | ||
| used_urls = getattr(request, '_webpack_loader_used_urls', None) | ||
| if not used_urls: | ||
| used_urls = request._webpack_loader_used_urls = set() | ||
| if skip_common_chunks: | ||
| tags = [tag for tag in tags if tag not in used_tags] | ||
| used_tags.update(tags) | ||
| return mark_safe('\n'.join(tags)) | ||
| tags = {url: tag for url, tag in tags.items() if url not in used_urls} | ||
| used_urls.update(tags) | ||
| return mark_safe('\n'.join(tags.values())) | ||
|
|
||
|
|
||
| @register.simple_tag | ||
| def webpack_static(asset_name, config='DEFAULT'): | ||
| return utils.get_static(asset_name, config=config) | ||
|
|
||
|
|
||
| @register.simple_tag | ||
| def get_files(bundle_name, extension=None, config='DEFAULT'): | ||
| @register.simple_tag(takes_context=True) | ||
| def get_files( | ||
| context, bundle_name, extension=None, config='DEFAULT', | ||
| skip_common_chunks=None): | ||
| """ | ||
| Returns all chunks in the given bundle. | ||
| Example usage:: | ||
|
|
||
| {% get_files 'editor' 'css' as editor_css_chunks %} | ||
| CKEDITOR.config.contentsCss = '{{ editor_css_chunks.0.url }}'; | ||
|
|
||
| :param context: The request, if you want to use `skip_common_chunks` | ||
| :param bundle_name: The name of the bundle | ||
| :param extension: (optional) filter by extension | ||
| :param config: (optional) the name of the configuration | ||
| :param skip_common_chunks: (optional) `True` if you want to skip returning already rendered common chunks | ||
| :return: a list of matching chunks | ||
| """ | ||
| return utils.get_files(bundle_name, extension=extension, config=config) | ||
| if skip_common_chunks is None: | ||
| skip_common_chunks = utils.get_skip_common_chunks(config) | ||
| if not skip_common_chunks: | ||
| return utils.get_files(bundle_name, extension=extension, config=config) | ||
| request = context.get('request') | ||
| result = utils.get_files(bundle_name, extension=extension, config=config) | ||
| if not skip_common_chunks: | ||
| return result | ||
| if request is None: | ||
| warn(message=_WARNING_MESSAGE, category=RuntimeWarning) | ||
| return result | ||
| used_urls = getattr(request, '_webpack_loader_used_urls', None) | ||
| if not used_urls: | ||
| used_urls = request._webpack_loader_used_urls = set() | ||
| return [x for x in result if x['url'] not in used_urls] | ||
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.