CoffeeScript middleware for TurboGears2
Project description
About tgext.coffeescript
------------------------------
`CoffeeScript <http://coffeescript.org/>`_ is a little language that compiles to JavaScript. Underneath all those
awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart.
`CoffeeScript <http://coffeescript.org/>`_ is an attempt to expose the good parts of JavaScript in a simple way.
`tgext.coffeescript <https://bitbucket.org/_amol_/tgext.coffeescript>`_ is a middleware aimed at making
`TurboGears2 <http://www.turbogears.org>`_ development easier, tgext.coffeescript converts regular coffee
files to javascript using the official CoffeeScript compiler.
tgext.coffeescript is based on `tgext.scss <https://bitbucket.org/_amol_/tgext.scss>`_ by Alessandro Molina and is
under the same license (MIT).
Installing
-------------------------------
tgext.coffeescript can be installed both from pypi or from bitbucket::
easy_install tgext.coffeescript
You will also need to install the CoffeeScript compiler, for instructions on this check their website.
`CoffeeScript <http://coffeescript.org/>`_
Enabling tgext.coffeescript
----------------------------------
Using tgext.coffeescript is really simple, you edit your `config/middeware.py` and just after
the `#Wrap your base TurboGears 2 application with custom middleware here` comment wrap
`app` with `CoffeeScriptMiddleware`::
from tgext.coffeescript import CoffeeScriptMiddleware
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
def make_app(global_conf, full_stack=True, **app_conf):
app = make_base_app(global_conf, full_stack=True, **app_conf)
# Wrap your base TurboGears 2 application with custom middleware here
app = CoffeeScriptMiddleware(app)
return app
Now you just have to put your .coffee files inside *public/javascript* and they will be served as JavaScript.
JavaScript Compression
----------------------------------
tgext.coffeescript supports javascript output minification via slimit or jsmin as a fallback, this function is
disabled by default and can be enabled by passing the parameter minify=True on the constructor:
app = CoffeeScriptMiddleware(app, minify=True)
Cache Backends
----------------------------------
You can change the cache backend storage into any dict like object that can serialize a dict object,
for example, you can use beaker cache by passing the cache object to the middleware constructor:
from tgext.coffeescript import CoffeeScriptMiddleware
from tg import cache
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
def make_app(global_conf, full_stack=True, **app_conf):
app = make_base_app(global_conf, full_stack=True, **app_conf)
# CoffeeScript with beaker cache backend
app = CoffeeScriptMiddleware(app, cache=cache)
return app
Compiler options
----------------------------------
Currently tgext.coffeescript turns the --bare compiler option by default, this means that the resulting javascript
output will not be wrapper under a top-level function, if you want to reverse this behaviour you can tell the
middleware to disable it::
app = CoffeeScriptMiddleware(app, bare=False)
This will disable the bare options for all files served with tgext.coffeescript, more granular control of this option
may be available later depending on the need for it.
------------------------------
`CoffeeScript <http://coffeescript.org/>`_ is a little language that compiles to JavaScript. Underneath all those
awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart.
`CoffeeScript <http://coffeescript.org/>`_ is an attempt to expose the good parts of JavaScript in a simple way.
`tgext.coffeescript <https://bitbucket.org/_amol_/tgext.coffeescript>`_ is a middleware aimed at making
`TurboGears2 <http://www.turbogears.org>`_ development easier, tgext.coffeescript converts regular coffee
files to javascript using the official CoffeeScript compiler.
tgext.coffeescript is based on `tgext.scss <https://bitbucket.org/_amol_/tgext.scss>`_ by Alessandro Molina and is
under the same license (MIT).
Installing
-------------------------------
tgext.coffeescript can be installed both from pypi or from bitbucket::
easy_install tgext.coffeescript
You will also need to install the CoffeeScript compiler, for instructions on this check their website.
`CoffeeScript <http://coffeescript.org/>`_
Enabling tgext.coffeescript
----------------------------------
Using tgext.coffeescript is really simple, you edit your `config/middeware.py` and just after
the `#Wrap your base TurboGears 2 application with custom middleware here` comment wrap
`app` with `CoffeeScriptMiddleware`::
from tgext.coffeescript import CoffeeScriptMiddleware
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
def make_app(global_conf, full_stack=True, **app_conf):
app = make_base_app(global_conf, full_stack=True, **app_conf)
# Wrap your base TurboGears 2 application with custom middleware here
app = CoffeeScriptMiddleware(app)
return app
Now you just have to put your .coffee files inside *public/javascript* and they will be served as JavaScript.
JavaScript Compression
----------------------------------
tgext.coffeescript supports javascript output minification via slimit or jsmin as a fallback, this function is
disabled by default and can be enabled by passing the parameter minify=True on the constructor:
app = CoffeeScriptMiddleware(app, minify=True)
Cache Backends
----------------------------------
You can change the cache backend storage into any dict like object that can serialize a dict object,
for example, you can use beaker cache by passing the cache object to the middleware constructor:
from tgext.coffeescript import CoffeeScriptMiddleware
from tg import cache
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
def make_app(global_conf, full_stack=True, **app_conf):
app = make_base_app(global_conf, full_stack=True, **app_conf)
# CoffeeScript with beaker cache backend
app = CoffeeScriptMiddleware(app, cache=cache)
return app
Compiler options
----------------------------------
Currently tgext.coffeescript turns the --bare compiler option by default, this means that the resulting javascript
output will not be wrapper under a top-level function, if you want to reverse this behaviour you can tell the
middleware to disable it::
app = CoffeeScriptMiddleware(app, bare=False)
This will disable the bare options for all files served with tgext.coffeescript, more granular control of this option
may be available later depending on the need for it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for tgext.coffeescript-0.2dev.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad438475e1cb33e9e48f1b769ccdad29fbbb1db0cb6f2a7cea78b24be81c3781 |
|
MD5 | e30259f4601ed2b5b3f981f530bd2328 |
|
BLAKE2b-256 | bf3d84c805087e9181fe8ed8b526993b32aca8cd472784e6e873cf893937e551 |