minifierskin 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#!/bin/bash

# This example script can be used to compact a skin (pastel by default)
# It uses CSS sprite and remove spaces in HTML

# Note: it must be launched in the skin dir

NAME=img
SRC=pastel
DST=pastel-compact
rm -rf $NAME $DST
mkdir $NAME $DST
find $SRC/ -type f -iname '*.css' -exec cat {} \; | \
perl -ne 'if(m#\@import url\(\s*"[\./]+(.*?.css)"#){print `cat $1`}else{print}' \
	| perl -pe 'if(!s#url\s*\(\s*"?(?:\.\./)?(\.\./common/[^\)"]*)"?\s*\)#url\("$1")#){
			if(s#url\s*\(\s*"?(?:.*?/)?([\w\-]+\.(?:png|gif|jpe?g))"?\s*\)#url\("$1")#){
				$name=$1;
				$img=`find '$SRC'/ -type f -name $name`;
				chomp $img;
				if($img){
					`cp $img '$DST'`;
				}
				else{
					$img=`find common/ -type f -name $name`;
					chomp $img;
					if($img){
						s#url\("#url\("../common/#;
					}
					else {
						print STDERR "$name not found\n";
					}
				}
			}
		}'>styles2.css
LIST=$(find $SRC -type f -iname '*.tpl')
for L in $LIST; do
	perl -ne 's/^\s+//;
		s/\s*$/\n/s;
		next if(/^$/);
		$j=1 if(m#<script#i);
		$j=0 if(m#</script#i);
		s#/css/#/#;
		if(s/<img[^>]*
		(?:<TMPL[^>]*>)?[^>]*?
		((?:\w+|<TMPL_VAR\s+NAME="\w+"\s*>))(\.(?:png|gif|jpe?g))[^>]*>
		/<div class="sprite-img-$1"><\/div>/xg){
				my $img=$1.$2;
				chomp $img;
				unless($img=~/^</){
					$img=`find '$SRC'/ common/ -type f -name $img`;
					chomp $img;
					unless($imgs{$img}){
						`cp $img '$NAME'`;
						$imgs{$img}++;
					}
				}
		}
		if((/^<!DOCTYPE/ or $ind) and !/>$/) {
			$ind=1;
		}
		elsif((/^<!DOCTYPE/ or $ind) and />$/) {
			$ind=0;
		}
		elsif(!/^<\?xml/i and !m#^//# and !$j) {
			chomp;
		}
		print "\n" if(m#^</?TMPL_IF#);
		print;' $L >${L/$SRC/$DST}
done
LIST=$(find $SRC -type l -iname '*.tpl')
for L in $LIST; do
	echo "####### $L"
	cp -d $L $DST
done
AUTHLIST=$(ls /usr/share/perl5/Lemonldap/NG/Portal/Auth*|sed -e 's/.*\/Auth/common\//' -e 's/\.pm/\.png/')
for FILE in $AUTHLIST; do
	[ -e $FILE ] && cp $FILE $NAME
done
glue-sprite $NAME $DST
find $DST/ -type f -iname '*.css' -exec cat {} \; -delete >styles.css
cat styles.css styles2.css > $DST/styles.css
rm -f styles.css styles2.css
rm -rf $NAME