Skip to content

Commit

Permalink
Merge 1aa8c88 into bc85558
Browse files Browse the repository at this point in the history
  • Loading branch information
levic committed Feb 3, 2016
2 parents bc85558 + 1aa8c88 commit e71e14c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 5 additions & 5 deletions webpack_loader/templatetags/webpack_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def filter_by_extension(bundle, extension):
yield chunk


def render_as_tags(bundle):
def render_as_tags(bundle, config_name):
config = get_config(config_name)
tags = []
for chunk in bundle:
url = chunk.get('publicPath') or chunk['url']
if chunk['name'].endswith('.js'):
tags.append('<script type="text/javascript" src="{}"></script>'.format(url))
tags.append('<script type="text/javascript" src="{}"></script>'.format(config['get_chunk_url'](chunk, config)))
elif chunk['name'].endswith('.css'):
tags.append('<link type="text/css" href="{}" rel="stylesheet"/>'.format(url))
tags.append('<link type="text/css" href="{}" rel="stylesheet"/>'.format(config['get_chunk_url'](chunk, config)))
return mark_safe('\n'.join(tags))


Expand All @@ -34,7 +34,7 @@ def _get_bundle(bundle_name, extension, config):

@register.simple_tag
def render_bundle(bundle_name, extension=None, config='DEFAULT'):
return render_as_tags(_get_bundle(bundle_name, extension, config))
return render_as_tags(_get_bundle(bundle_name, extension, config), config)


@register.simple_tag
Expand Down
14 changes: 12 additions & 2 deletions webpack_loader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils.module_loading import import_string


__all__ = ('get_assets', 'get_config', 'get_bundle',)
Expand All @@ -15,7 +16,8 @@
'STATS_FILE': 'webpack-stats.json',
# FIXME: Explore usage of fsnotify
'POLL_INTERVAL': 0.1,
'IGNORE': ['.+\.hot-update.js', '.+\.map']
'IGNORE': ['.+\.hot-update.js', '.+\.map'],
'GET_CHUNK_URL': 'webpack_loader.utils.default_chunk_url',
}
}

Expand All @@ -40,7 +42,10 @@ class WebpackLoaderBadStatsError(Exception):


def get_config(config_name):
return user_config[config_name]
config = user_config[config_name]
if 'get_chunk_url' not in config:
config['get_chunk_url'] = config['GET_CHUNK_URL'] if callable(config['GET_CHUNK_URL']) else import_string(config['GET_CHUNK_URL'])
return config


def get_assets(config):
Expand Down Expand Up @@ -90,3 +95,8 @@ def get_bundle(bundle_name, config):
"The stats file does not contain valid data. Make sure "
"webpack-bundle-tracker plugin is enabled and try to run "
"webpack again.")


def default_chunk_url(chunk, config):
url = chunk.get('publicPath') or chunk['url']
return url

0 comments on commit e71e14c

Please sign in to comment.