Acme-AsciiArt2HtmlTable

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

The result will be something like this:

  <style>
  .special td { width:1; height:1; }
  .special tr {  }
  </style>
  <table class="special" cellspacing="0" cellpadding="0" border="0">

=head4 use-default-colors

If set to a false value, no default mappings are used.

  my $html = aa2ht( { 'use-default-colors' => 0 }, $ascii);

Behind the curtains, there is still a mapping: the default mapping to
white.

=head4 colors

You can override color definitions or specify your own.

  my $html = aa2ht( { 'colors' => { '@' => 'ffddee',
                                    'g' => '00ffff' } }, $ascii);

=head4 randomize-new-colors

If set to a true value, letters with no mappings are assigned a
random one.

  my $html = aa2ht( { 'randomize-new-colors' => 1 }, $ascii);

You might want to remove the default mappings if you're really
interested in a completely random effect:

  my $html = aa2ht( { 'use-default-colors' => 0,
                      'randomize-new-colors' => 1 }, $ascii);

You might also want to keep the white space as a white block:

  my $html = aa2ht( { 'use-default-colors' => 0,
                      'colors' => { ' ' => 'ffffff'},
                      'randomize-new-colors' => 1 }, $ascii);

README  view on Meta::CPAN

When the optimization algorithm sees a chance of turning some cells
into a big one, it does so. It always chooses the biggest area
possible for optimizing.

If two different areas suitable for optimization starting from a given
cell are available and both present the same area size, the algorithm
picks the one that maximizes width.

=head4 default color

By default, an unmapped character is mapped to the default color,
which is black.

You can override this color by assigning a different mapping to
"default" with the C<colors> option.

  my $html = aa2ht( { 'colors' => { 'default' => 'ffffff' } }, $ascii);

This, for instance, makes the default color be white, thus making only
the recognized characters show up colored on the table.

=head1 MAPPINGS ( LETTER -> COLOR )

The following letters are mapped to colors in the following way:

   l          000000   # black
   b          0000ff   # blue
   o          a52a2a   # brown
   g          00ff00   # green
   a          bebebe   # gray
   e          bebebe   # grey
   m          ff00ff   # magenta
   o          ffa500   # orange
   p          ffc0cb   # pink

README  view on Meta::CPAN

   A          d3d3d3   # light gray
   E          d3d3d3   # light grey
   M          ff00ff   # light magenta
   O          ffa500   # light orange
   P          ffb6c1   # light pink
   U          9370db   # light purple
   R          cd5c5c   # light red
   W          ffffff   # light white
   Y          ffffe0   # light yellow

Spaces are mapped to white:

              ffffff   # white

By default, everything else is mapped to black

  default     000000   # black

=head1 SEE ALSO

The examples/ directory.

=head1 AUTHOR

Jose Castro, C<< <cog@cpan.org> >>

examples/camel  view on Meta::CPAN

     @camel1hump))&&/\S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if(
     defined($_=shift(@camel1hump))&&/\S/){$camel1hump+=1<<$CAME
     L;;}$camel.=(split(//,"\040..m`{/J\047\134}L^7FX"))[$camel1h
      ump];}$camel.="\n";}@camel1hump=split(/\n/,$camel);foreach(@
      camel1hump){chomp;$Camel=$_;y/LJF7\173\175`\047/\061\062\063\
      064\065\066\067\070/;y/12345678/JL7F\175\173\047`/;$_=reverse;
       print"$_\040$Camel\n";}foreach(@camel1hump){chomp;$Camel=$_;y
        /LJF7\173\175`\047/12345678/;y/12345678/JL7F\175\173\0 47`/;
         $_=reverse;print"\040$_$Camel\n";}';;s/\s*//g;;eval;   eval
           ("seek\040DATA,0,0;");undef$/;$_=<DATA>;s/\s*//g;(   );;s
             ;^.*_;;;map{eval"print\"$_\"";}/.{4}/g; __DATA__   \124
               \1   50\145\040\165\163\145\040\157\1 46\040\1  41\0
                    40\143\141  \155\145\1 54\040\1   51\155\  141
                    \147\145\0  40\151\156 \040\141    \163\16 3\
                     157\143\   151\141\16  4\151\1     57\156
                     \040\167  \151\164\1   50\040\      120\1
                     45\162\   154\040\15    1\163\      040\14
                     1\040\1   64\162\1      41\144       \145\
                     155\14    1\162\       153\04        0\157
                      \146\     040\11     7\047\         122\1
                      45\15      1\154\1  54\171          \040

examples/create_examples  view on Meta::CPAN


for my $person (qw/acme autrijus damian larry merlyn schwern/) {
  _writefile("$person.html",_people(_readfile("$person")));
  $people{$person} = aa2ht({'randomize-new-colors'=>1},_readfile($person));
  $people_opt{$person} = aa2ht({'randomize-new-colors'=>1,'optimization'=>1},_readfile($person));
  _writefile("${person}_opt.html",_people_opt(_readfile("$person")));
}

_writefile('people.html',
           '<table><tr>' .
           (join "\n", map { '<td>' . $people{$_} . '</td>' } sort keys %people) .
           '</tr><tr>' .
           (join "\n", map { "<td><a href=\"$_.html\">$_</a></td>" } sort keys %people) .
           '</tr></table>'
          );

_writefile('people_opt.html',
           '<table><tr>' .
           (join "\n", map { '<td>' . $people_opt{$_} . '</td>' } sort keys %people_opt) .
           '</tr><tr>' .
           (join "\n", map { "<td><a href=\"$_.html\">$_</a></td>" } sort keys %people) .
           '</tr></table>'
          );

# subroutines

sub _readfile { # reads a file
  my $file = shift;
  my $text;
  open (F, $file) or die "could not open $file ($!)\n";
  while (<F>) {

lib/Acme/AsciiArt2HtmlTable.pm  view on Meta::CPAN

  .special tr {  }
  </style>
  <table class="special" cellspacing="0" cellpadding="0" border="0">

=cut

    if (defined $new_config->{'id'}) { $config{'id'} = $new_config->{'id'} }

=head4 use-default-colors

If set to a false value, no default mappings are used.

  my $html = aa2ht( { 'use-default-colors' => 0 }, $ascii);

Behind the curtains, there is still a mapping: the default mapping to
white.

=cut

    if ( defined $new_config->{'use-default-colors'} ) {
      if ( not $new_config->{'use-default-colors'}) {
        $config{'colors'} = { 'default' => 'ffffff' } # everything is now white
      }
    }

lib/Acme/AsciiArt2HtmlTable.pm  view on Meta::CPAN

=cut

    if ( ref($new_config->{'colors'}) eq 'HASH' ) {
      for (keys %{$new_config->{'colors'}}) {
        $config{'colors'}{$_} = $new_config->{'colors'}{$_};
      }
    }

=head4 randomize-new-colors

If set to a true value, letters with no mappings are assigned a
random one.

  my $html = aa2ht( { 'randomize-new-colors' => 1 }, $ascii);

You might want to remove the default mappings if you're really
interested in a completely random effect:

  my $html = aa2ht( { 'use-default-colors' => 0,
                      'randomize-new-colors' => 1 }, $ascii);

You might also want to keep the white space as a white block:

  my $html = aa2ht( { 'use-default-colors' => 0,
                      'colors' => { ' ' => 'ffffff'},
                      'randomize-new-colors' => 1 }, $ascii);

lib/Acme/AsciiArt2HtmlTable.pm  view on Meta::CPAN


    if (defined $new_config->{'optimization'}) {
      $config{'optimization'} = $new_config->{'optimization'};
    }

  }

##############

  # prepare the table, tr and td attributes
  my $table = join ' ', map { "$_=\"$config{'table'}{$_}\"" } sort keys %{$config{'table'}};

  my $tr    = join ' ', map { "$_:$config{'tr'}{$_};"       } sort keys %{$config{'tr'   }};
  my $td    = join ' ', map { "$_:$config{'td'}{$_};"       } sort keys %{$config{'td'   }};

  # our ascii text
  my $text = shift;

  # where we'll store our html
  my $html = '';

  # style (td and tr elements' attributes)
  $html .= "<style>\n" .
           ".$config{'id'} td { $td }\n.$config{'id'} tr { $tr }" .
           "\n</style>\n";

  # table header
  $html .= "<table class=\"$config{'id'}\" $table>\n";

  # prepare the cells
  my @lines = map { [ split //, $_ ] } split /\n/, $text;

  # just to make sure an optimized table has the same width as the normal one
  my $opt_fix = '';
  if ( $config{'optimization'} ) {
    my $width = 0;
    for my $l ( 0 .. $#lines ) {
      if ( $width < $#{$lines[$l]} ) {
        $width = $#{$lines[$l]};
      }
    }

lib/Acme/AsciiArt2HtmlTable.pm  view on Meta::CPAN

    $lines[$line] = join "\n", grep /./, @{$lines[$line]};

    if ($config{'optimization'}) {
      # this is so empty rows aren't ignored by the browser
      $lines[$line] .= "\n<td></td>";
    }

  }

  # the table
  $html .= join "\n", map { "<tr>\n$_\n</tr>" } @lines;

  if ($config{'optimization'}) {
    # this is so empty columns aren't ignored by the browser
    $html .= "$opt_fix";
  }

  # table footer
  $html .= "\n</table>\n";

  # return the table

lib/Acme/AsciiArt2HtmlTable.pm  view on Meta::CPAN

When the optimization algorithm sees a chance of turning some cells
into a big one, it does so. It always chooses the biggest area
possible for optimizing.

If two different areas suitable for optimization starting from a given
cell are available and both present the same area size, the algorithm
picks the one that maximizes width.

=head4 default color

By default, an unmapped character is mapped to the default color,
which is black.

You can override this color by assigning a different mapping to
"default" with the C<colors> option.

  my $html = aa2ht( { 'colors' => { 'default' => 'ffffff' } }, $ascii);

This, for instance, makes the default color be white, thus making only
the recognized characters show up colored on the table.

=head1 MAPPINGS ( LETTER -> COLOR )

The following letters are mapped to colors in the following way:

   l          000000   # black
   b          0000ff   # blue
   o          a52a2a   # brown
   g          00ff00   # green
   a          bebebe   # gray
   e          bebebe   # grey
   m          ff00ff   # magenta
   o          ffa500   # orange
   p          ffc0cb   # pink

lib/Acme/AsciiArt2HtmlTable.pm  view on Meta::CPAN

   A          d3d3d3   # light gray
   E          d3d3d3   # light grey
   M          ff00ff   # light magenta
   O          ffa500   # light orange
   P          ffb6c1   # light pink
   U          9370db   # light purple
   R          cd5c5c   # light red
   W          ffffff   # light white
   Y          ffffe0   # light yellow

Spaces are mapped to white:

              ffffff   # white

By default, everything else is mapped to black

  default     000000   # black

=cut

BEGIN {

  # default configuration
  %default_configuration = (
            id    =>    'default',



( run in 0.950 second using v1.01-cache-2.11-cpan-140bd7fdf52 )