Split sendHtml() to be able to change HTML template params (#595)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 9 years ago
parent 9fc5edfe79
commit 371aa0c003
  1. 17
      lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI.pm
  2. 13
      lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm

@ -158,7 +158,8 @@ sub handler { _mustBeDefined(@_) }
sub sendHtml {
my ( $self, $req, $template, %args ) = @_;
$args{headers} ||= [];
$args{code} ||= 200;
$args{headers} ||= $req->respHeaders || [];
my $htpl;
$template = $self->templateDir . "/$template.tpl";
return $self->sendError( $req, "Unable to read $template", 500 )
@ -183,27 +184,17 @@ sub sendHtml {
STATIC_PREFIX => $sp,
AVAILABLE_LANGUAGES => $self->languages,
PORTAL => $self->portal,
LINKS => $self->links ? to_json( $self->links ) : '""',
MENULINKS => $self->menuLinks ? to_json( $self->menuLinks ) : '""',
VERSION => $VERSION,
( $self->can('tplParams') ? %{ $self->tplParams } : () ),
);
};
if ($@) {
return $self->sendError( $req, "Unable to load template: $@", 500 );
}
$self->lmLog(
'For more performance, store the result of this as static file',
'debug' );
# Set headers
my $hdrs = [ 'Content-Type' => 'text/html', @{ $args{headers} } ];
unless ( $self->logLevel eq 'debug' ) {
push @$hdrs,
ETag => "LMNG-manager-$VERSION",
'Cache-Control' => 'private, max-age=2592000';
}
$self->lmLog( "Sending $template", 'debug' );
return [ 200, $hdrs, [ $htpl->output() ] ];
return [ $args{code}, $hdrs, [ $htpl->output() ] ];
}
###############

@ -13,10 +13,12 @@ package Lemonldap::NG::Manager;
use 5.10.0;
use utf8;
use Mouse;
our $VERSION = '2.0.0';
use JSON;
use Lemonldap::NG::Common::Conf::Constants;
use Lemonldap::NG::Common::PSGI::Constants;
our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Manager::Lib', 'Lemonldap::NG::Handler::PSGI::Router';
## @method boolean init($args)
@ -105,6 +107,15 @@ sub init {
1;
}
sub tplParams {
my $self = shift;
return {
LINKS => $self->links ? to_json( $self->links ) : '""',
MENULINKS => $self->menuLinks ? to_json( $self->menuLinks ) : '""',
VERSION => $VERSION,
};
}
1;
__END__

Loading…
Cancel
Save