Debian Codegraph @

debian/packer/packMJfile

raw
1 #! /usr/bin/perl
2
3 # Compresses a MathJax file and reports the new size and savings.
4 # You need to have yuicompressor in order for this to work
5 #
6 # Usage: packMJfile src-file dest-file
7
8 use Cwd;
9 use FindBin;
10
11 $bindir = $FindBin::Bin;
12
13 $JAVA = "java";
14 $SED = "sed";
15 $YUICOMPRESSOR = "/usr/share/yui-compressor/yui-compressor.jar";
16
17 $YUIFILTER = "$bindir/yuiFilter";
18 $src = shift; $dst = shift;
19
20
21 if ($src =~ m!/config/(local/local|default)\.js$!) {
22 print "============================================\n";
23 print "Copying: $src\n";
24 system("cp '$src' '$dst'");
25 exit;
26 }
27
28 print "============================================\n";
29 print "Compressing: $src\n";
30 print "--------------------------------------------";
31 # The sed command uncomments the 'MathJax.isPacked = true;' from MathJax.js
32 system("cat '$src' | $SED \"s\/^.*\\/\\/ \\(MathJax.isPacked = true;\\).*$\/\\1\/\" | $JAVA -jar '$YUICOMPRESSOR' -v -o '$dst' --type js 2>&1 | $YUIFILTER");
33
34 open(MJX,"<", $dst);
35 @lines = <MJX>;
36 close(MJX);
37 $compressed = join("",@lines);
38
39 $template = "$bindir/template.js";
40
41 open(MJX,"<",$template);
42 @lines = <MJX>;
43 close(MJX);
44 $lines = join("",@lines);
45
46 $dstname = $dst; $dstname =~ s!.*/(dpvc-)?MathJax!/MathJax!;
47 $cwd = getcwd; $dstname =~ s/\Q$cwd\E/\/MathJax/;
48 $lines =~ s/%%%NAME%%%/$dstname/;
49 $lines =~ s/%%%DATA%%%/$compressed/;
50
51
52 open(MJX,">",$dst);
53 print MJX $lines;
54 close(MJX);
55
56 1;