Flask-Cake

Flask-Cake runs CoffeeScript Cake files automatically on filesystem changes. This is useful, for example, when you want to perform tasks like compile all CoffeeScript files in to JavaScript files.

Installation

The Flask-Cake extension can be easily installed. To install with easy_install:

$ easy_install Flask-Cake

Alternatively, if you have pip installed:

$ pip install Flask-Cake

Usage

You initialize the extension by creating an instance of flask_cake.Cake:

from flask import Flask
from flask_cake import Cake

app = Flask(__name__)
cake = Cake(app)

Like most Flask extensions, a Flask-Cake instance may be used with multiple applications by initializing with flask_cake.Cake.init_app():

app = Flask(__name__)
cake = Cake()
cake.init_app(app)

Currently, Flask-Cake requires you to have a directoy structure like this:

app/
  static/
    coffee/
      Cakefile

Inside the Cakefile, you need to have a build task. This will be configurable in the future, along with the path to the Cakefile. The build task can do whatever you want. Here is a simple example that combines many different .coffee files into a single .js file in a different directory:

{exec} = require 'child_process'

coffeeFiles = [
    'models/users.coffee',
    'controllers/user.coffee',
    'views/user.coffee',
    'login.coffee',
    'app.coffee',
]

task 'build', 'Build PunchedOut! JavaScript file', ->
    console.log 'Building PunchedOut! application.js file...'

    exec "coffee --join app.js --output ../js/ --compile #{coffeeFiles.toString().replace(/,/g, ' ')}"

CoffeeScript documentation

The following links might be useful for furthur information:

Fork me on GitHub