Tuesday, 21 June 2011

Flask-Coffee - Fill your flask with coffee

Flask-Coffee is a Flask extension that compiles .coffee CoffeeScript files into .js JavaScript files for you if they have changed before your app renders.

This is a nice idea in development and not so nice an idea in production, so please keep that in mind.

Prerequisites

You will need to have to have Node.js installed with NPM and coffee-script.

You can follow the instructions in my previous article to install Node.js and then it's just

npm -g install coffee-script

Installation

Install Flask-Coffee with pip:

pip install flask-coffee

Usage

from flaskext.coffee import coffee

coffee(app) 

This will watch your app’s static media directory and automatically render .coffee files into .js files in the same (sub)directory.

The best way to incorporate Flask-Coffee into your development is as described for flask-lesscss in my earlier flask-script tutorial.

Contribute

If you want to contribute email me at the email at http://pypi.python.org/pypi/Flask-Coffee after checking out the code at http://bettercodes.org/projects/flask-coffee.

2 comments:

  1. Any pointers on how to configure the source and destination folders for coffee script??? The other link to Flask-lesscsss show just how to use it.. I would really like to know how to configure it.

    ReplyDelete
    Replies
    1. You don't configure it as such, they just are where the coffee files are found. The js files are created in the same directory.

      Delete