Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Appending extensions in the url files #135

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
joaopslins merged 10 commits into django-webpack:master from joshjo:master
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move extension to template tag
  • Loading branch information
joshjo committed Dec 13, 2017
commit 03066aa85fdad1b1041a77a793079d8cd65ec5d8
7 changes: 1 addition & 6 deletions webpack_loader/config.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
# FIXME: Explore usage of fsnotify
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
'IGNORE': ['.+\.hot-update.js', '.+\.map'],
'APPEND_URL': {
'ENABLE': not settings.DEBUG,
'CSS': '.gz',
'JS': '.gz'
}
'IGNORE': ['.+\.hot-update.js', '.+\.map']
}
}

Expand Down
8 changes: 0 additions & 8 deletions webpack_loader/loader.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,9 @@ def get_chunk_url(self, chunk):
public_path = chunk.get('publicPath')
if public_path:
return public_path

relpath = '{0}{1}'.format(
self.config['BUNDLE_DIR_NAME'], chunk['name']
)

if self.config['APPEND_URL']['ENABLE']:
if relpath.endswith('.css'):
relpath += self.config['APPEND_URL']['CSS']
if relpath.endswith('.js'):
relpath += self.config['APPEND_URL']['JS']

return staticfiles_storage.url(relpath)

def get_bundle(self, bundle_name):
Expand Down
8 changes: 6 additions & 2 deletions webpack_loader/templatetags/webpack_loader.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@


@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', suffix='', attrs=''):
tags = utils.get_as_tags(
bundle_name, extension=extension, config=config,
suffix=suffix, attrs=attrs
)
return mark_safe('\n'.join(tags))


Expand Down
7 changes: 4 additions & 3 deletions webpack_loader/utils.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ 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', suffix='', attrs=''):
'''
Get a list of formatted <script> & <link> tags for the assets in the
named bundle.
Expand All @@ -48,11 +49,11 @@ def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
if chunk['name'].endswith(('.js', '.js.gz')):
tags.append((
'<script type="text/javascript" src="{0}" {1}></script>'
).format(chunk['url'], attrs))
).format(''.join([chunk['url'], suffix]), attrs))
elif chunk['name'].endswith(('.css', '.css.gz')):
tags.append((
'<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
).format(chunk['url'], attrs))
).format(''.join([chunk['url'], suffix]), attrs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not href="{0}{1}" {2}".format(url, suffix, attrs)?

KyeRussell reacted with thumbs up emoji
return tags


Expand Down

AltStyle によって変換されたページ (->オリジナル) /