| 1 | # -*- perl -*- | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | # $Id: PrintTemplates.pm,v 1.1 2005/01/29 16:48:12 eserte Exp $ | ||||||||||||||||||||
| 5 | # Author: Slaven Rezic | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # Copyright (C) 2005 Slaven Rezic. All rights reserved. | ||||||||||||||||||||
| 8 | # This package is free software; you can redistribute it and/or | ||||||||||||||||||||
| 9 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 10 | # | ||||||||||||||||||||
| 11 | # Mail: eserte@users.sourceforge.net | ||||||||||||||||||||
| 12 | # WWW: http://www.sourceforge.net/projects/we-framework | ||||||||||||||||||||
| 13 | # | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | package WebEditor::OldFeatures::PrintTemplates; | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | WebEditor::OldFeatures::PrintTemplates - additionally process print templates | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | Add the method makehtmlpage_print_templates to | ||||||||||||||||||||
| 26 | L<WebEditor::OldController>. This method is normally accessed as the | ||||||||||||||||||||
| 27 | C<print_templates> hook in the C<makehtmlhook> feature, see | ||||||||||||||||||||
| 28 | L<configuration.pod>. | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 AUTHOR | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | Slaven Rezic. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | ▶ | use mixin::with 'WebEditor::OldController'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # add mixin'ed methods here | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub makehtmlpage_print_templates { | ||||||||||||||||||
|
Subroutine
makehtmlpage_print_templates: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | my $root = $self->Root; | |||||||||||||||||||
| 48 | 0 | my $objdb = $root->ObjDB; | |||||||||||||||||||
| 49 | 0 | my $c = $self->C; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | my(%args) = @_; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | my $lang = $args{lang} || $c->project->sitelanguages->[0]; | ||||||||||||||||||
|
Condition0%0/3
$args{'lang'} || $c->project->sitelanguages->[0]
MC/DC0%0/2
$args{'lang'} || $c->project->sitelanguages->[0]
$args{'lang'}
$c->project->sitelanguages->[0]
Truth table0%0/3
A || B
A= $args{'lang'}B= $c->project->sitelanguages->[0]
| |||||||||||||||||||||
| 54 | 0 | ▶ | my $basedir = $args{basedir} || $c->paths->pubhtmldir; | ||||||||||||||||||
|
Condition0%0/3
$args{'basedir'} || $c->paths->pubhtmldir
MC/DC0%0/2
$args{'basedir'} || $c->paths->pubhtmldir
$args{'basedir'}
$c->paths->pubhtmldir
Truth table0%0/3
A || B
A= $args{'basedir'}B= $c->paths->pubhtmldir
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | my($id, $mainid, $template, $addtemplatevars) = | ||||||||||||||||||||
| 57 | 0 | @args{qw(id mainid template addtemplatevars)}; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | my $msg = ""; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # gibt es von diesem Template noch ein Print-Template? | ||||||||||||||||||||
| 62 | # dann nochmal die Print-Version erzeugen: | ||||||||||||||||||||
| 63 | 0 | my $printtemplate = $template; | |||||||||||||||||||
| 64 | 0 | $printtemplate =~ s/\.tpl\.html$/_p\.tpl\.html/; | |||||||||||||||||||
| 65 | 0 | ▶ | if (-e $c->paths->site_templatebase."/$printtemplate") { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | $msg .= "$printtemplate --- "; | |||||||||||||||||||
| 67 | 0 | require File::Compare; | |||||||||||||||||||
| 68 | 0 | my $phtmlfile = $basedir."/html/".$lang."/".$mainid."_p.html"; | |||||||||||||||||||
| 69 | 0 | $msg .= "$phtmlfile --- "; | |||||||||||||||||||
| 70 | 0 | my $tmpfile = "$phtmlfile~"; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | my $converter = $self->get_fh_charset_converter; | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | ▶ | open(HTML, ">$tmpfile") or die("Publish: can't write to $tmpfile: $!"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 0 | $converter->(\*HTML); | |||||||||||||||||||
| 76 | 0 | $self->_tpl("site", $printtemplate, $addtemplatevars, \*HTML); | |||||||||||||||||||
| 77 | 0 | close HTML; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | if (File::Compare::compare($phtmlfile, $tmpfile) == 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | # no change --- delete $tmpfile | ||||||||||||||||||||
| 81 | 0 | unlink $tmpfile; | |||||||||||||||||||
| 82 | 0 | $msg .= " ($lang: keine Änderung) "; | |||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||
| 84 | 0 | unlink $phtmlfile; # do not fail --- maybe file does not exist | |||||||||||||||||||
| 85 | 0 | ▶ | rename $tmpfile, $phtmlfile or die "Can't rename $tmpfile to $phtmlfile: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | return { Message => $msg }; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 1 | 1; | |||||||||||||||||||