| App-ZofCMS-Plugin-CSSMinifier documentation | Contained in the App-ZofCMS-Plugin-CSSMinifier distribution. |
App::ZofCMS::Plugin::CSSMinifier - plugin for minifying CSS files
In your ZofCMS Template or Main Config File:
plugins => [
qw/CSSMinifier/,
],
plug_css_minifier => {
file => 'main.css',
},
Now, this page can be linked into your document as a CSS file (it will be minified)
The module is a plugin for App::ZofCMS that provides means to send minified CSS files.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
Minified means that all the useless stuff (which means whitespace, etc) will be stripped off the CSS file to save a few bytes. See CSS::Minifier for more info.
plugins plugins => [
qw/CSSMinifier/,
],
Mandatory. You need to include the plugin to the list of plugins to execute.
plug_css_minifier plug_css_minifier => {
file => 'main.css',
auto_output => 1, # default value
cache => 1, # default value
},
plug_css_minifier => sub {
my ( $t, $q, $config ) = @_;
return {
file => 'main.css',
auto_output => 1, # default value
cache => 1, # default value
}
},
Mandatory. Takes or a subref as a value. If subref is specified,
its return value will be assigned to plug_css_minifier as if it was already there. If sub returns
an undef, then plugin will stop further processing. The @_ of the subref will
contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and
App::ZofCMS::Config object; individual keys can be set in both Main Config
File and ZofCMS Template, if the same key set in both, the value in ZofCMS Template will
take precedence. The following keys/values are accepted:
file plug_css_minifier => {
file => 'main.css',
}
Mandatory. Takes a string as an argument that specifies the name of the CSS file to
minify. The filename is relative to index.pl file.
cache plug_css_minifier => {
file => 'main.css',
cache => 1,
},
Optional. Takes either true or false values. When set to a true value the plugin will
send out an HTTP Expires header that will say that this content expries in like 2038, thus
set this option to a false value while still developing your CSS. This argument
has no effect when auto_output (see below) is turned off (set to a false value).
Defaults to: 1
auto_output plug_css_minifier => {
file => 'main.css',
auto_output => 1,
},
Optional. Takes either true or false values. When set to a true value, plugin will
automatically send text/css Content-type header (along with Expires header if
cache argument is set to a true value), output the minified CSS file and exit().
Otherwise, the minified CSS file will be put into $t->{t}{plug_css_minifier}
where $t is ZofCMS Template hashref and you can do whatever you want with it.
Defaults to: 1
'Zoffix, <'zoffix at cpan.org'>
(http://haslayout.net/, http://zoffix.com/, http://zofdesign.com/)
Please report any bugs or feature requests to bug-app-zofcms-plugin-cssminifier at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-CSSMinifier. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::CSSMinifier
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-CSSMinifier
Copyright 2009 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| App-ZofCMS-Plugin-CSSMinifier documentation | Contained in the App-ZofCMS-Plugin-CSSMinifier distribution. |
package App::ZofCMS::Plugin::CSSMinifier; use warnings; use strict; our $VERSION = '0.0104'; use CSS::Minifier qw/minify/; use base 'App::ZofCMS::Plugin::Base'; sub _key { 'plug_css_minifier' } sub _defaults { auto_output => 1, cache => 1, file => undef, } sub _do { my ( $self, $conf, $t ) = @_; return unless defined $conf->{file} and length $conf->{file}; -e $conf->{file} or die "$conf->{file} was not found"; open my $fh, '<', $conf->{file} or die "$conf->{file} could not be opened for reading: $!"; my $css = minify( input => $fh ); if ( $conf->{auto_output} ) { if ( $conf->{cache} ) { print "Expires: Fri, 29 Oct 2038 14:19:41 GMT\n" } print "Content-type: text/css\n\n"; print $css; exit; } else { $t->{t}{plug_css_minifier} = $css; } } 1; __END__