X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/dae492a5488a4b54635d1c8de597162e649fd123..9cabbcb99510ce7c9256d085d1c9de6c0b5fc8ce:/browser.plp diff --git a/browser.plp b/browser.plp index aaafa03..fa317a8 100644 --- a/browser.plp +++ b/browser.plp @@ -6,8 +6,10 @@ use List::Util qw(sum max first); Html({ title => 'browser compatibility cheat sheet', version => 'v1.0', - description => - "caniuse.", + description => [ + "Compatibility table of new web features (HTML5, CSS3, SVG, Javascript)", + "comparing support and usage share for all popular browser versions.", + ], keywords => [qw' web browser support compatibility usage available feature html html5 css css3 svg javascript js dom mobile @@ -66,8 +68,7 @@ if (my ($somerow) = values %{ $caniuse->{data} }) { $versions{$browser} = [ sort { paddedver($a) cmp paddedver($b) } keys %$row ]; } } -my @browsers = grep { $versions{$_} } - qw(trident gecko webkit_saf ios_saf webkit_chr android presto op_mob op_mini); +my @browsers = keys %versions; print <<'';
Alternate rendition of Fyrd's when can I use... page @@ -77,7 +78,7 @@ given ($get{usage} // 'wm') { when (!$_) { # none } - when (!/^\w+$/) { + when (!/^[a-z][\w-]+$/) { printf "
Invalid browser usage data request: %s",
'identifier must be alphanumeric name or 0
';
}
@@ -86,16 +87,20 @@ given ($get{usage} // 'wm') {
break;
};
$usage = $_;
- my $ref = $canihas->{-source} || 'unknown';
- $ref = sprintf '%s', $_, $ref for $canihas->{-url} || ();
+ my $ref = $canihas->{-title} || 'unknown';
+ $ref = sprintf '%s', $_, $ref
+ for $canihas->{-site} || $canihas->{-source} || ();
$ref .= " $_" for $canihas->{-date} || ();
print "\nwith $ref browser usage statistics";
}
-if ($usage) {
- # first() does not work inside given >:(
+if ($usage) { # first() does not work inside given >:(
+ # adapt version usage to actual support data
+ my %engineuse; # prefix => usage sum
while (my ($browser, $row) = each %$canihas) {
my $verlist = $versions{$browser} or next;
my %supported = map { $_ => 1 } @$verlist;
+
+ # cascade unknown versions
$row->{$_} //= undef for @$verlist; # ensure stable keys during iteration
while (my ($version, $usage) = each %$row) {
next if defined $supported{$version};
@@ -104,7 +109,28 @@ if ($usage) {
$row->{$next} += $usage;
$row->{$version} = 0; # balance browser total
}
+
+ # reusable aggregates (grouped by prefix (engine) and browser)
+ $engineuse{ $caniuse->{agents}->{$browser}->{prefix} } +=
+ $row->{-total} = sum(values %$row);
}
+
+ # order browser columns by usage grouped by engine
+ @browsers = sort {
+ $engineuse{ $caniuse->{agents}->{$b}->{prefix} } <=>
+ $engineuse{ $caniuse->{agents}->{$a}->{prefix} }
+ ||
+ $canihas->{$b}->{-total} <=> $canihas->{$a}->{-total}
+ } @browsers;
+}
+else {
+ # order browser columns by name grouped by engine
+ @browsers = sort {
+ $caniuse->{agents}->{$b}->{prefix} cmp
+ $caniuse->{agents}->{$a}->{prefix}
+ ||
+ $a cmp $b
+ } @browsers;
}
:>.
$_
" for map { ref $_ ? @$_ : $_ || () } - Entity($row->{description}), formathtml($row->{notes}); # sic + Entity($row->{description}), + map { s/\s*\n/\n