]> git.deb.at Git - deb/packages.git/blobdiff - lib/Packages/Template.pm
Move common functions for template use to Packages::Template
[deb/packages.git] / lib / Packages / Template.pm
index 0fe24813ee9bad83afbf1999a4213f3c7ab9f451..be71d154ffbcaf890d8e0fc8cec583e90a5ade81 100644 (file)
@@ -5,6 +5,9 @@ use warnings;
 
 use Template;
 use Locale::gettext;
+use URI ();
+use HTML::Entities ();
+use URI::Escape ();
 use Benchmark ':hireswallclock';
 
 use Packages::CGI;
@@ -19,6 +22,7 @@ use constant COMPILE => 1;
 
 sub new {
     my ($classname, $include, $format, $vars, $options) = @_;
+    $vars ||= {};
     $options ||= {};
 
     my $self = {};
@@ -29,6 +33,19 @@ sub new {
        year => $timestamp[5]+1900,
        string => scalar gmtime() .' UTC',
     };
+    $vars->{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
+    $vars->{make_url} = sub { return &Packages::CGI::make_url(@_) };
+    $vars->{g} = sub { return &Packages::I18N::Locale::tt_gettext(@_) };
+    $vars->{extract_host} = sub { my $uri = URI->new($_[0]);
+                                 my $host = $uri->host;
+                                 $host .= ':'.$uri->port if $uri->port != $uri->default_port;
+                                 return $host;
+                             };
+    # needed to work around the limitations of the the FILTER syntax
+    $vars->{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
+    $vars->{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
+    $vars->{quotemeta} = sub { return quotemeta($_[0]) };
+    $vars->{string2id} = sub { return &Packages::CGI::string2id(@_) };
 
     $self->{template} = Template->new( {
        PRE_PROCESS => [ 'config.tmpl' ],