summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-01-24 14:21:26 +0100
committerYorhel <git@yorhel.nl>2010-01-24 14:22:46 +0100
commitb04c46baec8aef93d21898ef7f52b9d6d2442ce3 (patch)
treeca68ca3d952b4dc84ef21bac844c97b1523d323a /util
parent9b7a44bee4f47dca175be2f38bc516aa34e14104 (diff)
SkinFile: Abstracted access to the skin configuration files
And updated skingen.pl and vndb.pl to make use of this abstraction.
Diffstat (limited to 'util')
-rwxr-xr-xutil/skingen.pl76
-rwxr-xr-xutil/vndb.pl18
2 files changed, 35 insertions, 59 deletions
diff --git a/util/skingen.pl b/util/skingen.pl
index 73e4fdc7..37504921 100755
--- a/util/skingen.pl
+++ b/util/skingen.pl
@@ -1,6 +1,5 @@
#!/usr/bin/perl
-package VNDB;
use strict;
use warnings;
@@ -8,81 +7,66 @@ use Cwd 'abs_path';
use Image::Magick;
eval { require CSS::Minifier::XS };
-
-our($ROOT, %O);
+our $ROOT;
BEGIN { ($ROOT = abs_path $0) =~ s{/util/skingen\.pl$}{}; }
-
-if(@ARGV) {
- writeskin(readskin($_)) for (@ARGV);
-} else {
- /([^\/]+)$/ && writeskin(readskin($1)) for (glob($ROOT.'/static/s/*'));
-}
+use lib "$ROOT/lib";
+use SkinFile;
-sub readskin { # skin name
+sub writeskin { # $name
my $name = shift;
- my %o;
- open my $F, '<', $ROOT.'/static/s/'.$name.'/conf' or die $!;
- while(<$F>) {
- chomp;
- s/\r//g;
- s{[\t\s]*//.+$}{};
- next if !/^([a-z0-9]+)[\t\s]+(.+)$/;
- $o{$1} = $2;
- }
- close $F;
- $o{_name} = $name;
- return \%o;
-}
-
-
-sub writeskin { # $obj
- my $o = shift;
-
- # fix image locations
- $o->{$_} && ($o->{$_} = '/s/'.$o->{_name}.'/'.$o->{$_}) for (qw|imglefttop imgrighttop|);
+ my $skin = SkinFile->new("$ROOT/static/s", $name);
+ my %o = map +($_ => $skin->get($_)), $skin->get;
# get the right top image
- if($o->{imgrighttop}) {
+ if($o{imgrighttop}) {
+ my $path = "/s/$name/$o{imgrighttop}";
my $img = Image::Magick->new;
- $img->Read($ROOT.'/static'.$o->{imgrighttop});
- $o->{_bgright} = sprintf 'background: url(%s) no-repeat; width: %dpx; height: %dpx',
- $o->{imgrighttop}, $img->Get('width'), $img->Get('height');
+ $img->Read("$ROOT/static$path");
+ $o{_bgright} = sprintf 'background: url(%s) no-repeat; width: %dpx; height: %dpx',
+ $path, $img->Get('width'), $img->Get('height');
} else {
- $o->{_bgright} = 'display: none';
+ $o{_bgright} = 'display: none';
}
# body background
- if(!$o->{imglefttop}) {
- $o->{_bodybg} = "background-color: $o->{bodybg}";
+ if($o{imglefttop}) {
+ $o{_bodybg} = sprintf 'background: %s url(/s/%s/%s) no-repeat', $o{bodybg}, $name, $o{imglefttop};
} else {
- $o->{_bodybg} = "background: $o->{bodybg} url($o->{imglefttop}) no-repeat";
+ $o{_bodybg} = sprintf 'background-color: %s', $o{bodybg};
}
# main title
- $o->{_maintitle} = $o->{maintitle} ? "color: $o->{maintitle}" : 'display: none';
+ $o{_maintitle} = $o{maintitle} ? "color: ".$o{maintitle} : 'display: none';
# create boxbg.png
my $img = Image::Magick->new(size => '1x1');
- $img->Read('xc:'.$o->{boxbg});
- $img->Write(filename => $ROOT.'/static/s/'.$o->{_name}.'/boxbg.png');
- $o->{_boxbg} = '/s/'.$o->{_name}.'/boxbg.png';
+ $img->Read("xc:$o{boxbg}");
+ $img->Write(filename => "$ROOT/static/s/$name/boxbg.png");
+ $o{_boxbg} = "/s/$name/boxbg.png";
# get the blend color
$img = Image::Magick->new(size => '1x1');
- $img->Read('xc:'.$o->{bodybg}, 'xc:'.$o->{boxbg});
+ $img->Read("xc:$o{bodybg}", "xc:$o{boxbg}");
$img = $img->Flatten();
- $o->{_blendbg} = '#'.join '', map sprintf('%02x', $_*255), $img->GetPixel(x=>1,y=>1);
+ $o{_blendbg} = '#'.join '', map sprintf('%02x', $_*255), $img->GetPixel(x=>1,y=>1);
# write the CSS
open my $CSS, '<', "$ROOT/data/style.css" or die $!;
my $css = join '', <$CSS>;
close $CSS;
- $css =~ s/\$$_\$/$o->{$_}/g for (keys %$o);
- open my $SKIN, '>', "$ROOT/static/s/$o->{_name}/style.css" or die $!;
+ $css =~ s/\$$_\$/$o{$_}/g for (keys %o);
+ open my $SKIN, '>', "$ROOT/static/s/$name/style.css" or die $!;
print $SKIN $CSS::Minifier::XS::VERSION ? CSS::Minifier::XS::minify($css) : $css;
close $SKIN;
}
+if(@ARGV) {
+ writeskin($_) for (@ARGV);
+} else {
+ writeskin($_) for (SkinFile->new("$ROOT/static/s")->list);
+}
+
+
diff --git a/util/vndb.pl b/util/vndb.pl
index 32e1bdb4..07ad20aa 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -18,6 +18,7 @@ use lib $ROOT.'/lib';
use YAWF ':html';
use VNDB::L10N;
+use SkinFile;
our(%O, %S);
@@ -104,21 +105,12 @@ sub readskins {
my %skins; # dirname => skin name
my @regen;
my $lasttemplate = [stat "$ROOT/data/style.css"]->[9];
- for my $f (glob "$ROOT/static/s/*") {
- next if !-e "$f/conf";
- my $n = $1 if $f =~ m{([^/]+)$};
- open my $F, '<', "$f/conf" or die $!;
- while(<$F>) {
- chomp;
- s/\r//;
- s{[\t\s]*//.*$}{};
- next if !/^name[\t\s]+(.+)$/;
- $skins{$n} = $1;
- last;
- }
- close $F;
+ my $skin = SkinFile->new("$ROOT/static/s");
+ for my $n ($skin->list) {
+ $skins{$n} = $skin->get($n, 'name');
next if !$skins{$n};
+ 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;