formatchar: annotation options, print method
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Mar 2010 22:59:55 +0000 (22:59 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 25 Mar 2010 17:39:31 +0000 (17:39 +0000)
Shiar_Sheet/FormatChar.pm
unicode.plp
writing.plp

index a501b945ca1ecb1a784f27ebe477e80ef4e46ec8..ba380356ac7a69debe2060458a36f8117472b132 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use Data::Dump 'pp';
 use PLP::Functions 'EscapeHTML';
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 our $diinfo = do 'digraphs.inc.pl';
 our %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
@@ -14,7 +14,7 @@ our %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
 
 sub new {
        my ($class) = @_;
-       bless {}, $class;
+       bless { digraph => 1, unicode => 0 }, $class;
 }
 
 sub glyph_info {
@@ -38,7 +38,7 @@ sub glyph_html {
        my $title = sprintf 'U+%04X%s', $codepoint, $name && " ($name)";
        my @class = ('X', grep {$_} $prop, $script);
 
-       $cell = "<span>$cell</span>" if $prop eq 'Zs';
+       $cell = "<span>$cell</span>" if $prop and $prop eq 'Zs';
        $cell = '&nbsp;' if $cell eq '';
 
        return ($cell, EscapeHTML($title), join(' ', @class), $mnem);
@@ -101,9 +101,9 @@ sub cell {
                @class ? sprintf(' class="%s"', join ' ', @class) : '',
                $html || '',
                $cell eq '' ? '&nbsp;' : $cell,
-               defined $mnem && length $mnem
+               $self->{digraph} && defined $mnem && length $mnem
                        ? sprintf(' <small class="digraph">%s</small>', EscapeHTML($mnem))
-                       : $cell =~ /^[^a-zA-Z]$/
+                       : $self->{unicode} + $cell =~ /^[^a-zA-Z]$/ > 0
                                ? sprintf(' <small class="%s">%04X</small>', 'value', ord $cell)
                                : '',
        );
@@ -151,9 +151,21 @@ sub table {
                $colspan = 1;
        }
 
-       return sprintf qq{<table class="glyphs dilabel">\n%s</table>\n},
+       return sprintf qq{<table class="glyphs%s">\n%s</table>\n},
+               $self->{digraph} || $self->{unicode} >= 0 ? ' dilabel' : '',
                join '', map {"<tr>$_\n"} @rows;
 }
 
+sub print {
+       my $self = shift;
+       while (@_) {
+               printf '<div class="section"><h2>%s</h2>'."\n\n", shift;
+               while (ref $_[0] and $_ = shift) {
+                       print $self->table($_);
+               }
+               print '</div>';
+       }
+}
+
 1;
 
index fb5ee03672068556ab492ffac406f10bb490c8fd..f506fb59165df582096e3fbced9d105457adf9a6 100644 (file)
@@ -28,19 +28,14 @@ i^k or i^vu respectively in <a href="/vi">Vim</a>.
 use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
 
-sub print_glyph_tables {
-       while (@_) {
-               printf '<div class="section"><h2>%s</h2>'."\n\n", shift;
-               while (ref $_[0] and $_ = shift) {
-                       print $glyphs->table($_);
-               }
-               print '</div>';
-       }
+if (exists $get{q}) {
+       $glyphs->{unicode}--;
+       $glyphs->{digraph}--;
 }
 
 our $verbose = exists $get{v};
 
-print_glyph_tables(
+$glyphs->print(
        'Popular',
        [qw{. « » . ‹ › . ‘ ’ . “ ” . „ ‚ . ‟ ‛}],
        [qw{. † ‡ • . § ¶ # . © ® ™ . ° ′ ″ . − × ÷ . ± ² √}],
index e57ceec47838c026e62584d195adad2d698eba88..30080ec41c282d4ebdb926f71df544e2fd1d94a9 100644 (file)
@@ -26,6 +26,10 @@ and <a href="/unicode">common chars</a>.</p>
 <:
 use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
+unless (exists $get{v}) {
+       $glyphs->{unicode}--;
+       $glyphs->{digraph}--;
+}
 
 print $glyphs->table([qw{
        .>Chinese              壹 貳 參 肆 伍 陸 柒 捌 玖 零
@@ -55,17 +59,7 @@ print $glyphs->table([qw{
        .>Osmanya              𐒡 𐒢 𐒣 𐒤 𐒥 𐒦 𐒧 𐒨 𐒩 𐒠
 }]);
 
-sub print_glyph_tables {
-       while (@_) {
-               printf '<div class="section"><h2>%s</h2>'."\n\n", shift;
-               while (ref $_[0] and $_ = shift) {
-                       print $glyphs->table($_);
-               }
-               print '</div>';
-       }
-}
-
-print_glyph_tables(
+$glyphs->print(
 Western => [qw{
        .>Latin      A > B  C G  D  > E  F  Y  VU W Z H  -  I J K L M N > X  O  P >  - Q  R > S  T
        .>Old_Italic 𐌀 > 𐌁  > 𐌂  𐌃  > 𐌄  𐌅𐌚 >  >  𐌖 𐌆 𐌇  𐌈  𐌉 𐌝 𐌊 𐌋 𐌌 𐌍 > 𐌎  𐌏  𐌐 >  𐌑 𐌒  𐌓 > 𐌔  𐌕