#!/usr/bin/perl # (c) Copyright by authors of the Tiki Wiki CMS Groupware Project # # All Rights Reserved. See copyright.txt for details and a complete list of authors. # Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. # $Id$ # red : element not exists in css coloumn # green : element exists in css column # yellow : base markup # #0ff (aqua): css column title # #f70 (orange): element not found in script (may be in smarty variable ?) # #7f7 (light green): element found in script use Getopt::Long; use File::Spec::Functions; use File::Find; # base directory of tikiwiki my $root = 'E:\Eclipse\3.2.1\tiki'; # file to generate my $html = "mapcss.html"; # nb rows between titles my $row = 30; # nb columns between elements my $col = 17; # synopsys : extract_selector.pl [-root ] [-html ] [-row y] [-col x] GetOptions( "root=s" => \$root, "html=s" => \$html, "row=i" => \$row, "col=i" => \$col); my $style = catdir($root,'styles'); my %markup = map { $_ => 1 } ('*','a','abbr','acronym','address','applet','area', 'b','base','basefont','bdo','big','blogquote','body','br','button','caption','center', 'cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','fieldset','font', 'form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img', 'input','ins','isindex','kbd','label','legend','li','link','map','menu','meta','noframes', 'noscript','object','ol','optgroup','option','p','param','pre','q','s','samp','script', 'select','small','span','strike','strong','style','sub','sup','table','tbody','td', 'textarea','tfoot','th','thead','title','tr','tt','u','ul','var'); ################################### print "Looking for main css ...\n"; ################################### opendir(REP, $style) or die "Impossible to open directory : $style\n"; my @css = map { s/\.css// ; $_ } grep { /\.css$/ } readdir REP; closedir REP; ################################### print "Looking for elements ...\n"; ################################### my %list; my %recap; foreach my $css (@css) { my $file = catfile($style, "${css}.css"); open(FILE, "<$file") or die "Impossible to open file : $file\n"; while($ligne = ) { next if $ligne =~ /\/\*/ .. $ligne =~ /\*\//; if ($ligne =~ /^(\S.*?)\s*\{/) { my $list = $1; foreach my $slist (split /[,>\s]/, $list) { $list{$css}{$slist}++; $recap{$slist}{n}++; ($slistdp = $slist) =~ s/:.*$//; $recap{$slist}{h}++, next if exists $markup{lc($slistdp)}; ($slistpp = $slistdp) =~ s/\[.*\]$//; $recap{$slist}{h}++ if exists $markup{lc($slistpp)}; } } } close FILE; } my $nbel = keys %recap; ################################### print "Looking for use case ...\n"; ################################### my %ref; find(\&analyze, ($root)); sub analyze { next unless /\.(tpl|php)$/; if (open(FILE, $File::Find::name)) { my $file = $_; while (my $line = ) { while ($line =~ /(class|id)="(.*?)"/ig) { if (uc($1) eq 'CLASS') { $ref{".$2"}{$file}++; } else { $ref{"#$2"}{$file}++; } } } close FILE; } } ################################################# print "Associating use case with elements ...\n"; ################################################# foreach my $use (keys %ref) { foreach my $el (keys %recap) { if ($el =~ /\Q$use\E(\s|:|$)/) { $recap{$el}{f} = join "\n", sort keys %{$ref{$use}}, ($recap{$el}{f} ? $recap{$el}{f} : ()); } } } %ref = undef; ################################# print "Building html page ...\n"; ################################# open(FILE,">$html") or die "Impossible to open file : $html\n"; print FILE "

Map of non existent elements in all main css : $root

"; print FILE "\n"; print FILE "\n"; my $cssname = ""; my $nbcss = 0; my %count; foreach my $css (sort keys %list) { $cssname .= "" if $nbcss % $col == 0; $cssname .= ""; $nbcss++; $count{$css} = 0; } $cssname .= "\n"; my $count = 0; foreach my $el (sort keys %recap) { my $ccol = 0; my $flag = 0; my $coul = exists $recap{$el}{h} ? 'y' : (exists $recap{$el}{f} ? 'o' : 'e'); my $ligne = ""; foreach my $css (sort keys %list) { $ligne .= "" if $ccol % $col == 0; $ccol++; if (exists $list{$css}{$el}) { $ligne .= ""; $count{$css}++; } else { $ligne .= ""; $flag++; } } $ligne .= "\n"; if ($flag) { print FILE $cssname if $count % $row == 0; print FILE $ligne; $count++; } } print FILE ""; $nbcss = 0; foreach my $css (sort keys %list) { print FILE "" if $nbcss % $col == 0; print FILE ""; $nbcss++; } print FILE "\n"; print FILE "
$css
$el
$count{$css}
\n"; print FILE "

$count/$nbel elements to complete in $nbcss css

"; close FILE; print "Terminated.\n";