X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/58725794d72361cc70cb082476a32d08e22d21d0..7178c19ec55db35dc1d073aef9a20138b15b19d7:/common.inc.plp diff --git a/common.inc.plp b/common.inc.plp index 39865bd..d282f09 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -78,7 +78,7 @@ sub stylesheet { return map { sprintf( '', - $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.13", $_ + $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.14", $_ ) } @avail; } @@ -102,7 +102,11 @@ sub checkmodified { sub Data { my ($filename) = @_; my @data = eval { - do "$filename.inc.pl"; + open my $cache, '<:raw', "data/$filename.json" + or return do "./$filename.inc.pl"; # silent fallback to original code + require JSON; + local $/; # slurp + return JSON::decode_json(readline $cache); }; if ($! or $@ or !@data or !$data[0]) { die ['Table data not found', $@ || $!]; @@ -129,6 +133,7 @@ sub Html { # default fallbacks $meta->{stylesheet} ||= [qw( light dark circus mono red )]; $meta->{charset} ||= 'utf-8'; + $meta->{lang} ||= 'en'; # convert options to arrays ref $_ eq 'ARRAY' or $_ = [$_] @@ -137,6 +142,7 @@ sub Html { # document headers before output $header{content_type} = "text/html; charset=$meta->{charset}" unless $PLP::sentheaders; + exit if $ENV{REQUEST_METHOD} eq 'HEAD'; unshift @{ $meta->{raw} }, stylesheet($meta->{stylesheet}); push @{ $meta->{raw} }, ( @@ -157,7 +163,7 @@ sub Html { PLP_START { # leading output say ''; - say ''; + say qq(); say ''; say ''; say sprintf '', $_ @@ -229,10 +235,9 @@ BEGIN { sub showlink { my ($title, $href, $selected) = @_; - return sprintf( - !$href ? '%s' : - $selected ? '%s' : '%s', - EscapeHTML($title), EscapeHTML($href) - ); + EscapeHTML($title); + return $title if not $href; + return "$title" if $selected; + return sprintf '%s', EscapeHTML($href), $title; }