Acme-AsciiArt2HtmlTable

 view release on metacpan or  search on metacpan

examples/create_examples  view on Meta::CPAN

_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>) {
    $text .= $_;
  }
  close F;
  return $text;
}

sub _writefile { # writes a file
  my $filename = shift;
  my $text = shift;
  open (F, ">$filename") or die "could not write $filename ($!)\n";
  print F $text;
  close F;
}

sub _people { # default configuration for big people's heads
  return aa2ht( {'use-default-colors'   => 0,
                'colors'               => { ' '          => 'ffffff' },
                'randomize-new-colors' => 1,
                'table'                =>{ 'cellspacing' => 1,
                                           'colspacing'  => 1,
                                         },
                'td'                   =>{ 'width'       => '4px',
                                           'height'      => '8px'
                                         },
               },
               shift);
}

sub _people_opt { # default configuration for big people's heads, optimized
  return aa2ht( {'use-default-colors'   => 0,
                'colors'               => { ' '          => 'ffffff' },
                'randomize-new-colors' => 1,
                'optimization'         => 1,
                'table'                =>{ 'cellspacing' => 1,
                                           'colspacing'  => 1,
                                         },
                'td'                   =>{ 'width'       => '4px',
                                           'height'      => '8px'
                                         },

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


=item * each letter is a C<td> element

=item * each C<td> has background of a specific color, which is
defined by the letter that created it

=back

=cut

sub aa2ht {

  # default configuration
  my %config = _clone_hash( \%default_configuration );

=head3 OPTIONS

You can pass a reference to a hash before the text you want to
convert.

=cut

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

                        default => '000000', # black
                     },
            'randomize-new-colors' => 0,
            'optimization'         => 0,
          );

}

# subroutines

sub _random_color {
  my $color = '';

  for (1 .. 6) {
    $color .= qw/1 2 3 4 5 6 7 8 9 0 a b c d e f/[int rand 16];
  }

  return $color;
}

sub _clone_hash {
  my %hash = %{+shift};

  my %new_hash;

  for (keys %hash) {
    if (ref($hash{$_})) { 
      $new_hash{$_} = { _clone_hash ( $hash{$_} ) };
    }
    else {
      $new_hash{$_} = $hash{$_};
    }
  }

  return %new_hash;
}

sub _count_in_the_beginning {
  my ($cell, @elems) = @_;
  my $t = 0;
  for (@elems) {
    if ($cell eq $_) {
      $t++;
    }
    else {
      last;
    }
  }
  return $t;
}

sub _min {
  my $min = shift;

  for (@_) {
    if ( $min > $_ ) { $min = $_ }
  }

  return $min;
}

sub _max {
  my $max = shift;

  for (@_) {
    if ( $max < $_ ) { $max = $_ }
  }

  return $max;
}

=head1 SEE ALSO



( run in 0.228 second using v1.01-cache-2.11-cpan-a5abf4f5562 )