|
#! /usr/bin/env perl # -*- perl -*-
my $assets = {
strings => [
{ value => 'bazoo' },
{ value => 'bar' },
{ value => 'foo' },
{ value => 'Appleseed' },
{ value => 'John' },
{ value => 'Jane' },
{ value => 'baz' },
{ value => 'baz' },
{ value => 'Acme' },
{ value => 'Doe' },
],
numbers => [
{ value => 48 },
{ value => 2304 },
{ value => 48 },
{ value => 13 },
{ value => 13 },
{ value => 12345679 },
],
months => [
{
name => 'January' ,
const => 'constant' ,
date => {
month => '01' ,
imonth => 1,
},
},
{
name => 'February' ,
const => 'constant' ,
date => {
month => '02' ,
imonth => 2,
},
},
{
name => 'March' ,
const => 'constant' ,
date => {
month => '03' ,
imonth => 3,
},
},
{
name => 'April' ,
const => 'constant' ,
date => {
month => '04' ,
imonth => 4,
},
},
{
name => 'May' ,
const => 'constant' ,
date => {
month => '05' ,
imonth => 5,
},
},
{
name => 'June' ,
const => 'constant' ,
date => {
month => '06' ,
imonth => 6,
},
},
{
name => 'July' ,
const => 'constant' ,
date => {
month => '07' ,
imonth => 7,
},
},
{
name => 'August' ,
const => 'constant' ,
date => {
month => '08' ,
imonth => 8,
},
},
{
name => 'September' ,
const => 'constant' ,
date => {
month => '09' ,
imonth => 9,
},
},
{
name => 'October' ,
const => 'constant' ,
date => {
month => '10' ,
imonth => 10,
},
},
{
name => 'November' ,
const => 'constant' ,
date => {
month => '11' ,
imonth => 11,
},
},
{
name => 'December' ,
const => 'constant' ,
date => {
month => '12' ,
imonth => 12,
},
},
]
};
my $tt = Template->new(
PLUGIN_BASE => [ 'Qgoda::TT2::Plugin' ],
);
my ( $in , $out );
$out = '' ;
$in = <<EOF;
[%- USE Qgoda -%]
[%- FOREACH string IN strings.sortBy('value') %]
[%- string.value %]
[% END -%]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
Acme
Appleseed
Doe
Jane
John
bar
baz
baz
bazoo
foo
EOF
$out = '' ;
$in = <<EOF;
[%- USE Qgoda -%]
[%- FOREACH number IN numbers.nsortBy('value') %]
[%- number.value %]
[% END -%]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
13
13
48
48
2304
12345679
EOF
$out = '' ;
$in = <<EOF;
[%- USE Qgoda -%]
[%- a = 1 %][% b = 2 -%]
[%- FOREACH month IN months.sortBy('name') %]
[% month.name %]
[%- END -%]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
April
August
December
February
January
July
June
March
May
November
October
September
EOF
$out = '' ;
$in = <<EOF;
[% USE Qgoda %]
[% FOREACH month IN months.sortBy('date.imonth') %]
[%- month.name %]
[% END %]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
January
October
November
December
February
March
April
May
June
July
August
September
EOF
$out = '' ;
$in = <<EOF;
[% USE Qgoda %]
[% FOREACH month IN months.nsortBy('date.imonth') %]
[%- month.name %]
[% END %]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
January
February
March
April
May
June
July
August
September
October
November
December
EOF
$out = '' ;
$in = <<EOF;
[% USE Qgoda %]
[% FOREACH month IN months.sortBy('date.month') %]
[%- month.name %]
[% END %]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
January
February
March
April
May
June
July
August
September
October
November
December
EOF
$out = '' ;
$in = <<EOF;
[% USE Qgoda %]
[% FOREACH month IN months.sortBy('const', 'date.month') %]
[%- month.name %]
[% END %]
EOF
$tt ->process(\ $in , $assets , \ $out ) or die $tt ->error;
is $out , <<EOF;
January
February
March
April
May
June
July
August
September
October
November
December
EOF
|