Skip to content

Commit

Permalink
Merge 1927dab into f0b9550
Browse files Browse the repository at this point in the history
  • Loading branch information
pglotov committed Jan 8, 2020
2 parents f0b9550 + 1927dab commit b4a0121
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions webpack_loader/templatetags/webpack_loader.py
Expand Up @@ -8,8 +8,8 @@


@register.simple_tag
def render_bundle(bundle_name, extension=None, config='DEFAULT', attrs=''):
tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs)
def render_bundle(bundle_name, extension=None, config='DEFAULT', attrs='', is_preload=False):
tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs, is_preload=is_preload)
return mark_safe('\n'.join(tags))


Expand All @@ -19,6 +19,8 @@ def webpack_static(asset_name, config='DEFAULT'):


assignment_tag = register.simple_tag if VERSION >= (1, 9) else register.assignment_tag


@assignment_tag
def get_files(bundle_name, extension=None, config='DEFAULT'):
"""
Expand Down
7 changes: 3 additions & 4 deletions webpack_loader/utils.py
Expand Up @@ -2,7 +2,6 @@

from .loader import WebpackLoader


_loaders = {}


Expand Down Expand Up @@ -31,7 +30,7 @@ def get_files(bundle_name, extension=None, config='DEFAULT'):
return list(_get_bundle(bundle_name, extension, config))


def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs='', is_preload=False):
'''
Get a list of formatted <script> & <link> tags for the assets in the
named bundle.
Expand All @@ -51,8 +50,8 @@ def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
).format(chunk['url'], attrs))
elif chunk['name'].endswith(('.css', '.css.gz')):
tags.append((
'<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
).format(chunk['url'], attrs))
'<link type="text/css" href="{0}" rel={2} {1}/>'
).format(chunk['url'], attrs, '"stylesheet"' if not is_preload else '"preload" as="style"'))
return tags


Expand Down

0 comments on commit b4a0121

Please sign in to comment.