NAME

Plack::Middleware::Compile

VERSION

version 0.01

SYNOPSIS

use Plack::Builder;

builder {
    enable 'Compile' => (
        pattern => qr{\.coffee$},
        lib     => 'coffee',
        blib    => 'js',
        mime    => 'text/plain',
        map     => sub { 
            my $filename = shift;
            $filename =~ s/coffee$/js/;
            return $filename;
        },
        compile => sub { 
            my ($in, $out) = @_;
            system("coffee --compile --stdio < $in > $out");
        }
    );
}

DESCRIPTION

Enable this middleware to serve compiled content (Coffeescript -> Javascript, Sass -> CSS, HAML -> HTML, etc). The content will only be compiled when the source is changed.

CONFIGURATION

pattern

A regex which will be matched against PATH_INFO to determine if the middleware should handle this request.

lib

A directory in which to find the source files.

blib

An output directory to send the compiled files to. This will be the same as your lib directory if you don't specify it.

mime

The mime type to serve the files as. Defaults to 'text/plain'.

map

A function that maps input filenames to output filenames.

compile

A function that takes the input and output filenames as arguments and produces the compiled file from the input.