forked from acme/cpan-mini-webserver
-
Notifications
You must be signed in to change notification settings - Fork 8
/
build_css.pl
executable file
·61 lines (53 loc) · 1.47 KB
/
build_css.pl
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
#!perl
use strict;
use warnings;
use Cwd qw(cwd);
use CSS::Squish;
use File::Find::Rule;
use File::Slurp;
use Perl::Tidy;
use Template;
use YAML qw(LoadFile DumpFile);
foreach my $filename ( File::Find::Rule->new->file->in( 'root/static/css' ) ) {
next if $filename =~ /my-screen\.css/;
unlink( $filename ) || die $!;
}
my $settings = 'blueprint/lib/settings.yml';
my $conf = LoadFile( $settings );
$conf->{cpanminiwebserver}->{path} = cwd . '/root/static/css/';
DumpFile( $settings, $conf );
use YAML;
system "cd blueprint/lib && ruby compress.rb -p cpanminiwebserver";
die "CSS files not generated" unless -f 'root/static/css/screen.css';
my $template = q{package CPAN::Mini::Webserver::Templates::CSS;
use strict;
use warnings;
use Template::Declare::Tags;
use base 'Template::Declare';
[% FOREACH file IN files %]
[% name = file.0 %]
[% css = file.1 %]
template 'css_[% name %]' => sub {
my $self = shift;
my $css = <<'END';
[% css %]
END
outs_raw $css;
};
[% END %]
1;
};
my $tt = Template->new;
$tt->process(
\$template,
{
files => [
[ 'ie' => scalar read_file( 'root/static/css/ie.css' ) ],
[ 'print' => scalar read_file( 'root/static/css/print.css' ) ],
[ 'screen' => scalar read_file( 'root/static/css/screen.css' ) ],
],
},
\my $perl,
) || die $template->error();
Perl::Tidy::perltidy( source => \$perl, destination => \my $tidied );
write_file( 'lib/CPAN/Mini/Webserver/Templates/CSS.pm', $tidied );