CGI-Application-Plugin-HtmlTidy

 view release on metacpan or  search on metacpan

lib/CGI/Application/Plugin/HtmlTidy.pm  view on Meta::CPAN

use HTML::Tidy 1.08;

require Exporter;
our @ISA = qw(Exporter);

our @EXPORT = qw(htmltidy htmltidy_clean htmltidy_config);

sub import
{
    my $c = scalar caller;
    $c->add_callback( 'devpopup_report', \&htmltidy_validate ) if $c->can('devpopup');
    goto &Exporter::import;
}

sub htmltidy
{
    my $self = shift;
    my $opts = $self->param('htmltidy_config') || {};
    htmltidy_config( $self, %$opts ) unless $self->{ __PACKAGE__ . 'OPTIONS' };
    $self->{ __PACKAGE__ . 'HTMLTIDY' } ||= HTML::Tidy->new( $self->{ __PACKAGE__ . 'OPTIONS' } );
}

lib/CGI/Application/Plugin/HtmlTidy.pm  view on Meta::CPAN

            push @{ $output[ $_->line - 1 ]->{messages} },
              {
                type => $_->type == TIDY_WARNING ? 'warning' : 'error',
                line => $_->line,
                column => $_->column,
                text   => $_->text,
              };
        }
        my $t = HTML::Template->new( filename => __find_my_path() . '/validate.tmpl', die_on_bad_params => 0, cache => 1 );
        $t->param( output => \@output );
        $self->devpopup->add_report(
            title   => 'HTML::Tidy validation report',
            summary => "$errors errors, $warnings warnings",
            report  => $t->output
        );
    }
    else
    {
        $self->devpopup->add_report(
            title   => 'HTML::Tidy validation report',
            summary => "Your HTML is valid!",
        );
    }
}

sub __check_header
{
    my $self = shift;

t/07tmpl_load.t  view on Meta::CPAN

    $ENV{CAP_DEVPOPUP_EXEC} = 1;
    require TemplateApp;
    my $app = TemplateApp->new(PARAMS=> {
                    htmltidy_config => {
                        config_file => './t/tidy.conf',
                    }
            });
    $app->start_mode('non_html');
    my $out = eval { return $app->run; };

    unlike($@, qr/Error executing class callback in devpopup_report stage: HTML::Template/, 'template loaded ok');
}

__END__
t/07tmpl_load....1..1
ok 1 - template loaded ok
ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.09 cusr +  0.00 csys =  0.09 CPU)



( run in 2.192 seconds using v1.01-cache-2.11-cpan-364913b4093 )