Skip to content

Commit

Permalink
Add Vend::PDF module which provides [pdf] tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
racke committed Dec 16, 2010
1 parent e25154d commit 8b84e15
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions lib/Vend/PDF.pm
@@ -0,0 +1,103 @@
# Vend::PDF - PDF generation for Interchange
#
# Copyright (C) 2010 Stefan Hornburg (Racke) <racke@linuxia.de>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

package Vend::PDF;

use Template::Zoom::Specification::XML;
use Template::Zoom::HTML;
use Template::Zoom::Database::Rose;
use Template::Zoom::Style::CSS;
use Template::Zoom;
use Template::Zoom::PDF;

use Vend::Config;
use Vend::Data;

# define [pdf] tag
Vend::Config::parse_tag('UserTag', 'pdf Order specification template output');
Vend::Config::parse_tag('UserTag', 'pdf AddAttr');
Vend::Config::parse_tag('UserTag', 'pdf MapRoutine Vend::PDF::pdf');

# [pdf]
sub pdf {
my ($specification, $template, $output, $opt) = @_;
my (%input);

# input for Zoom template
if (exists $opt->{input}) {
%input = %{$opt->{input}};
}

# parse specification file
my ($xml_spec, $spec);

$xml_spec = new Template::Zoom::Specification::XML;

unless ($spec = $xml_spec->parse_file($specification)) {
die "$0: error parsing $xml_file: " . $xml_spec->error() . "\n";
}

# parse template
my ($html_object);

$html_object = new Template::Zoom::HTML;

$html_object->parse_template($template, $spec);

for $list_object ($html_object->lists()) {
# seed and check input
$list_object->input(\%input);
}

for $form_object ($html_object->forms()) {
# seed and check input
$form_object->input(\%input);
}

# create database object
my ($rose);

$rose = new Template::Zoom::Database::Rose(dbh => database_exists_ref('products')->dbh());

# create CSS object
my ($css);

$css = new Template::Zoom::Style::CSS (template => $html_object);

# create Template::Zoom object and process template
my ($zoom);

$zoom = new Template::Zoom (template => $html_object,
database => $rose,
values => $opt->{values},
);

$zoom->process();

# finally generate PDF
my ($pdf);

$pdf = new Template::Zoom::PDF (template => $html_object);

$pdf->process($output);

return;
}

1;

0 comments on commit 8b84e15

Please sign in to comment.