X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/4e46e11f48bd75bb78cc5b310166287789efdd53..76de9b7e588839cbae32bf0cb21f529963363450:/browser.plp?ds=sidebyside diff --git a/browser.plp b/browser.plp index 55d5e65..0d4d4e7 100644 --- a/browser.plp +++ b/browser.plp @@ -1,11 +1,10 @@ <(common.inc.plp)><: -use 5.010; -use utf8; use List::Util qw(sum max first); +no if $] >= 5.018, warnings => 'experimental::smartmatch'; Html({ title => 'browser compatibility cheat sheet', - version => 'v1.1', + version => '1.4', description => [ "Compatibility table of new web features (HTML5, CSS3, SVG, Javascript)", "comparing support and usage share for all popular browser versions.", @@ -16,12 +15,12 @@ Html({ ie internet explorer firefox chrome safari webkit opera '], stylesheet => [qw'circus dark mono red light'], - data => ['browser-support.inc.pl'], + data => ['data/browser/support.inc.pl'], }); say "
Invalid browser usage data request: %s",
- 'identifier must be alphanumeric name or 0
';
+ when (!m{ \A [a-z]\w+ (?:/\d[\d-]*\d)? \z }x) {
+ Alert([
+ 'Invalid browser usage data request',
+ 'Identifier must be alphanumeric name or 0
.',
+ ]);
}
- $canihas = do "browser-usage-$_.inc.pl" or do {
- printf "
Browser usage data not found: %s", $! || $@;
+ $canihas = do "data/browser/usage-$_.inc.pl" or do {
+ Alert('Browser usage data not found', $@ || $!);
break;
};
$usage = $_;
@@ -159,6 +169,7 @@ if ($usage) { # first() does not work inside given >:(
}
else {
# order browser columns by name grouped by engine
+ @{$_} = map { [$_] } @{$_} for values %versions;
@browsers = sort {
$caniuse->{agents}->{$b}->{prefix} cmp
$caniuse->{agents}->{$a}->{prefix}
@@ -256,14 +267,14 @@ say '';
sub featurescore {
# relative amount of support for given feature
- state $statspts = { y=>1, 'y x'=>1, a=>.5, 'a x'=>.5, j=>.2, 'p j'=>.2, 'p p'=>.2, p=>.1 };
my $rank = 0;
if (my $row = shift) {
if ($canihas) {
while (my ($browser, $versions) = each %$row) {
ref $versions eq 'HASH' or next;
- while (my ($version, $_) = each %$versions) {
- $rank += ($canihas->{$browser}->{$version} || .001) * $statspts->{$_};
+ while (my ($version, $status) = each %$versions) {
+ $status =~ s/\h\#\d+//g;
+ $rank += ($canihas->{$browser}->{$version} || .001) * $PSTATS{$status};
}
}
return $rank;
@@ -281,12 +292,25 @@ sub featurescore {
}
splice @vers, -1, 0, @future; # move ahead to decrease precedence
}
- $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
+ $rank += $PSTATS{$_} * 2**($div--) for reverse @vers;
}
}
return $rank;
}
+sub formatnotes {
+ my @html = @_;
+ for (@html) {
+ s/\r\n?/\n/g; # windows returns
+ s/\h* $//gmx; # trailing whitespace
+ s/(?<= [^.\n]) $/./gmx; # consistently end each line by a period
+ Entity($_);
+ s{ ` ([^`]*) ` }{$1
}gx;
+ s{ \[ ([^]]*) \] \( ([^)]*) \) }{$1}gx;
+ }
+ return @html;
+}
+
sub saytitlecol {
my ($id) = @_;
my $row = $caniuse->{data}->{$id};
@@ -307,11 +331,15 @@ sub saytitlecol {
);
} $row->{title};
print '
$_
" for map { ref $_ ? @$_ : $_ || () } - Entity($row->{description}), - map { s/\s*\n/\n$_
" + for formatnotes($row->{description}, $row->{notes} || ()); + if (my %notes = %{ $row->{notes_by_num} }) { + say 'Browser-specific notes:';
+ say "
#$_: ", formatnotes($notes{$_}) for sort keys %notes;
+ say '