treebird/perl/template_helpers.pm
nekobit 3ffbfb2f13 Refactormaxxxxx account lists, rewrite muted/blocked users
FossilOrigin-Name: e571d12a115516b8dea8a68ee3caa1272b102e10a4e0fb308df4e7556b8c30ec
2022-08-13 22:35:30 +00:00

41 lines
707 B
Perl

package template_helpers;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( &to_template );
use string_helpers 'simple_escape';
my $template = Template->new(
{
INTERPOLATE => 1,
POST_CHOMP => 1,
EVAL_PERL => 1,
TRIM => 1
});
sub pretty_error($)
{
my $error = simple_escape(shift);
<< "END_ERROR";
<span class="e-error error-pad">
$error
</span>
END_ERROR
}
sub to_template
{
my ($vars, $data) = @_;
my $result;
return 0 unless ref $data;
return 0 unless ref $vars;
# TODO HTML error formatting
$template->process($data, $vars, \$result) ||
return pretty_error($template->error());
$result;
}