forked from django-webpack/django-webpack-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the following template tag ``` {% webpack_asset 'path/to/original/file' %} ``` Fixes django-webpack#343 Depends on django-webpack/webpack-bundle-tracker#125
- Loading branch information
1 parent
eb1ee36
commit 7d52a83
Showing
17 changed files
with
1,640 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
django_webpack_loader_bundles/ | ||
webpack-stats.json |
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,116 @@ | ||
""" | ||
Django settings for app project. | ||
Generated by 'django-admin startproject' using Django 1.8.2. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.8/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.8/ref/settings/ | ||
""" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '+g25&y9i+-6_z$$z!ov$l2s%b#0kcmnx)n7y*2_ehy-w011p#k' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'app', | ||
'webpack_loader', | ||
'django_jinja', | ||
) | ||
|
||
MIDDLEWARE = [ | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
'django.middleware.security.SecurityMiddleware', | ||
] | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'app.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.8/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.8/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
STATICFILES_DIRS = ( | ||
os.path.join(BASE_DIR, 'assets'), | ||
) | ||
|
||
WEBPACK_LOADER = { | ||
'DEFAULT': { | ||
'CACHE': False, | ||
'BUNDLE_DIR_NAME': 'django_webpack_loader_bundles/', | ||
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'), | ||
}, | ||
} | ||
|
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,12 @@ | ||
{% load webpack_asset from webpack_loader %} | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Example</title> | ||
</head> | ||
|
||
<body> | ||
<a href="{% webpack_asset 'assets/js/resource.txt' %}">Download resource</a> | ||
</body> | ||
</html> |
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,29 @@ | ||
import time | ||
from shutil import rmtree | ||
from subprocess import call | ||
|
||
from django.test.client import RequestFactory | ||
from django.test.testcases import TestCase | ||
from django.views.generic.base import TemplateView | ||
|
||
|
||
class LoaderTestCase(TestCase): | ||
def setUp(self): | ||
self.factory = RequestFactory() | ||
self.cleanup_bundles_folder() | ||
|
||
def cleanup_bundles_folder(self): | ||
rmtree('./assets/django_webpack_loader_bundles', ignore_errors=True) | ||
|
||
def compile_bundles(self, config, wait=None): | ||
if wait: | ||
time.sleep(wait) | ||
call(['./node_modules/.bin/webpack', '--config', config]) | ||
|
||
def test_templatetags(self): | ||
self.compile_bundles('webpack.config.js') | ||
view = TemplateView.as_view(template_name='home.html') | ||
request = self.factory.get('/') | ||
result = view(request) | ||
self.assertIn( | ||
'<a href="/static/assets/resource-3c9e4020d3e3c7a09c68.txt">Download resource</a>', result.rendered_content) |
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 @@ | ||
Hello world! |
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 @@ | ||
require("./resource.txt") |
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,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
Oops, something went wrong.