#!/usr/bin/perl use Data::Dumper; use JavaScript::Minifier qw(minify); use CSS::Compressor qw( css_compress ); my $index = shift; if (!$index) { print STDERR "Usage: $0 \n"; exit 1; } my $out = "digiproof.html"; print STDERR "open index\n"; open I, "<$index" or die "Could not open index: $index $!\n"; my @source = ; close I; print STDERR "open $out\n"; open OUT, ">$out" or die "Could not open output $out: $!\n"; select OUT; print STDERR "enter loop\n"; foreach (@source) { chomp; next if(/^\s*$/); if (/rel="stylesheet" href="([^"]*)"/) { my $cssfile = $1; my $media = ""; if (/media="([^"]*)"/) { $media = qq( media="$1" ); } print STDERR "Inserting $cssfile\n"; print qq(\n); } elsif (/script src="([^"]*)"/) { my $jsfile = $1; print STDERR "Inserting $jsfile\n"; print qq(\n); } else { print qq($_\n); } } sub fetch { my $file = shift; open F, "<$file" or die "Could not open index: $file $!\n"; if($file =~ /\.js/) { my $js = minify(input => *F); # ember.js (and probably others) contain strings which contain # which leads to rendering failures, those will be fixed here $js =~ s/<\/script>/' + Slash + 'script>/g; close F; return "/* js from $file */\n" . $js; } else { my $src = join "", ; close F; return "/* css from $file */\n" . css_compress($src); } }