]> iEval git - gruntmaster-page.git/commitdiff
Merge branch 'master' into newmc
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 2 Apr 2015 08:11:59 +0000 (11:11 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 2 Apr 2015 08:11:59 +0000 (11:11 +0300)
Conflicts:
Makefile.PL
make_static.PL

1  2 
Makefile.PL
lib/Plack/App/Gruntmaster/HTML.pm
make_static.PL

diff --combined Makefile.PL
index 2b025b150581082049e9a4feb1d00aa7673a47c7,6da9ecfdcc774618a09f3f493a534a5001f2746a..6f86eb4000552f0305115281d414563a5332706a
@@@ -10,11 -10,10 +10,11 @@@ WriteMakefile
        LICENSE           => 'AGPL_3',
        SIGN              => 1,
        clean             => {
-               FILES => 'static/css/ static/js.js css/logos.css static/logos.png static/js.map static/js/'
 -              FILES => 'static/css/ static/js.js static/js.js.gz static/js.map static/js/'
++              FILES => 'static/css/ static/js.js static/js.js.gz css/logos.css static/logos.png static/js.map static/js/'
        },
        BUILD_REQUIRES    => {
                qw/CSS::Minifier::XS          0
 +                 CSS::SpriteMaker           0
                   File::Slurp                0
                   JavaScript::Minifier::XS   0
                   Test::MockTime             0
                   strict      0
                   warnings    0
  
-                  Email::Simple                    0
-                  Email::Sender::Simple            0
                   File::Slurp                      0
                   Gruntmaster::Data                0
-                  HTML::Seamstress                 0
+                  HTML::Element::Library           0
+                  HTML::TreeBuilder                0
                   JSON::MaybeXS                    0
                   Log::Log4perl                    0
                   PerlX::Maybe                     0
index 7b343b22bb45c15ba067e792f0c611b7e9c8adf5,ebbc145e22cd3bd9f328c3e3a8da27b749d9e9c8..396f7d9fbdc93e54964e25c869543a37c90bb042
@@@ -4,7 -4,8 +4,8 @@@ use parent qw/Exporter/
  our @EXPORT = qw/render render_article/;
  
  use File::Slurp qw/read_file/;
- use HTML::Seamstress;
+ use HTML::Element::Library;
+ use HTML::TreeBuilder;
  use POSIX qw//;
  use Data::Dumper qw/Dumper/;
  
@@@ -45,7 -46,7 +46,7 @@@ sub HTML::Element::namedlink 
  my %page_cache;
  for (<tmpl/*>) {
        my ($tmpl, $lang) = m,tmpl/(\w+)\.(\w+),;
-       my $builder = HTML::Seamstress->new;
+       my $builder = HTML::TreeBuilder->new;
        $builder->ignore_unknown(0);
        $page_cache{$tmpl, $lang} = $builder->parse_file($_);
  }
@@@ -74,17 -75,12 +75,17 @@@ sub _render 
        $process->($tree, %args) if $process;
        $_->detach for $tree->look_down(static => $args{static} ? 'no' : 'yes');
        $_->attr('static', undef) for $tree->look_down(sub {$_[0]->attr('static')});
-       $_->attr('smap', undef) for $tree->look_down(sub {$_[0]->attr('defmap')});
+       $_->attr('smap', undef) for $tree->look_down(sub {$_[0]->attr('smap')});
        $tree->as_HTML;
  }
  
 +my $logo = read_file 'mclogo.svg';
 +$logo =~ y/\n//d;
 +$logo =~ s/(\s+)/ /g;
 +
  sub process_skel {
        my ($tree, %args) = @_;
 +      $tree->fid('logo')->replace_with(literal $logo);
        $tree->content_handler(
                title   =>         $args{title},
                content => literal $args{meat});
@@@ -170,7 -166,10 +171,7 @@@ sub process_pb_entry 
        if ($args{contest_stop}) {
                $tree->fid('solution')->detach;
                $tree->fid('solution_modal')->detach;
 -              my $score = $tree->fid('score');
 -              $score->attr('data-start' => $args{open_time});
 -              $score->attr('data-stop'  => $args{contest_stop});
 -              $score->attr('data-value'  => $args{value});
 +              $tree->fid('score')->replace_content($args{value});
                $tree->fid('countdown')->attr('data-stop' => $args{contest_stop});
        } else {
                $tree->fid('job_log')->edit_href(sub{$_ .= "&private=$args{private}"}) if $args{private};
diff --combined make_static.PL
index 489652a421a4db89db15774b32b758e2f8d95664,10532b9a8dbd502663ba66c505f36b92534d592c..4d737fa3d7c330c28a8bb9c477f941c5e9ca2b10
@@@ -3,39 -3,19 +3,45 @@@ use v5.14
  use warnings;
  
  use CSS::Minifier::XS qw//;
 +use CSS::SpriteMaker;
  use JavaScript::Minifier::XS qw//;
  
+ use IO::Compress::Gzip qw/gzip/;
  use File::Slurp qw/read_file write_file/;
  
  mkdir 'static';
  mkdir 'static/css';
  
 +sub make_sprite {
 +      my $maker = Local::CSS::SpriteMaker->new(
 +              css_class_prefix => 'logo-',
 +              rc_override_classname => sub {
 +                      my ($name) = @_;
 +                      $name =~ s/-light/.logo-light/r;
 +              }
 +      );
 +
 +      $maker->make_sprite(
 +              source_images     => ['logos/'],
 +              target_file       => 'static/logos.png',
 +              add_extra_padding => 10,
 +      );
 +
 +      $maker->print_css(
 +              filename        => 'css/logos.css',
 +              sprite_filename => '/static/logos.png',
 +      );
 +
 +      system 'pngnq-s9', '-s1', 'static/logos.png';
 +      system 'optipng', '-o7', '-zm1-9', 'static/logos-nq8.png';
 +      rename 'static/logos-nq8.png', 'static/logos.png';
 +}
 +
+ sub gzip_file {
+       my ($file) = @_;
+       gzip $file => "$file.gz", -Level => 9, Minimal => 1;
+ }
  sub make_css {
        my $common_css;
        $common_css .= read_file $_ for <css/*.css>;
@@@ -44,6 -24,7 +50,7 @@@
                my $css = read_file $_;
                $css .= $common_css;
                write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css;
+               gzip_file "static/css/$theme.css";
        }
  }
  
@@@ -58,6 -39,7 +65,7 @@@ sub make_js 
                $js .= read_file $_ for <js/*.js>;
                write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
        }
+       gzip_file 'static/js.js';
  }
  
  my $css_mtime = -M 'static/css/slate.css' // 0;
@@@ -75,32 -57,3 +83,32 @@@ for (<js/*>) 
                last
        }
  }
 +
 +my $sprite_mtime = -M 'static/logos.png' // 0;
 +for (<logos/*>) {
 +      if (!$sprite_mtime || $sprite_mtime > -M) {
 +              make_sprite;
 +              last
 +      }
 +}
 +
 +package
 +  Local::CSS::SpriteMaker;
 +
 +use parent qw/CSS::SpriteMaker/;
 +
 +sub _get_stylesheet_string {
 +      my $self = shift;
 +      my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_);
 +      shift @ret;
 +      @ret = sort @ret;
 +      unshift @ret, <<EOF;
 +a.logo {
 +      background-image: url("/static/logos.png");
 +      background-repeat: no-repeat;
 +      display: inline-block;
 +      vertical-align: middle;
 +}
 +EOF
 +      join "\n", @ret;
 +}
This page took 0.037897 seconds and 4 git commands to generate.