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)

By default, cake build will be executed. If your task is called something else, you can specifiy that with an additional argument when you create an instance of flask_cake.Cake. If you need to run multiple tasks, you can also specify a list of tasks:

app = Flask(__name__)
cake = Cake(app, "build")

# Or, specify multiple tasks
cake = Cake(app, ["build", "minify"])

Here is a simple example of a build task 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, ' ')}"

If your Cakefile isn’t located at the default static/coffee/Cakefile directory, you can specify the parent directory by using the cakeparent argument. Any path you specify should be relative to the Flask static_path. For example, to use a Cakefile located at static_path/example/coffeefiles/Cakefile, you should pass cakeparent="example/coffeefiles":

app = Flask(__name__)
cake = Cake(app, cakeparent="example/coffeefiles")

CoffeeScript documentation

The following links might be useful for furthur information:

Fork me on GitHub