Skip to content

Commit

Permalink
Derive location of specification file from template file if not prese…
Browse files Browse the repository at this point in the history
…nt at bootstrap time.
  • Loading branch information
racke committed Mar 11, 2011
1 parent 0957e60 commit d4544be
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/Template/Zoom.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package Template::Zoom;
use strict;
use warnings;

use Template::Zoom::Utils;
use Template::Zoom::Specification::XML;
use Template::Zoom::HTML;

Expand All @@ -41,6 +42,15 @@ sub _bootstrap {
my ($parser_name, $parser_spec, $spec_file, $spec, $template_file, $template_object);

unless ($self->{specification}) {
unless ($self->{specification_file}) {
# try to derive specification file name from template file name
$self->{specification_file} = Template::Zoom::Utils::derive_filename($self->{template_file}, '.xml');

unless (-f $self->{specification_file}) {
die "Missing Template::Zoom specification for template $self->{template_file}\n";
}
}

if ($parser_name = $self->{specification_parser}) {
# load parser class
my $class;
Expand Down Expand Up @@ -75,7 +85,7 @@ sub _bootstrap {
}
}
else {
die "$0: Missing Template::Zoom specification.\n";
die "$0: Missing Template::Zoom specification, template: $self->{template_file}.\n";
}
}

Expand Down
37 changes: 37 additions & 0 deletions lib/Template/Zoom/Utils.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Template::Zoom::Utils - Template::Zoom utility functions
#
# Copyright (C) 2010-2011 Stefan Hornburg (Racke) <[email protected]>.
#
# 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 Template::Zoom::Utils;

use strict;
use warnings;

use File::Basename;
use File::Spec;

sub derive_filename {
my ($orig_filename, $suffix) = @_;
my ($orig_dir, @frags);

@frags = fileparse($orig_filename, qr/\.[^.]*/);

return $frags[1] . $frags[0] . $suffix;
}

1;

0 comments on commit d4544be

Please sign in to comment.