]> iEval git - gruntmaster-page.git/blame - make_static.PL
Call optipng on sprite file
[gruntmaster-page.git] / make_static.PL
CommitLineData
8798626b
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6eb2623e 6use CSS::SpriteMaker;
8798626b
MG
7use JavaScript::Minifier::XS qw//;
8
9use File::Slurp qw/read_file write_file/;
10
11mkdir 'static';
12mkdir 'static/css';
13
6eb2623e
MG
14my $maker = Local::CSS::SpriteMaker->new(
15 css_class_prefix => 'logo-',
16 rc_override_classname => sub {
17 my ($name) = @_;
18 $name =~ s/-light/.logo-light/r;
19 }
20);
21
22$maker->make_sprite(
23 source_images => ['logos/'],
24 target_file => 'static/logos.png',
25 add_extra_padding => 10,
26);
27
28$maker->print_css(
29 filename => 'css/logos.css',
30 sprite_filename => 'https://static.mindcoding.ro/static/logos.png',
31);
32
c9dee865
MG
33system 'optipng', '-o7', '-zm1-9', 'static/logos.png';
34
8798626b
MG
35my $common_css;
36$common_css .= read_file $_ for <css/*.css>;
37for (<css/themes/*>) {
38 my ($theme) = m,themes/(.*)\.css,;
39 my $css = read_file $_;
40 $css .= $common_css;
41 write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css;
42}
43
9cad7bdd
MG
44if (-f 'compiler.jar') {
45 system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js.map --js_output_file static/js.js --language_in ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
46 my $js = read_file 'static/js.js';
47 write_file 'static/js.js', '//# sourceMappingURL=/static/js.map', "\n", $js;
48 system 'cp', '-rp', 'js', 'static/';
49} else {
50 my $js;
51 $js .= read_file $_ for <js/*.js>;
52 write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
53}
6eb2623e
MG
54
55package
56 Local::CSS::SpriteMaker;
57
58use parent qw/CSS::SpriteMaker/;
59
60sub _get_stylesheet_string {
61 my $self = shift;
62 my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_);
63 shift @ret;
64 @ret = sort @ret;
65 unshift @ret, <<EOF;
66a.logo {
67 background-image: url("https://static.mindcoding.ro/static/logos.png");
68 background-repeat: no-repeat;
69 display: inline-block;
70 vertical-align: middle;
71}
72EOF
73 join "\n", @ret;
74}
This page took 0.029411 seconds and 4 git commands to generate.