Skip to content

Instantly share code, notes, and snippets.

@tokubass
Last active December 14, 2015 18:28
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tokubass/5129241 to your computer and use it in GitHub Desktop.
xslate行数調整
#!/usr/bin/env perl
use strict;
use warnings;
use Text::Xslate;
use IO::All;
my $tx = Text::Xslate->new(
syntax => 'TTerse',
verbose => 2,
header => [qw/header.inc/],
footer => [qw/footer.inc/],
macro => [qw/macro.inc/],
);
$tx->{warn_handler} = sub {
my @macro = @{ $tx->{macro} || [] };
my @header = @{ $tx->{header} || [] };
my $line_num;
my $base_path = $tx->{path}->[0];
for my $mh (@macro,@header) {
$line_num += io("${base_path}/${mh}")->getlines;
}
for (@_) {
if (m/\(([^:]+):(\d+)\) at/) {
chomp;
$_ = sprintf("%s adjusted line number: (%s:%s)", $_, $1, $2-$line_num);
}
}
Text::Xslate->note( @_ );
};
my %vars = (
title => 'A list of books',
books => [{
title => 'Islands in the stream'
},{
title => 'Programming Perl'
}],
);
my $template = q{
[% INCLUDE 'include.inc' -%]
[% FOR book IN books -%]
[% book.hogeee # warning %]
[% END -%]
};
print $tx->render_string($template, \%vars);
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment