Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37834463
en ru br
Репозитории ALT

Группа :: Разработка/Perl
Пакет: perl-Text-Xslate-Bridge-TT2Like

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

pax_global_header00006660000000000000000000000064116343045510014514gustar00rootroot0000000000000052 comment=465f9fb60af0d8bef348767894d61863e8ff1d31
perl-Text-Xslate-Bridge-TT2Like-0.00010/000075500000000000000000000000001163430455100174025ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/.gitignore000064400000000000000000000000161163430455100213670ustar00rootroot00000000000000inc/
Makefile
perl-Text-Xslate-Bridge-TT2Like-0.00010/Changes000064400000000000000000000032101163430455100206710ustar00rootroot00000000000000Changes
=======

0.00010 - 15 Sep 2011
* Release solely to fix this Change log
* Require Text::Xsate 1.3000 (suggested by nihen)
* Changes that went in 0.0009, but had completely escaped my memory:
* These filters now *ESCAPE* html before doing their magic
html_para
html_break
html_para_break
html_line_break

0.00009 - 15 Sep 2011
* XXX INITIALLY THIS RELEASE WAS DESCRIVED AS "NO CHANGES", BUT
THERE WERE CHANGES. SEE 0.00010 ABOVE
* Add t/005_xss.t to validate we're safe from potential xss attacks
[https://github.com/lestrrat/Text-Xslate-Bridge-TT2Like/pull/1] (gfx)

0.00008 - 11 May 2011
* Now html_* and xml filters return strings that are prorperly
marked as raw via Text::Xslate::html_builder()
(http://cpanbook.koneta.org/post/5361569358)

0.00007 - 4 Sep 2010
* Grrrr, fight against PAUSE indexer.
* No code changes

0.00006 - 3 Sep 2010
* Rename the functions so that they are private
* Split up the .pm file and the .pod file so I can auto-generate
the list of functions that are available.
(request for the list of functions by gfx)
* Add pod tests

0.00005 - 9 Aug 2010
* Add truncate() filter.

0.00004 - 1 Aug 2010
* Update Text::Xslate dependency
* Remove uri() which is a builtin filter since Xslate 0.1052 (gfx)
* Use uri_escape from Xslate 0.1052 as the background for url filter (gfx)

0.00003 - 19 Jul 2010
* Add dynamic filter support (tokuhirom)

0.00002 - 19 Jul 2010
* Add filter support (tokuhirom)
* Update Text::Xslate dependency

0.00001 - 09 Jun 2010
* Initial release
perl-Text-Xslate-Bridge-TT2Like-0.00010/Makefile.PL000064400000000000000000000024021163430455100213520ustar00rootroot00000000000000use inc::Module::Install;

name 'Text-Xslate-Bridge-TT2Like';
all_from 'lib/Text/Xslate/Bridge/TT2Like.pm';

requires 'Text::Xslate' => '1.3000';
requires 'Scalar::Util';
author_tests 'xt';

no_index 'directory' => 'src';
WriteAll;

if ($Module::Install::AUTHOR) {
warn "Author mode, auto generating pod";

open my $fh, '<', File::Spec->catfile('lib', 'Text', 'Xslate', 'Bridge', 'TT2Like.pm' ) or
die "Could not open file : $!";

my $currkey;
my %sections;
while ( <$fh> ) {
next unless /^__PACKAGE__->bridge\(/;
while ( <$fh> ) {
last if /^\)$/;
if (/^\s+(\w+)\s+=>\s+{/) {
$currkey = $1;
$sections{ $currkey } = [];
} elsif ( /^\s+(\w+)\s+=>/ ) {
push @{ $sections{ $currkey } }, $1;
}
}
}

require Text::Xslate;
my $xslate = Text::Xslate->new(
syntax => 'TTerse',
path => 'src'
);
my $string = $xslate->render( 'TT2Like.tx', {
sections => \%sections,
names => [ sort keys %sections ],
} );
open my $pod, '>', File::Spec->catfile('lib', 'Text', 'Xslate', 'Bridge', 'TT2Like.pod' ) or
die "Could not open file: $!";

print $pod $string;
close $pod;
}
perl-Text-Xslate-Bridge-TT2Like-0.00010/lib/000075500000000000000000000000001163430455100201505ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/lib/Text/000075500000000000000000000000001163430455100210745ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/lib/Text/Xslate/000075500000000000000000000000001163430455100223345ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/lib/Text/Xslate/Bridge/000075500000000000000000000000001163430455100235305ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/lib/Text/Xslate/Bridge/TT2Like.pm000064400000000000000000000357131163430455100253150ustar00rootroot00000000000000package Text::Xslate::Bridge::TT2Like;
use 5.008001;
use strict;
use warnings;
use base qw(Text::Xslate::Bridge);

our $VERSION = '0.00010';

use Scalar::Util 'blessed';
use Text::Xslate;

our $TRUNCATE_LENGTH = 32;
our $TRUNCATE_ADDON = '...';

__PACKAGE__->bridge(
scalar => {
item => \&_text_item,
list => \&_text_list,
hash => \&_text_hash,
length => \&_text_length,
size => \&_text_size,
defined => \&_text_defined,
match => \&_text_match,
search => \&_text_search,
repeat => \&_text_repeat,
replace => \&_text_replace,
remove => \&_text_remove,
split => \&_text_split,
chunk => \&_text_chunk,
substr => \&_text_substr,
},
hash => {
item => \&_hash_item,
hash => \&_hash_hash,
size => \&_hash_size,
each => \&_hash_each,
keys => \&_hash_keys,
values => \&_hash_values,
items => \&_hash_items,
pairs => \&_hash_pairs,
list => \&_hash_list,
exists => \&_hash_exists,
defined => \&_hash_defined,
delete => \&_hash_delete,
import => \&_hash_import,
sort => \&_hash_sort,
nsort => \&_hash_nsort,
},
array => {
item => \&_list_item,
list => \&_list_list,
hash => \&_list_hash,
push => \&_list_push,
pop => \&_list_pop,
unshift => \&_list_unshift,
shift => \&_list_shift,
max => \&_list_max,
size => \&_list_size,
defined => \&_list_defined,
first => \&_list_first,
last => \&_list_last,
reverse => \&_list_reverse,
grep => \&_list_grep,
join => \&_list_join,
sort => \&_list_sort,
nsort => \&_list_nsort,
unique => \&_list_unique,
import => \&_list_import,
merge => \&_list_merge,
slice => \&_list_slice,
splice => \&_list_splice,
},
function => {
# 'html' => \&_html_filter, # Xslate has builtin filter for html escape, and it is not overridable.
html_para => Text::Xslate::html_builder(\&_html_paragraph),
html_break => Text::Xslate::html_builder(\&_html_para_break),
html_para_break => Text::Xslate::html_builder(\&_html_para_break),
html_line_break => Text::Xslate::html_builder(\&_html_line_break),
xml => Text::Xslate::html_builder(\&_xml_filter),
# 'uri' => \&uri_escape, # builtin from version 0.1052
url => \&Text::Xslate::uri_escape,
upper => sub { uc $_[0] },
lower => sub { lc $_[0] },
ucfirst => sub { ucfirst $_[0] },
lcfirst => sub { lcfirst $_[0] },
# 'stderr' => sub { print STDERR @_; return '' }, # anyone want this??
trim => sub { for ($_[0]) { s/^\s+//; s/\s+$// }; $_[0] },
null => sub { return '' },
collapse => sub { for ($_[0]) { s/^\s+//; s/\s+$//; s/\s+/ /g };
$_[0] },
indent => \&_indent_filter_factory,
format => \&_format_filter_factory,
truncate => \&_truncate_filter_factory,
repeat => \&_repeat_filter_factory,
replace => \&_replace_filter_factory,
remove => \&_remove_filter_factory,
},
);

sub _text_item {
$_[0];
}

sub _text_list {
[ $_[0] ];
}

sub _text_hash {
{ value => $_[0] };
}

sub _text_length {
length $_[0];
}

sub _text_size {
return 1;
}

sub _text_defined {
return 1;
}

sub _text_match {
my ($str, $search, $global) = @_;
return $str unless defined $str and defined $search;
my @matches = $global ? ($str =~ /$search/g)
: ($str =~ /$search/);
return @matches ? \@matches : '';
}

sub _text_search {
my ($str, $pattern) = @_;
return $str unless defined $str and defined $pattern;
return $str =~ /$pattern/;
}

sub _text_repeat {
my ($str, $count) = @_;
$str = '' unless defined $str;
return '' unless $count;
$count ||= 1;
return $str x $count;
}

sub _text_replace {
my ($text, $pattern, $replace, $global) = @_;
$text = '' unless defined $text;
$pattern = '' unless defined $pattern;
$replace = '' unless defined $replace;
$global = 1 unless defined $global;

if ($replace =~ /\$\d+/) {
# replacement string may contain backrefs
my $expand = sub {
my ($chunk, $start, $end) = @_;
$chunk =~ s{ \\(\\|\$) | \$ (\d+) }{
$1 ? $1
: ($2 > $#$start || $2 == 0) ? ''
: substr($text, $start->[$2], $end->[$2] - $start->[$2]);
}exg;
$chunk;
};
if ($global) {
$text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }eg;
}
else {
$text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }e;
}
}
else {
if ($global) {
$text =~ s/$pattern/$replace/g;
}
else {
$text =~ s/$pattern/$replace/;
}
}
return $text;
}

sub _text_remove {
my ($str, $search) = @_;
return $str unless defined $str and defined $search;
$str =~ s/$search//g;
return $str;
}

sub _text_split {
my ($str, $split, $limit) = @_;
$str = '' unless defined $str;

# we have to be very careful about spelling out each possible
# combination of arguments because split() is very sensitive
# to them, for example C<split(' ', ...)> behaves differently
# to C<$space=' '; split($space, ...)>

if (defined $limit) {
return [ defined $split
? split($split, $str, $limit)
: split(' ', $str, $limit) ];
}
else {
return [ defined $split
? split($split, $str)
: split(' ', $str) ];
}
}

sub _text_chunk {
my ($string, $size) = @_;
my @list;
$size ||= 1;
if ($size < 0) {
# sexeger! It's faster to reverse the string, search
# it from the front and then reverse the output than to
# search it from the end, believe it nor not!
$string = reverse $string;
$size = -$size;
unshift(@list, scalar reverse $1)
while ($string =~ /((.{$size})|(.+))/g);
}
else {
push(@list, $1) while ($string =~ /((.{$size})|(.+))/g);
}
return \@list;
}

sub _text_substr {
my ($text, $offset, $length, $replacement) = @_;
$offset ||= 0;

if(defined $length) {
if (defined $replacement) {
substr( $text, $offset, $length, $replacement );
return $text;
}
else {
return substr( $text, $offset, $length );
}
}
else {
return substr( $text, $offset );
}
}

sub _hash_item {
my ($hash, $item) = @_;
$item = '' unless defined $item;
$hash->{ $item };
}

sub _hash_hash {
$_[0];
}

sub _hash_size {
scalar keys %{$_[0]};
}

sub _hash_each {
# this will be changed in TT3 to do what hash_pairs() does
[ %{ $_[0] } ];
}

sub _hash_keys {
[ keys %{ $_[0] } ];
}

sub _hash_values {
[ values %{ $_[0] } ];
}

sub _hash_items {
[ %{ $_[0] } ];
}

sub _hash_pairs {
[ map {
{ key => $_ , value => $_[0]->{ $_ } }
}
sort keys %{ $_[0] }
];
}

sub _hash_list {
my ($hash, $what) = @_;
$what ||= '';
return ($what eq 'keys') ? [ keys %$hash ]
: ($what eq 'values') ? [ values %$hash ]
: ($what eq 'each') ? [ %$hash ]
: # for now we do what pairs does but this will be changed
# in TT3 to return [ $hash ] by default
[ map { { key => $_ , value => $hash->{ $_ } } }
sort keys %$hash
];
}

sub _hash_exists {
exists $_[0]->{ $_[1] };
}

sub _hash_defined {
# return the item requested, or 1 if no argument
# to indicate that the hash itself is defined
my $hash = shift;
return @_ ? defined $hash->{ $_[0] } : 1;
}

sub _hash_delete {
my $hash = shift;
delete $hash->{ $_ } for @_;
}

sub _hash_import {
my ($hash, $imp) = @_;
$imp = {} unless ref $imp eq 'HASH';
@$hash{ keys %$imp } = values %$imp;
return '';
}

sub _hash_sort {
my ($hash) = @_;
[ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash) ];
}

sub _hash_nsort {
my ($hash) = @_;
[ sort { $hash->{$a} <=> $hash->{$b} } (keys %$hash) ];
}

sub _list_item {
$_[0]->[ $_[1] || 0 ];
}

sub _list_list {
$_[0];
}

sub _list_hash {
my $list = shift;
if (@_) {
my $n = shift || 0;
return { map { ($n++, $_) } @$list };
}
no warnings;
return { @$list };
}

sub _list_push {
my $list = shift;
push(@$list, @_);
return '';
}

sub _list_pop {
my $list = shift;
pop(@$list);
}

sub _list_unshift {
my $list = shift;
unshift(@$list, @_);
return '';
}

sub _list_shift {
my $list = shift;
shift(@$list);
}

sub _list_max {
no warnings;
my $list = shift;
$#$list;
}

sub _list_size {
no warnings;
my $list = shift;
$#$list + 1;
}

sub _list_defined {
# return the item requested, or 1 if no argument to
# indicate that the hash itself is defined
my $list = shift;
return @_ ? defined $list->[$_[0]] : 1;
}

sub _list_first {
my $list = shift;
return $list->[0] unless @_;
return [ @$list[0..$_[0]-1] ];
}

sub _list_last {
my $list = shift;
return $list->[-1] unless @_;
return [ @$list[-$_[0]..-1] ];
}

sub _list_reverse {
my $list = shift;
[ reverse @$list ];
}

sub _list_grep {
my ($list, $pattern) = @_;
$pattern ||= '';
return [ grep /$pattern/, @$list ];
}

sub _list_join {
my ($list, $joint) = @_;
join(defined $joint ? $joint : ' ',
map { defined $_ ? $_ : '' } @$list);
}

sub _list_sort_make_key {
my ($item, $fields) = @_;
my @keys;

if (ref($item) eq 'HASH') {
@keys = map { $item->{ $_ } } @$fields;
}
elsif (blessed $item) {
@keys = map { $item->can($_) ? $item->$_() : $item } @$fields;
}
else {
@keys = $item;
}

# ugly hack to generate a single string using a delimiter that is
# unlikely (but not impossible) to be found in the wild.
return lc join('/*^UNLIKELY^*/', map { defined $_ ? $_ : '' } @keys);
}

sub _list_sort {
my ($list, @fields) = @_;
return $list unless @$list > 1; # no need to sort 1 item lists
return [
@fields # Schwartzian Transform
? map { $_->[0] } # for case insensitivity
sort { $a->[1] cmp $b->[1] }
map { [ $_, _list_sort_make_key($_, \@fields) ] }
@$list
: map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, lc $_ ] }
@$list,
];
}

sub _list_nsort {
my ($list, @fields) = @_;
return $list unless @$list > 1; # no need to sort 1 item lists
return [
@fields # Schwartzian Transform
? map { $_->[0] } # for case insensitivity
sort { $a->[1] <=> $b->[1] }
map { [ $_, _list_sort_make_key($_, \@fields) ] }
@$list
: map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, lc $_ ] }
@$list,
];
}

sub _list_unique {
my %u;
[ grep { ++$u{$_} == 1 } @{$_[0]} ];
}

sub _list_import {
my $list = shift;
push(@$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_);
return $list;
}

sub _list_merge {
my $list = shift;
return [ @$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_ ];
}

sub _list_slice {
my ($list, $from, $to) = @_;
$from ||= 0;
$to = $#$list unless defined $to;
$from += @$list if $from < 0;
$to += @$list if $to < 0;
return [ @$list[$from..$to] ];
}

sub _list_splice {
my ($list, $offset, $length, @replace) = @_;
if (@replace) {
# @replace can contain a list of multiple replace items, or
# be a single reference to a list
@replace = @{ $replace[0] }
if @replace == 1 && ref $replace[0] eq 'ARRAY';
return [ splice @$list, $offset, $length, @replace ];
}
elsif (defined $length) {
return [ splice @$list, $offset, $length ];
}
elsif (defined $offset) {
return [ splice @$list, $offset ];
}
else {
return [ splice(@$list) ];
}
}

sub _xml_filter {
my $text = shift;
for ($text) {
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
s/"/&quot;/g;
s/'/&apos;/g;
}
return $text;
}

sub _html_paragraph {
my $text = shift;
return "<p>\n"
. join("\n</p>\n\n<p>\n", split(/(?:\r?\n){2,}/, Text::Xslate::Util::html_escape($text)))
. "</p>\n";
}

sub _html_para_break {
my $text = shift;
$text = Text::Xslate::Util::html_escape($text);
$text =~ s|(\r?\n){2,}|$1<br />$1<br />$1|g;
return $text;
}

sub _html_line_break {
my $text = shift;
$text = Text::Xslate::Util::html_escape($text);
$text =~ s|(\r?\n)|<br />$1|g;
return $text;
}

sub _indent_filter_factory {
my ($pad) = @_;
$pad = 4 unless defined $pad;
$pad = ' ' x $pad if $pad =~ /^\d+$/;

return sub {
my $text = shift;
$text = '' unless defined $text;
$text =~ s/^/$pad/mg;
return $text;
}
}

sub _format_filter_factory {
my ($format) = @_;
$format = '%s' unless defined $format;

return sub {
my $text = shift;
$text = '' unless defined $text;
return join("\n", map{ sprintf($format, $_) } split(/\n/, $text));
}
}

sub _truncate_filter_factory {
my ($len, $char) = @_;
$len = $TRUNCATE_LENGTH unless defined $len;
$char = $TRUNCATE_ADDON unless defined $char;

# Length of char is the minimum length
my $lchar = length $char;
if ($len < $lchar) {
$char = substr($char, 0, $len);
$lchar = $len;
}

return sub {
my $text = shift;
return $text if length $text <= $len;
return substr($text, 0, $len - $lchar) . $char;
}
}

sub _repeat_filter_factory {
my ($iter) = @_;
$iter = 1 unless defined $iter and length $iter;

return sub {
my $text = shift;
$text = '' unless defined $text;
return join('\n', $text) x $iter;
}
}

sub _replace_filter_factory {
my ($search, $replace) = @_;
$search = '' unless defined $search;
$replace = '' unless defined $replace;

return sub {
my $text = shift;
$text = '' unless defined $text;
$text =~ s/$search/$replace/g;
return $text;
}
}

sub _remove_filter_factory {
my ($search) = @_;

return sub {
my $text = shift;
$text = '' unless defined $text;
$text =~ s/$search//g;
return $text;
}
}

1;
perl-Text-Xslate-Bridge-TT2Like-0.00010/src/000075500000000000000000000000001163430455100201715ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/src/TT2Like.tx000064400000000000000000000033411163430455100217650ustar00rootroot00000000000000=head1 NAME

Text::Xslate::Bridge::TT2Like - TT2 Variable Method Clone For Text::Xslate

=head1 SYNOPSIS

use Text::Xslate;

my $xslate = Text::Xslate->new(
module => [
'Text::Xslate::Bridge::TT2Like'
],
);

# Note that all methods require a set of parenthesis to be
# recognized as a method.
$xslate->render_string(
'<: $foo.length() :>',
{ foo => "foo" }
);

$xslate->render_string(
'<: $foo.replace("foo", "bar") :>',
{ foo => "foo" }
);

=head1 DESCRIPTION

Text::Xslate::Bridge::TT2Like exports Template-Toolkit variable methods into
Text::Xslate namespace, such that you can use them on your variables.

The only difference between this module and Text::Xslate::Bridge::TT2 is that
Bridge::TT2 uses Template::Toolkit underneath, while this module is independent
of Template::Toolkit and therefore does not require TT to be installed

=head1 AVAILABLE FUNCTIONS

Upon loading Text::Xslate::Bridge::TT2Like, you will be able to use the
following functions in your template. Please note that some functions like
C<uri> are available from Text::Xslate to start with, so we don't
reimplment them. Check the manual for Text::Xslate for more info.

[% FOREACH name IN names %]
=head2 C<[% name %]>

=over 4
[% FOREACH section IN sections.$name %]
=item C<[% section %]>
[% END %]

=back
[% END %]

=head1 ACKNOWLEDGEMENT

Original code was taken from Template::VMethods, Template::Filters by Andy Wardley.

=head1 AUTHOR

Copyright (c) 2010 Daisuke Maki C<< <daisuke@endeworks.jp> >>

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

=cutperl-Text-Xslate-Bridge-TT2Like-0.00010/t/000075500000000000000000000000001163430455100176455ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/t/001_scalar.t000064400000000000000000000023741163430455100216650ustar00rootroot00000000000000use strict;
use Test::More;
use t::TT2LikeTest qw(render_ok);

use_ok "Text::Xslate";
use_ok "Text::Xslate::Bridge::TT2Like";

# note Text::Xslate::Bridge::TT2Like->dump;

render_ok '[% foo.length() %]', undef, 3, "foo.length";
render_ok '[% foo.size() %]', undef, 1, "foo.size";
render_ok '[% foo.match( "o", 1 ).join("") %]', undef, 'oo', "foo.match";
render_ok '[% IF (foo.search( "fo" )) %]match[% ELSE %]no match[% END %]', undef, "match", "foo.search (MATCH)";
render_ok '[% IF (foo.search( "bar" )) %]match[% ELSE %]no match[% END %]', undef, "no match", "foo.search (NO MATCH)";
render_ok '[% foo.remove( "oo" ) %]', undef, "f", "foo.remove";
render_ok '[% foobar.split().size() %]', undef, 2, "foobar.split (size)";
render_ok '[% foobar.split().0 %]', undef, "foo", "foobar.split (foo)";
render_ok '[% foobar.split().1 %]', undef, "bar", "foobar.split (bar)";
render_ok '[% foobar.chunk(2).0 %]', undef, "fo", "foobar.chunk 0";
render_ok '[% foobar.chunk(2).1 %]', undef, "o ", "foobar.chunk 1";
render_ok '[% foobar.replace("bar", "baz") %]', undef, "foo baz", "foobar.replace";
render_ok '[% foobar.substr( 0, 2 ) %]', undef, "fo", "foobar.substr (get)";
render_ok '[% foobar.substr( 0, 2, "ba" ) %]', undef, "bao bar", "foobar.substr (replace)";


done_testing();
perl-Text-Xslate-Bridge-TT2Like-0.00010/t/002_array.t000064400000000000000000000037171163430455100215410ustar00rootroot00000000000000use strict;
use Test::More;
use t::TT2LikeTest qw(render_ok);

use_ok "Text::Xslate";
use_ok "Text::Xslate::Bridge::TT2Like";

render_ok '[% strings.size() %]', undef, 4, "strings.size";
render_ok '[% strings.join("-") %]', undef, "abc-def-ghi-jkl", "strings.join";
render_ok '[% CALL strings.push("end"); strings.4 %]', undef, "end", "strings.push";
render_ok '[% strings.pop() %]', undef, "jkl", "strings.pop";
render_ok '[% CALL strings.unshift("begin"); strings.0 %]', undef, "begin", "strings.unshift";
render_ok '[% strings.shift() %]', undef, "abc", "strings.shift";
render_ok '[% strings.max() %]', undef, 3, "strings.max";
render_ok '[% strings.size() %]', undef, 4, "strings.size";
render_ok '[% strings.defined() %]', undef, 1, "strings.defined";
render_ok '[% strings.first() %]', undef, "abc", "strings.first";
render_ok '[% strings.last() %]', undef, "jkl", "strings.last";
render_ok '[% strings.reverse().shift() %]', undef, "jkl", "strings.reverse";
render_ok '[% strings.grep( "[ce]" ).join("-") %]', undef, "abc-def", "strings.grep";
render_ok '[% CALL strings.unshift("zzz"); strings.sort().join("-") %]', undef, 'abc-def-ghi-jkl-zzz', "strings.sort";
render_ok '[% CALL numbers.unshift(99); numbers.nsort().join("-") %]', undef, "1-2-3-4-5-99", "numbers.nsort";
render_ok '[% CALL numbers.unshift(1); numbers.unique().join("-") %]', undef, "1-2-3-4-5", "numbers.unique";
render_ok '[% SET newlist = [ 6, 7, 8, 9 ]; CALL numbers.import( newlist ); numbers.join("-") %]', undef, "1-2-3-4-5-6-7-8-9", "numbers.import";
render_ok '[% SET newlist = numbers.merge( [ 6, 7, 8, 9 ] ); newlist.join("-") %]', undef, "1-2-3-4-5-6-7-8-9", "numbers.merge 1";
render_ok '[% SET newlist = numbers.merge( [ 6, 7, 8, 9 ] ); numbers.join("-") %]', undef, "1-2-3-4-5", "numbers.merge 2";
render_ok '[% numbers.slice( 1, 3 ).join("-") %]', undef, "2-3-4", "numbers.slice";
render_ok '[% CALL numbers.splice( 1, 3, [ 99 ] ); numbers.join("-") %]', undef, "1-99-5", "numbers.splice";

done_testing();perl-Text-Xslate-Bridge-TT2Like-0.00010/t/003_hash.t000064400000000000000000000024401163430455100213370ustar00rootroot00000000000000use strict;
use Test::More;
use t::TT2LikeTest qw(render_xslate render_ok);

use_ok "Text::Xslate";
use_ok "Text::Xslate::Bridge::TT2Like";

render_ok '[% hashmap.item("abc") %]', undef, "def", "hashmap.item";
render_ok '[% hashmap.size() %]', undef, 3, "hashmap.size";
render_ok '[% IF (hashmap.exists("abc")) %]exists[% ELSE %]not there[% END %]', undef, "exists", "hashmap.exists (MATCH)";
render_ok '[% IF (hashmap.exists("foo")) %]exists[% ELSE %]not there[% END %]', undef, "not there", "hashmap.exists (NO MATCH)";
render_ok '[% hashmap.defined() %]', undef, 1, "hashmap.defined";
render_ok '[% CALL hashmap.delete("abc"); FOREACH pair IN hashmap.pairs() %][% pair.key %]:[% pair.value %],[% END %]', undef, qr/ghi:jkl,list:ARRAY/, 'hashmap.delete';
render_ok '[% FOREACH key IN hashmap.sort() %][% key %],[% END %]', undef, "list,abc,ghi,", "hashmap.sort";
render_ok '[% FOREACH key IN hashmap.keys().sort() %][% key %],[% END %]', undef, 'abc,ghi,list,', 'hashmap.keys';

render_ok '[% hashmap.list.item(0).item("list_foo1") %]', undef, "list_bar1", "nested structures";

{
my $output = render_xslate '[% FOREACH pair IN hashmap.pairs() %][% pair.key %]:[% pair.value %],[% END %]';
like $output, qr/abc:def,/, "hashmap.pairs";
like $output, qr/ghi:jkl,/, "hashmap.pairs";
}

done_testing();perl-Text-Xslate-Bridge-TT2Like-0.00010/t/004_filters.t000064400000000000000000000027631163430455100220750ustar00rootroot00000000000000use strict;
use Test::More;
use t::TT2LikeTest qw(render_ok);

use_ok "Text::Xslate";
use_ok "Text::Xslate::Bridge::TT2Like";

# note(Text::Xslate::Bridge::TT2Like->dump);

render_ok q{[% "foo\n\nbar" | html_para %]}, undef, "<p>\nfoo\n</p>\n\n<p>\nbar</p>\n";
render_ok q{[% "foo\n\nbar" | html_para %]}, undef, "<p>\nfoo\n</p>\n\n<p>\nbar</p>\n";
render_ok q{[% "foo\n\nbar" | html_break %]}, undef, "foo\n<br />\n<br />\nbar";
render_ok q{[% "foo\n\nbar" | html_para_break %]}, undef, "foo\n<br />\n<br />\nbar";
render_ok q{[% "foo\n\nbar" | html_line_break %]}, undef, "foo<br />\n<br />\nbar";
render_ok q{[% "&'" | xml %]}, undef, "&amp;&apos;";
render_ok q{[% "my file.html" | uri %]}, undef, "my%20file.html";
render_ok q{[% "my file.html" | url %]}, undef, "my%20file.html";
render_ok '[% "foo" | upper %]', undef, "FOO", "foo.uc";
render_ok '[% "fOo" | lower %]', undef, "foo", "foo.lc";
render_ok '[% "foo" | ucfirst %]', undef, "Foo";
render_ok '[% "FOO" | lcfirst %]', undef, "fOO";
render_ok '[% " FOO " | trim %]', undef, "FOO";
render_ok '[% " I am a pen. " | collapse %]', undef, "I am a pen.";

render_ok '[% "foo\nbar" | indent("me> ") %]', undef, "me&gt; foo\nme&gt; bar";
render_ok '[% "7" | format("%03d") %]', undef, "007";
render_ok '[% "7" | repeat(3) %]', undef, "777";
render_ok '[% "I am a pen." | replace("pen", "John") %]', undef, "I am a John.";
render_ok '[% "pen." | remove("n") %]', undef, "pe.";
render_ok '[% "aiueoaiueo" | truncate(5) %]', undef, "ai...";


done_testing();
perl-Text-Xslate-Bridge-TT2Like-0.00010/t/005_xss.t000064400000000000000000000013361163430455100212360ustar00rootroot00000000000000use strict;
use Test::More;
use t::TT2LikeTest qw(render_ok);

use_ok "Text::Xslate";
use_ok "Text::Xslate::Util", "html_escape";
use_ok "Text::Xslate::Bridge::TT2Like";

# note(Text::Xslate::Bridge::TT2Like->dump);

my $xss = "<script>alert(1)</script>";
my $e = html_escape($xss)->as_string;

my $vars = { xss => $xss };

render_ok q{[% xss _ "foo\n\nbar" | html_para %]}, $vars, "<p>\n${e}foo\n</p>\n\n<p>\nbar</p>\n";
render_ok q{[% xss _ "foo\n\nbar" | html_break %]}, $vars, "${e}foo\n<br />\n<br />\nbar";
render_ok q{[% xss _ "foo\n\nbar" | html_para_break %]}, $vars, "${e}foo\n<br />\n<br />\nbar";
render_ok q{[% xss _ "foo\n\nbar" | html_line_break %]}, $vars, "${e}foo<br />\n<br />\nbar";


done_testing();
perl-Text-Xslate-Bridge-TT2Like-0.00010/t/TT2LikeTest.pm000064400000000000000000000023061163430455100222620ustar00rootroot00000000000000package
t::TT2LikeTest;
use Exporter 'import';
use Test::More ();
use Text::Xslate;
use Text::Xslate::Bridge::TT2Like;

our @EXPORT_OK = qw(render_xslate render_ok);

our $XSLATE = Text::Xslate->new(
syntax => 'TTerse',
module => [ 'Text::Xslate::Bridge::TT2Like' ],
);

sub render_xslate {
my ($template, $args) = @_;
$args ||= {
foo => "foo",
foobar => "foo bar",
strings => [ "abc", "def", "ghi", "jkl" ],
numbers => [ 1, 2, 3, 4, 5 ],
hashmap => {
abc => "def",
ghi => "jkl",
list => [
{ list_foo1 => "list_bar1" },
{ list_foo2 => "list_bar2" }
]
}
};
$XSLATE->render_string( $template, $args ),
}

sub render_ok {
my ($template, $args, $expect, $name) = @_;

local $Test::Builder::Level = $Test::Builder::Level + 1;
my $ref = ref $expect;
if (! $ref ) {
$func = \&Test::More::is;
} elsif ( $ref =~ /^Reg[Ee]xp$/ ) {
$func = \&Test::More::like;
} else {
die "Don't know how to handle expect type $ref";
}

$func->(
render_xslate( $template, $args ),
$expect,
$name
);
}

1;perl-Text-Xslate-Bridge-TT2Like-0.00010/xt/000075500000000000000000000000001163430455100200355ustar00rootroot00000000000000perl-Text-Xslate-Bridge-TT2Like-0.00010/xt/999_pod-coverage.t000064400000000000000000000002411163430455100232040ustar00rootroot00000000000000use strict;
use Test::More;
use Test::Requires;

test_requires 'Test::Pod::Coverage';

Test::Pod::Coverage::all_pod_coverage_ok({
trustme => [ 'BUILD' ]
});
perl-Text-Xslate-Bridge-TT2Like-0.00010/xt/999_pod.t000064400000000000000000000001361163430455100214160ustar00rootroot00000000000000use Test::More;
use Test::Requires;

test_requires 'Test::Pod';
Test::Pod::all_pod_files_ok();
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin