Add WebAssets support

This commit is contained in:
Alessandro Molina 2015-11-06 15:59:59 +01:00
parent 28f49a7df9
commit 93c9e9cb07
3 changed files with 30 additions and 0 deletions

View File

@ -41,6 +41,16 @@ To compile ES6 code to ES5 for everyday usage you can use ``dukpy.babel_compile`
... ''')
'"use strict";\n\nvar _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };\n\nvar _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };\n\nvar Point = (function () {\n function Point(x, y) {\n _classCallCheck(this, Point);\n\n this.x = x;\n this.y = y;\n }\n\n _prototypeProperties(Point, null, {\n toString: {\n value: function toString() {\n return "(" + this.x + ", " + this.y + ")";\n },\n writable: true,\n configurable: true\n }\n });\n\n return Point;\n})();\n'
The DukPY based BabelJS compiler also provides a WebAssets ( http://webassets.readthedocs.org/en/latest/ ) filter to automatically compile ES6 code in your assets pipeline.
You register this filter as ``babeljs`` within WebAssets using::
from webassets.filter import register_filter
from dukpy.webassets.babelfilter import BabelJS
register_filter(BabelJS)
Which makes the filter available with the ``babeljs`` name.
**NOTE:** When using the BabelJS compiler for code that needs to run in the browser, make sure to add https://cdnjs.cloudflare.com/ajax/libs/babel-core/4.6.6/browser-polyfill.js dependency.
Using the JavaScript Interpreter

0
webassets/__init__.py Normal file
View File

20
webassets/babelfilter.py Normal file
View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
from webassets.filter import Filter
import dukpy
__all__ = ('BabelJS', )
class BabelJS(Filter):
name = 'babeljs'
max_debug_level = None
def setup(self):
super(BabelJS, self).setup()
def input(self, _in, out, **kw):
src = dukpy.babel_compile(_in.read())
out.write(src)