Apache2::Filter::CSS::LESS - Apache2 LESS to CSS conversion filter


Apache2-Filter-CSS-LESS documentation Contained in the Apache2-Filter-CSS-LESS distribution.

Index


Code Index:

NAME

Top

Apache2::Filter::CSS::LESS - Apache2 LESS to CSS conversion filter

SYNOPSIS

Top

  <LocationMatch "\.less$">
      PerlOutputFilterHandler   Apache2::Filter::CSS::LESS
      # optionally, set the output content type.
      # default content type is text/css
      # PerlSetVar LessContentType "text/plain"
  </LocationMatch>

DESCRIPTION

Top

Apache2::Filter::CSS::LESS is a mod_perl2 output filter which converts CSS LESS files into CSS on demand using CSS::LESSp.

Caching

Conversion of LESS files to CSS requires considerably more CPU resources than simply serving up static CSS files. Therefore, it is recommended that you use some sort of cache in order to minimize the processing required to convert LESS files. An example to cache everything under /less using mod_cache:

 # cache root directory
 CacheRoot /path/to/disk/cache
 # turn on cache for "/less/" location
 CacheEnable disk /less/

see the mod_cache documentation for more details.

CONFIGURATION

Top

The following PerlSetVar's are recognized:

LessContentType

Sets the output content type of the filtered CSS. The default content type is text/css.

SOURCE

Top

You can contribute or fork this project via github:

http://github.com/mschout/apache2-filter-css-less

 git clone git://github.com/mschout/apache2-filter-css-less.git

BUGS

Top

Please report any bugs or feature requests to bug-apache2-filter-css-less@rt.cpan.org, or through the web interface at http://rt.cpan.org/

AUTHOR

Top

Michael Schout <mschout@cpan.org>

COPYRIGHT & LICENSE

Top

SEE ALSO

Top

CSS::LESSp, Apache2


Apache2-Filter-CSS-LESS documentation Contained in the Apache2-Filter-CSS-LESS distribution.

package Apache2::Filter::CSS::LESS;

use 5.008;
use strict;

use APR::Table;
use Apache2::Const -compile => qw(OK);
use Apache2::Filter;
use Apache2::Log;
use Apache2::RequestRec;
use Apache2::RequestUtil;

use CSS::LESSp;

our $VERSION = '0.30';

sub handler :method {
    my ($class, $f) = @_;

    my $r = $f->r;

    my $ctx = $f->ctx;
    while ($f->read(my $buffer, 4096)) {
        $ctx .= $buffer;
    }

    unless ($f->seen_eos) {
        $f->ctx($ctx);
        return Apache2::Const::OK;
    }

    if ($ctx) {
        my $css = join '', CSS::LESSp->parse($ctx);

        # fix headers, change content type
        $r->headers_out->unset('Content-Length');
        $r->content_type($r->dir_config('LessContentType') || 'text/css');

        $f->print($css);
    }

    return Apache2::Const::OK;
}

1;

__END__