git.shiar.nl
/
sheet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
word/quiz: dynamic lang(uage) option
[sheet.git]
/
common.inc.plp
diff --git
a/common.inc.plp
b/common.inc.plp
index 39865bdb55f2ca961da6d7f0ebcaecbc760aab9a..6ea11976106b6363bd8b0d88dfca1b267cae6476 100644
(file)
--- a/
common.inc.plp
+++ b/
common.inc.plp
@@
-102,7
+102,11
@@
sub checkmodified {
sub Data {
my ($filename) = @_;
my @data = eval {
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', $@ || $!];
};
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';
# 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 $_ = [$_]
# convert options to arrays
ref $_ eq 'ARRAY' or $_ = [$_]
@@
-157,7
+162,7
@@
sub Html {
PLP_START {
# leading output
say '<!DOCTYPE html>';
PLP_START {
# leading output
say '<!DOCTYPE html>';
- say
'<html lang="en">'
;
+ say
qq(<html lang="$meta->{lang}">)
;
say '';
say '<head>';
say sprintf '<meta http-equiv="content-type" content="%s">', $_
say '';
say '<head>';
say sprintf '<meta http-equiv="content-type" content="%s">', $_
@@
-229,10
+234,9
@@
BEGIN {
sub showlink {
my ($title, $href, $selected) = @_;
sub showlink {
my ($title, $href, $selected) = @_;
- return sprintf(
- !$href ? '%s' :
- $selected ? '<strong>%s</strong>' : '<a href="%2$s">%s</a>',
- EscapeHTML($title), EscapeHTML($href)
- );
+ EscapeHTML($title);
+ return $title if not $href;
+ return "<strong>$title</strong>" if $selected;
+ return sprintf '<a href="%s">%s</a>', EscapeHTML($href), $title;
}
}