From 2347d8a09fdb7cefea4913236b3bd74bc69a3583 Mon Sep 17 00:00:00 2001 From: Simone Gasbarroni Date: Thu, 17 Mar 2016 16:10:51 +0100 Subject: [PATCH] added webassets TypeScript filter --- README.rst | 13 +++++++++++++ dukpy/webassets/__init__.py | 1 + dukpy/webassets/typescriptfilter.py | 20 ++++++++++++++++++++ setup.py | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 dukpy/webassets/typescriptfilter.py diff --git a/README.rst b/README.rst index 58ff60b..6c2f2c8 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,19 @@ The TypeScript compiler can be used through the Currently the compiler has built-in options and doesn't accept additional ones, +The DukPY based TypeScript 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 +``typescript`` within WebAssets using: + +.. code:: python + + from webassets.filter import register_filter + from dukpy.webassets import TypeScript + + register_filter(TypeScript) + +Which makes the filter available with the ``typescript`` name. EcmaScript6 BabelJS Transpiler ------------------------------ diff --git a/dukpy/webassets/__init__.py b/dukpy/webassets/__init__.py index b286c51..459d47d 100644 --- a/dukpy/webassets/__init__.py +++ b/dukpy/webassets/__init__.py @@ -1 +1,2 @@ from .babelfilter import BabelJS +from .typescriptfilter import TypeScript diff --git a/dukpy/webassets/typescriptfilter.py b/dukpy/webassets/typescriptfilter.py new file mode 100644 index 0000000..f118d1e --- /dev/null +++ b/dukpy/webassets/typescriptfilter.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, print_function +from webassets.filter import Filter + +import dukpy + + +__all__ = ('TypeScript', ) + + +class TypeScript(Filter): + name = 'typescript' + max_debug_level = None + + def setup(self): + super(TypeScript, self).setup() + + def input(self, _in, out, **kw): + src = dukpy.typescript_compile(_in.read()) + out.write(src['code']) diff --git a/setup.py b/setup.py index 1e874e1..947f7a3 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( version='0.0.1', description='Simple JavaScript interpreter for Python', long_description=README, - keywords='javascript compiler babeljs coffeescript', + keywords='javascript compiler babeljs coffeescript typescript', author='Alessandro Molina', author_email='alessandro.molina@axant.it', url='https://github.com/amol-/dukpy',