From bafb8b134744cba74a3a019fefb36091b0e19d13 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 7 Oct 2009 10:22:14 +0200 Subject: skingen: Used CSS::Minifier::XS instead of my crappy regexes The minified and gzipped CSS file is now 0.7kB smaller than the non-minified but gzipped CSS file. That's significant enough on ~5kB. --- README | 4 ++++ util/skingen.pl | 17 +++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README b/README index 1060c544..0ea41d8c 100644 --- a/README +++ b/README @@ -48,6 +48,10 @@ Requirements XML::Writer PerlIO::gzip + util/skingen.pl + Image::Magick + CSS::Minifier::XS (optional, minimizes CSS output) + Contact diff --git a/util/skingen.pl b/util/skingen.pl index e27ea4a1..d18f5fde 100755 --- a/util/skingen.pl +++ b/util/skingen.pl @@ -5,8 +5,8 @@ package VNDB; use strict; use warnings; use Cwd 'abs_path'; -use Data::Dumper 'Dumper'; use Image::Magick; +eval { require CSS::Minifier::XS }; our($ROOT, %O); @@ -78,19 +78,12 @@ sub writeskin { # $obj # write the CSS open my $CSS, '<', "$ROOT/data/style.css" or die $!; + my $css = join '', <$CSS>; + close $CSS; + $css =~ s/\$$_\$/$o->{$_}/g for (keys %$o); open my $SKIN, '>', "$ROOT/static/s/$o->{_name}/style.css" or die $!; - while((my $d = <$CSS>)) { - if($O{debug}) { - chomp $d; - $d =~ s/^\s*/ /; - $d =~ s{/\*.+\*/}{}; # NOTE: multiline comments or multiple comments per line won't work - next if $d !~ /[^\s\t]/; - } - $d =~ s/\$$_\$/$o->{$_}/g for (keys %$o); - print $SKIN $d; - } + print $SKIN $CSS::Minifier::XS::VERSION ? CSS::Minifier::XS::minify($css) : $css; close $SKIN; - close $CSS; } -- cgit v1.2.3