App-Plog

 view release on metacpan or  search on metacpan

lib/App/Plog.pm  view on Meta::CPAN

}

#-------------------------------------------------------------------------------

sub render
{

=head2 render($self, $blog_directory, $temporary_directory, $version, $commit, $text, $date)

I<Arguments>

=over 2 

=item * $self - 

=item * $blog_directory - the path to the blog directory

=item * $temporary_directory - directory where temporary data can be saved

=item * $version - number - the version  of the blog entry

=item * $commit - the commit id of the blog entry

=item * $text - the text of the entry as it was found by the version control system

=item * $date - string in format "2009-10-05 14:53:24 +0200"

=back

I<Returns> - the pod text rendered to HTML

I<Exceptions> - None

=cut

my ($self, $blog_directory, $temporary_directory, $version, $commit, $text, $date) = @_ ;

open my $input, '<', \$text or croak q{Error: Can't redirect from scalar};
open my $output, '>', \my $html or croak q{Error: Can't redirect to scalar} ;

my $parser = Pod::Simple::HTML->new();
$parser->index(0);
$parser->html_css($self->{css}) ;

$parser->output_fh($output);
$parser->parse_file($input);

my $date_html = $self->get_entry_date_html($date) ;

my $version_html = $version > 1 ? "<br> version: $version" : $EMPTY_STRING ;

my $entry_html = 'Error: App::Plog::Renderer::HTML::Pod found no pod!' ;

if(defined $html && $html =~ m{^.*\Q<!-- start doc -->\E(.*)\Q<!-- end doc -->}xsm)
	{
	$entry_html = $1 ;
	}

$entry_html = <<"EOE" ;
        <tr>
          <td width="100" valign="top"> <font size="1"> <br> $date_html $version_html </td>
 	  <td></td>
         <td width="540"> 
	  	  <a name = '$commit'> </a>
	          $entry_html 
	  </td>
        </tr>
        <td><hr></td><td><hr></td><td><hr></td>

EOE

return $entry_html ;
}

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------

package App::Plog::Renderer::HTML::Asciidoc ;

use base 'App::Plog::Renderer::HTML';

=head1 App::Plog::Renderer::HTML::Asciidoc SUBROUTINES/METHODS

=cut

use strict;
use warnings ;
use Carp qw(carp croak confess) ;
use FileHandle;
use English qw( -no_match_vars ) ;
use IPC::Open2 ;

sub new
{

=head2 new(\%options)

I<Arguments>

=over 2 

=item * \%options - the section from the blog configuration file where a  App::Plog::Renderer::HTML::Asciidoc object was required

=back

I<Returns> - an App::Plog::Renderer::HTML::Asciidoc object

I<Exceptions> -None

=cut

my ($invocant, $options) = @_ ;

my $class = ref($invocant) || $invocant ;
confess 'Invalid constructor call!' unless defined $class ;

my $ascii_doc_version = `asciidoc --version` ;
unless($ascii_doc_version =~ s/^.*(asciidoc \d\.\d.*)/$1/)
	{
	$ascii_doc_version = undef ;
	}

my $object = {%{$options}, ascii_doc_version => $ascii_doc_version} ;

return bless $object, $class ;
}

#-------------------------------------------------------------------------------

sub render
{

=head2 render($self, $blog_directory, $temporary_directory, $version, $commit, $text, $date)

I<Arguments>

=over 2 

=item * $self - 

=item * $blog_directory - the path to the blog directory

=item * $temporary_directory - directory where temporary data can be saved

=item * $version - number - the version  of the blog entry

=item * $commit - the commit id of the blog entry

=item * $text - the text of the entry as it was found by the version control system

=item * $date - string in format "2009-10-05 14:53:24 +0200"

=back

I<Returns> - the asciidoc text rendered to HTML

I<Exceptions> - None

=cut

my ($self, $blog_directory, $temporary_directory, $version, $commit, $text, $date) = @_ ;

my $date_html = $self->get_entry_date_html($date) ;

my $version_html = $version > 1 ? "<br> version: $version" : $EMPTY_STRING ;

my ($entry_html, $reader, $writer) = (q{Error: App::Plog::Renderer::HTML::Asciidoc can't run command 'asciidoc'!}) ;

if (defined $self->{ascii_doc_version})
	{
	my $pid = open2($reader, $writer, 'asciidoc -o - -s -' );

	local $INPUT_RECORD_SEPARATOR = undef ;
	print {$writer} $text ; close $writer ;
	$entry_html = <$reader>; close $reader ;
	}

	$entry_html = <<"EOE" ;
	<tr>
	  <td width="100" valign="top"> <font size="1"> <br> $date_html $version_html </td>
	  <td></td>
	  <td width="540"> 
		  <a name = '$commit'> </a>
		  $entry_html 
	  </td>
	</tr>
	<td><hr></td><td><hr></td><td><hr></td>

EOE
	
return $entry_html ;
}

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------

package App::Plog::Aggregator::Template::Inline ;

=head1 App::Plog::Aggregator::Template::Inline SUBROUTINES/METHODS

=cut

use strict;
use warnings ;
use Carp qw(carp croak confess) ;
use File::Slurp ;

sub new
{

=head2 new(\%options)

I<Arguments>

=over 2 

=item * \%options - the B<aggregator> section from the blog configuration file

=back

I<Returns> - an App::Plog::Aggregator::Template::Inline object

I<Exceptions> -None

=cut

my ($invocant, $options) = @_ ;

my $class = ref($invocant) || $invocant ;
confess 'Invalid constructor call!' unless defined $class ;

my $object = {%{$options}} ;

return bless $object, $class ;
}

#-------------------------------------------------------------------------------

sub aggregate
{



( run in 1.817 second using v1.01-cache-2.11-cpan-ceb78f64989 )