Last active
December 14, 2015 18:28
-
-
Save tokubass/5129241 to your computer and use it in GitHub Desktop.
xslate行数調整
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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