[Python-modules-commits] [django-webpack-loader] 01/05: Import django-webpack-loader_0.5.0.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Tue Jun 20 18:42:58 UTC 2017
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch master
in repository django-webpack-loader.
commit f299da9539e71de04e051f0099086f19156c71d2
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Tue Jun 20 20:36:46 2017 +0200
Import django-webpack-loader_0.5.0.orig.tar.gz
---
PKG-INFO | 28 +++++++++---
README.md | 18 +++++++-
README.rst | 24 +++++++++--
django_webpack_loader.egg-info/PKG-INFO | 28 +++++++++---
setup.cfg | 1 -
setup.py | 5 ++-
webpack_loader/__init__.py | 2 +-
webpack_loader/loader.py | 2 +
webpack_loader/templatetags/webpack_loader.py | 47 ++++----------------
webpack_loader/utils.py | 62 +++++++++++++++++++++++++++
10 files changed, 161 insertions(+), 56 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 52ac730..375114a 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,12 +1,12 @@
Metadata-Version: 1.1
Name: django-webpack-loader
-Version: 0.4.1
+Version: 0.5.0
Summary: Transparently use webpack with django
Home-page: https://github.com/owais/django-webpack-loader
Author: Owais Lone
Author-email: hello at owaislone.org
License: UNKNOWN
-Download-URL: https://github.com/owais/django-webpack-loader/tarball/0.4.1
+Download-URL: https://github.com/owais/django-webpack-loader/tarball/0.5.0
Description: django-webpack-loader
=====================
@@ -61,9 +61,11 @@ Description: django-webpack-loader
pip install django-webpack-loader
- ## Configuration
+ Configuration
+ -------------
- ### Assumptions
+ Assumptions
+ ~~~~~~~~~~~
Assuming ``BASE_DIR`` in settings refers to the root of your django app.
@@ -87,7 +89,7 @@ Description: django-webpack-loader
.. code:: javascript
- var path = require("path");
+ var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
@@ -348,6 +350,22 @@ Description: django-webpack-loader
<!-- render full public path of logo.png -->
<img src="{% webpack_static 'logo.png' %}"/>
+ From Python code
+ ~~~~~~~~~~~~~~~~
+
+ If you want to access the webpack asset path information from your
+ application code then you can use the function in the
+ ``webpack_loader.utils`` module.
+
+ .. code:: python
+
+ >>> utils.get_files('main')
+ [{'url': '/static/bundles/main.js', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/main.js', u'name': u'main.js'},
+ {'url': '/static/bundles/styles.css', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/styles.css', u'name': u'styles.css'}]
+ >>> utils.get_as_tags('main')
+ ['<script type="text/javascript" src="/static/bundles/main.js" ></script>',
+ '<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet" />']
+
How to use in Production
------------------------
diff --git a/README.md b/README.md
index 5d8bb7d..26f6133 100644
--- a/README.md
+++ b/README.md
@@ -37,9 +37,11 @@ pip install django-webpack-loader
```
<br>
+
## Configuration
<br>
+
### Assumptions
Assuming `BASE_DIR` in settings refers to the root of your django app.
@@ -64,7 +66,7 @@ STATICFILES_DIRS = (
Assuming your webpack config lives at `./webpack.config.js` and looks like this
```javascript
-var path = require("path");
+var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
@@ -295,6 +297,20 @@ In the below example, `logo.png` can be any static asset shipped with any npm or
<br>
+### From Python code
+
+If you want to access the webpack asset path information from your application code then you can use
+the function in the `webpack_loader.utils` module.
+
+```python
+>>> utils.get_files('main')
+[{'url': '/static/bundles/main.js', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/main.js', u'name': u'main.js'},
+ {'url': '/static/bundles/styles.css', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/styles.css', u'name': u'styles.css'}]
+>>> utils.get_as_tags('main')
+['<script type="text/javascript" src="/static/bundles/main.js" ></script>',
+ '<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet" />']
+```
+
## How to use in Production
**It is up to you**. There are a few ways to handle this. I like to have slightly separate configs for production and local. I tell git to ignore my local stats + bundle file but track the ones for production. Before pushing out newer version to production, I generate a new bundle using production config and commit the new stats file and bundle. I store the stats file and bundles in a directory that is added to the `STATICFILES_DIR`. This gives me integration with collectstatic for free. [...]
diff --git a/README.rst b/README.rst
index 153f5ae..38b99a9 100644
--- a/README.rst
+++ b/README.rst
@@ -52,9 +52,11 @@ Install
pip install django-webpack-loader
- ## Configuration
+Configuration
+-------------
- ### Assumptions
+Assumptions
+~~~~~~~~~~~
Assuming ``BASE_DIR`` in settings refers to the root of your django app.
@@ -78,7 +80,7 @@ like this
.. code:: javascript
- var path = require("path");
+ var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
@@ -339,6 +341,22 @@ package.
<!-- render full public path of logo.png -->
<img src="{% webpack_static 'logo.png' %}"/>
+From Python code
+~~~~~~~~~~~~~~~~
+
+If you want to access the webpack asset path information from your
+application code then you can use the function in the
+``webpack_loader.utils`` module.
+
+.. code:: python
+
+ >>> utils.get_files('main')
+ [{'url': '/static/bundles/main.js', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/main.js', u'name': u'main.js'},
+ {'url': '/static/bundles/styles.css', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/styles.css', u'name': u'styles.css'}]
+ >>> utils.get_as_tags('main')
+ ['<script type="text/javascript" src="/static/bundles/main.js" ></script>',
+ '<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet" />']
+
How to use in Production
------------------------
diff --git a/django_webpack_loader.egg-info/PKG-INFO b/django_webpack_loader.egg-info/PKG-INFO
index 52ac730..375114a 100644
--- a/django_webpack_loader.egg-info/PKG-INFO
+++ b/django_webpack_loader.egg-info/PKG-INFO
@@ -1,12 +1,12 @@
Metadata-Version: 1.1
Name: django-webpack-loader
-Version: 0.4.1
+Version: 0.5.0
Summary: Transparently use webpack with django
Home-page: https://github.com/owais/django-webpack-loader
Author: Owais Lone
Author-email: hello at owaislone.org
License: UNKNOWN
-Download-URL: https://github.com/owais/django-webpack-loader/tarball/0.4.1
+Download-URL: https://github.com/owais/django-webpack-loader/tarball/0.5.0
Description: django-webpack-loader
=====================
@@ -61,9 +61,11 @@ Description: django-webpack-loader
pip install django-webpack-loader
- ## Configuration
+ Configuration
+ -------------
- ### Assumptions
+ Assumptions
+ ~~~~~~~~~~~
Assuming ``BASE_DIR`` in settings refers to the root of your django app.
@@ -87,7 +89,7 @@ Description: django-webpack-loader
.. code:: javascript
- var path = require("path");
+ var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
@@ -348,6 +350,22 @@ Description: django-webpack-loader
<!-- render full public path of logo.png -->
<img src="{% webpack_static 'logo.png' %}"/>
+ From Python code
+ ~~~~~~~~~~~~~~~~
+
+ If you want to access the webpack asset path information from your
+ application code then you can use the function in the
+ ``webpack_loader.utils`` module.
+
+ .. code:: python
+
+ >>> utils.get_files('main')
+ [{'url': '/static/bundles/main.js', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/main.js', u'name': u'main.js'},
+ {'url': '/static/bundles/styles.css', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/styles.css', u'name': u'styles.css'}]
+ >>> utils.get_as_tags('main')
+ ['<script type="text/javascript" src="/static/bundles/main.js" ></script>',
+ '<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet" />']
+
How to use in Production
------------------------
diff --git a/setup.cfg b/setup.cfg
index 368d041..26fc631 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -4,5 +4,4 @@ description-file = README.rst
[egg_info]
tag_build =
tag_date = 0
-tag_svn_revision = 0
diff --git a/setup.py b/setup.py
index 7b70d30..c92f50e 100644
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,10 @@ def rel(*parts):
'''returns the relative path to a file wrt to the current directory'''
return os.path.abspath(os.path.join(os.path.dirname(__file__), *parts))
-README = open('README.rst', 'r').read()
+if os.path.isfile('README.rst'):
+ README = open('README.rst', 'r').read()
+else:
+ README = open('README.md', 'r').read()
with open(rel('webpack_loader', '__init__.py')) as handler:
INIT_PY = handler.read()
diff --git a/webpack_loader/__init__.py b/webpack_loader/__init__.py
index e3a64fc..1d8ed84 100644
--- a/webpack_loader/__init__.py
+++ b/webpack_loader/__init__.py
@@ -1,4 +1,4 @@
__author__ = 'Owais Lone'
-__version__ = '0.4.1'
+__version__ = '0.5.0'
default_app_config = 'webpack_loader.apps.WebpackLoaderConfig'
diff --git a/webpack_loader/loader.py b/webpack_loader/loader.py
index faf5fb4..6b72564 100644
--- a/webpack_loader/loader.py
+++ b/webpack_loader/loader.py
@@ -87,6 +87,8 @@ class WebpackLoader(object):
assets['file'] = ''
if 'error' not in assets:
assets['error'] = 'Unknown Error'
+ if 'message' not in assets:
+ assets['message'] = ''
error = u"""
{error} in {file}
{message}
diff --git a/webpack_loader/templatetags/webpack_loader.py b/webpack_loader/templatetags/webpack_loader.py
index 4b45343..d1e87ce 100644
--- a/webpack_loader/templatetags/webpack_loader.py
+++ b/webpack_loader/templatetags/webpack_loader.py
@@ -1,56 +1,25 @@
-from django import template
+from django import template, VERSION
from django.conf import settings
from django.utils.safestring import mark_safe
-from ..utils import get_loader
+from .. import utils
register = template.Library()
-def filter_by_extension(bundle, extension):
- '''Return only files with the given extension'''
- for chunk in bundle:
- if chunk['name'].endswith('.{0}'.format(extension)):
- yield chunk
-
-
-def render_as_tags(bundle, attrs):
- tags = []
- for chunk in bundle:
- if chunk['name'].endswith(('.js', '.js.gz')):
- tags.append((
- '<script type="text/javascript" src="{0}" {1}></script>'
- ).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))
- return mark_safe('\n'.join(tags))
-
-
-def _get_bundle(bundle_name, extension, config):
- bundle = get_loader(config).get_bundle(bundle_name)
- if extension:
- bundle = filter_by_extension(bundle, extension)
- return bundle
-
-
@register.simple_tag
def render_bundle(bundle_name, extension=None, config='DEFAULT', attrs=''):
- return render_as_tags(_get_bundle(bundle_name, extension, config), attrs)
+ tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs)
+ return mark_safe('\n'.join(tags))
@register.simple_tag
def webpack_static(asset_name, config='DEFAULT'):
- return "{0}{1}".format(
- get_loader(config).get_assets().get(
- 'publicPath', getattr(settings, 'STATIC_URL')
- ),
- asset_name
- )
+ return utils.get_static(asset_name, config=config)
- at register.assignment_tag
+assignment_tag = register.simple_tag if VERSION >= (1, 9) else register.assignment_tag
+ at assignment_tag
def get_files(bundle_name, extension=None, config='DEFAULT'):
"""
Returns all chunks in the given bundle.
@@ -64,4 +33,4 @@ def get_files(bundle_name, extension=None, config='DEFAULT'):
:param config: (optional) the name of the configuration
:return: a list of matching chunks
"""
- return list(_get_bundle(bundle_name, extension, config))
+ return utils.get_files(bundle_name, extension=extension, config=config)
diff --git a/webpack_loader/utils.py b/webpack_loader/utils.py
index 012a056..e7b7b2f 100644
--- a/webpack_loader/utils.py
+++ b/webpack_loader/utils.py
@@ -1,3 +1,5 @@
+from django.conf import settings
+
from .loader import WebpackLoader
@@ -8,3 +10,63 @@ def get_loader(config_name):
if config_name not in _loaders:
_loaders[config_name] = WebpackLoader(config_name)
return _loaders[config_name]
+
+
+def _filter_by_extension(bundle, extension):
+ '''Return only files with the given extension'''
+ for chunk in bundle:
+ if chunk['name'].endswith('.{0}'.format(extension)):
+ yield chunk
+
+
+def _get_bundle(bundle_name, extension, config):
+ bundle = get_loader(config).get_bundle(bundle_name)
+ if extension:
+ bundle = _filter_by_extension(bundle, extension)
+ return bundle
+
+
+def get_files(bundle_name, extension=None, config='DEFAULT'):
+ '''Returns list of chunks from named bundle'''
+ return list(_get_bundle(bundle_name, extension, config))
+
+
+def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
+ '''
+ Get a list of formatted <script> & <link> tags for the assets in the
+ named bundle.
+
+ :param bundle_name: The name of the bundle
+ :param extension: (optional) filter by extension, eg. 'js' or 'css'
+ :param config: (optional) the name of the configuration
+ :return: a list of formatted tags as strings
+ '''
+
+ bundle = _get_bundle(bundle_name, extension, config)
+ tags = []
+ for chunk in bundle:
+ if chunk['name'].endswith(('.js', '.js.gz')):
+ tags.append((
+ '<script type="text/javascript" src="{0}" {1}></script>'
+ ).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))
+ return tags
+
+
+def get_static(asset_name, config='DEFAULT'):
+ '''
+ Equivalent to Django's 'static' look up but for webpack assets.
+
+ :param asset_name: the name of the asset
+ :param config: (optional) the name of the configuration
+ :return: path to webpack asset as a string
+ '''
+ return "{0}{1}".format(
+ get_loader(config).get_assets().get(
+ 'publicPath', getattr(settings, 'STATIC_URL')
+ ),
+ asset_name
+ )
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-webpack-loader.git
More information about the Python-modules-commits
mailing list