Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wishlist (TTerse): add support for multiple function/filter parameters #121

Open
chocolateboy opened this issue Apr 25, 2014 · 0 comments
Open

Comments

@chocolateboy
Copy link

Perl: v5.16.0
Text::Xslate: 3.2.3

Multiple function/filter parameters work in Template Toolkit e.g.:

[% "The  cat  sat  on  the  mat" | replace('\s+', '_') %]

- but don't appear to be supported in Text::Xslate.

Test case (I know replace is available elsewhere: it's just an example):

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More tests => 4;
use Text::Xslate;

use constant {
    FILTER   => '[% name | replace("ohn", "ane") %]',
    FUNCTION => '[% replace(name, "ane", "ohn") %]',
};

sub replace($;$$) {
    my $string = shift;
    my $params = is(scalar(@_), 2);

    if ($params) {
        my ($search, $replace) = @_;
        $string =~ s{$search}{$replace};
    }

    return $string;
}

my $template = Text::Xslate->new(syntax => 'TTerse', function => { replace => \&replace });
my $rendered_filter = $template->render_string(FILTER, { name => 'John Doe' });
my $rendered_function = $template->render_string(FUNCTION, { name => 'Jane Doe' });

is $rendered_filter, 'Jane Doe';
is $rendered_function, 'John Doe';
@chocolateboy chocolateboy changed the title Wishlist (TTerse): add support for function/filter parameters Wishlist (TTerse): add support for multiple function/filter parameters Apr 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants