From 7004c8352cda3c81e547aabc037fd9ec7f03172c Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 24 Nov 2010 09:53:18 +0100 Subject: vndb.pl: Use the Makefile to auto-update static files Rather than trying to figure out what to update in the Perl code, duplicating the logic that's already present in the Makefile. This is only enabled when 'regen_static' is set to true in data/config.pl. --- data/global.pl | 1 + lib/VNDB/Plugin/TransAdmin.pm | 2 +- util/vndb.pl | 49 +++++++------------------------------------ 3 files changed, 9 insertions(+), 43 deletions(-) diff --git a/data/global.pl b/data/global.pl index 1a617580..c64eeac7 100644 --- a/data/global.pl +++ b/data/global.pl @@ -22,6 +22,7 @@ our %S = (%S, cookie_prefix => 'vndb_', global_salt => 'any-private-string-here', form_salt => 'a-different-private-string-here', + regen_static => 0, source_url => 'http://git.blicky.net/vndb.git/?h=master', admin_email => 'contact@vndb.org', scr_size => [ 136, 102 ], # w*h of screenshot thumbnails diff --git a/lib/VNDB/Plugin/TransAdmin.pm b/lib/VNDB/Plugin/TransAdmin.pm index 4859ea67..6d4de67e 100644 --- a/lib/VNDB/Plugin/TransAdmin.pm +++ b/lib/VNDB/Plugin/TransAdmin.pm @@ -121,7 +121,7 @@ sub _savelang { # re-read the file and regenerate the JS in case we're not running as CGI if($INC{"FCGI.pm"}) { VNDB::L10N::loadfile(); - VNDB::checkjs(); + system "make -sC $VNDB::ROOT js" if $self->{regen_static}; } } diff --git a/util/vndb.pl b/util/vndb.pl index 29c2648c..b8988fd5 100755 --- a/util/vndb.pl +++ b/util/vndb.pl @@ -24,13 +24,10 @@ use SkinFile; our(%O, %S); -# load and (if required) regenerate the skins +# load the skins # NOTE: $S{skins} can be modified in data/config.pl, allowing deletion of skins or forcing only one skin -$S{skins} = readskins(); - - -# automatically regenerate script.js when required and possible -checkjs(); +my $skin = SkinFile->new("$ROOT/static/s"); +$S{skins} = { map +($_ => [ $skin->get($_, 'name'), $skin->get($_, 'userid') ]), $skin->list }; # load lang.dat @@ -41,6 +38,10 @@ VNDB::L10N::loadfile(); require $ROOT.'/data/global.pl'; +# automatically regenerate the skins and script.js and whatever else should be done +system "make -sC $ROOT" if $S{regen_static}; + + YAWF::init( %O, namespace => 'VNDB', @@ -96,39 +97,3 @@ sub handle404 { $self->htmlFooter; } - -sub readskins { - my %skins; # dirname => skin name - my @regen; - my $lasttemplate = [stat "$ROOT/data/style.css"]->[9]; - my $skin = SkinFile->new("$ROOT/static/s"); - for my $n ($skin->list) { - $skins{$n} = [ $skin->get($n, 'name'), $skin->get($n, 'userid') ]; - next if !$skins{$n}[0]; - - my $f = "$ROOT/static/s/$n"; - my $css = -f "$f/style.css" && [stat "$f/style.css"]->[9] || 0; - my $boxbg = -f "$f/boxbg.png" && [stat "$f/boxbg.png"]->[9] || 0; - my $lastgen = $css < $boxbg ? $css : $boxbg; - push @regen, $n if (!$lastgen && -x $f && (!$css && !$boxbg || $css && -w "$f/style.css" || $boxbg && -w "$f/boxbg.png")) - || ([stat "$f/conf"]->[9] > $lastgen || $lasttemplate > $lastgen) && -w "$f/style.css" && -w "$f/boxbg.png"; - } - system "$ROOT/util/skingen.pl", @regen if @regen; - return \%skins; -} - - -sub checkjs { - my $script = "$ROOT/static/f/script.js"; - my $lastmod = [stat $script]->[9]; - system "$ROOT/util/jsgen.pl" if - (!-e $script && -x "$ROOT/static/f") - || (-e $script && -w $script && ( - $lastmod < [stat "$ROOT/data/script.js"]->[9] - || $lastmod < [stat "$ROOT/data/lang.txt"]->[9] - || (-e "$ROOT/data/config.pl" && $lastmod < [stat "$ROOT/data/config.pl"]->[9]) - || $lastmod < [stat "$ROOT/data/global.pl"]->[9] - || $lastmod < [stat "$ROOT/util/jsgen.pl"]->[9] - )); -} - -- cgit v1.2.3