App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Output/LaTeX.pm view on Meta::CPAN
$gcfg = $::config->{latex};
$gtemplate = Template->new
({ INCLUDE_PATH => [@{$gcfg->{template_include_path}},
CP->findres("templates"), $CHORDPRO_LIBRARY],
INTERPOLATE => 1,
}) || die "$Template::ERROR\n";
foreach my $song ( @{$sb->{songs}} ) {
push( @songs, generate_song($song) );
}
my $songbook = '';
my %vars = ();
$vars{songs} = [@songs] ;
$gtemplate->process($gcfg->{templates}->{songbook}, \%vars, $::options->{output} )
|| die $gtemplate->error();
# i like it more to handle output through template module - but its possible to result it as array.
# return split(/\n/, $songbook);
$::options->{output} = '-';
return [];
}
# some not implemented feature is requested. will be removed.
sub line_default {
my ( $lineobject, $ref_lineobjects ) = @_;
return "";
}
$line_routines{line_default} = \&line_default;
sub get_firstphrase{
my ( $elts ) = @_; # reference to array
my $line = "";
foreach my $elt (@{ $elts }) {
if($elt->{type} eq 'songline'){
foreach my $phrase (@{$elt->{phrases}}){
$line .= $phrase;
}
return my_latex_encode($line);
}
}
}
sub line_songline {
my ( $lineobject ) = @_;
my $index = 0;
my $line = "";
my $chord = "";
my $has_chord = 0;
foreach my $phrase (@{$lineobject->{phrases}}){
if(defined $lineobject->{chords}){
if (@{$lineobject->{chords}}[$index] ne '' ){
$chord = $gchordstart_tag.@{$lineobject->{chords}}[$index]->key .$gchordend_tag; #songbook format \\[chord]
$has_chord = 1;
}}
$line .= $chord . latex_encode($phrase);
$index += 1;
$chord = "";
}
my $empty = $line;
my $textline = $line;
my $nbsp = $start_spaces_songline; #unicode for nbsp sign # start_spaces_songline
if($empty =~ /^\s+/){ # starts with spaces
$empty =~ s/^(\s+).*$/$1/; # not the elegant solution - but working - replace all spaces in the beginning of a line
my $replaces = $empty; #with a nbsp symbol as the intend tend to be intentional
$replaces =~ s/\s+/$nbsp/g;
$textline =~ s/$empty/$replaces/;
}
$line = $textline;
if ($has_chord) { $line = $chorded_line . $line; } else { $line = $unchorded_line . $line; }
return $line.$eol;
}
$line_routines{line_songline} = \&line_songline;
sub line_newpage {
my ( $lineobject ) = @_;
return $newpage_tag;
}
$line_routines{line_newpage} = \&line_newpage;
sub line_empty {
my ( $lineobject ) = @_;
return $emptyline_tag;
}
$line_routines{line_empty} = \&line_empty;
sub line_comment {
my ( $lineobject ) = @_; # Template for comment?
my $vars = {
comment => latex_encode($lineobject->{text})
};
my $comment = '';
$gtemplate->process($gcfg->{templates}->{comment}, $vars, \$comment) || die $gtemplate->error();
return $comment ;
}
$line_routines{line_comment} = \&line_comment;
sub line_comment_italic {
my ( $lineobject ) = @_; # Template for comment?
my $vars = {
comment => "\\textit{". latex_encode($lineobject->{text}) ."}"
};
my $comment = '';
$gtemplate->process($gcfg->{templates}->{comment}, $vars, \$comment) || die $gtemplate->error();
return $comment;
}
$line_routines{line_comment_italic} = \&line_comment_italic;
sub line_image {
my ( $lineobject ) = @_;
my $image = '';
$gtemplate->process($gcfg->{templates}->{image}, $lineobject, \$image)|| die $gtemplate->error();
return $image;
}
$line_routines{line_image} = \&line_image;
sub line_colb {
my ( $lineobject ) = @_; # Template for comment?
return $columnbreak_tag;
}
$line_routines{line_colb} = \&line_colb;
( run in 0.786 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )