File Coverage

blib/lib/WebEditor/OldFeatures/PrintTemplates.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 8 0.0
condition 0 6 0.0
subroutine 3 4 75.0
pod 0 1 0.0
total 12 56 21.4


line stmt bran cond sub pod time code
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. This method is normally accessed as the
27             C hook in the C feature, see
28             L.
29              
30             =head1 AUTHOR
31              
32             Slaven Rezic.
33              
34             =cut
35              
36 1     1   1197 use strict;
  1         2  
  1         32  
37 1     1   5 use vars qw($VERSION);
  1         2  
  1         67  
38             $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
39              
40 1     1   5 use mixin::with 'WebEditor::OldController';
  1         2  
  1         6  
41              
42             # add mixin'ed methods here
43              
44             sub makehtmlpage_print_templates {
45 0     0 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   0       my $lang = $args{lang} || $c->project->sitelanguages->[0];
54 0   0       my $basedir = $args{basedir} || $c->paths->pubhtmldir;
55              
56 0           my($id, $mainid, $template, $addtemplatevars) =
57             @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 0         if (-e $c->paths->site_templatebase."/$printtemplate") {
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 0         open(HTML, ">$tmpfile") or die("Publish: can't write to $tmpfile: $!");
75 0           $converter->(\*HTML);
76 0           $self->_tpl("site", $printtemplate, $addtemplatevars, \*HTML);
77 0           close HTML;
78              
79 0 0         if (File::Compare::compare($phtmlfile, $tmpfile) == 0) {
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 0         rename $tmpfile, $phtmlfile or die "Can't rename $tmpfile to $phtmlfile: $!";
86             }
87              
88             }
89              
90 0           return { Message => $msg };
91             }
92              
93             1;