Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d4458803

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID d445880375bce1462b8f9a8b1a502b34c296d41f
  • Vorgänger 2bc66c62
  • Nachfolger 5b5dbec0

SL::Presenter -- die neue Präsentationsschicht

Unterschiede anzeigen:

SL/Controller/Base.pm
9 9
use List::Util qw(first);
10 10
use SL::Request qw(flatten);
11 11
use SL::MoreCommon qw(uri_encode);
12
use SL::Presenter;
12 13

  
13 14
use Rose::Object::MakeMethods::Generic
14 15
(
......
62 63
  $options->{type}       = lc($options->{type} || 'html');
63 64
  $options->{no_layout}  = 1 if $options->{type} eq 'js';
64 65

  
65
  my $source;
66
  if ($options->{inline}) {
67
    $source = \$template;
68

  
69
  } elsif($options->{raw}) {
70
    $source =  $template;
71

  
72
  } else {
73
    $source = "templates/webpages/${template}." . $options->{type};
74
    croak "Template file ${source} not found" unless -f $source;
75
  }
76

  
77 66
  if (!$options->{partial} && !$options->{inline} && !$::form->{header}) {
78 67
    if ($options->{no_layout}) {
79 68
      $::form->{header} = 1;
......
88 77
    }
89 78
  }
90 79

  
91
  my %params = ( %locals,
92
                 AUTH          => $::auth,
93
                 FLASH         => $::form->{FLASH},
94
                 FORM          => $::form,
95
                 INSTANCE_CONF => $::instance_conf,
96
                 LOCALE        => $::locale,
97
                 LXCONFIG      => \%::lx_office_conf,
98
                 LXDEBUG       => $::lxdebug,
99
                 MYCONFIG      => \%::myconfig,
100
                 SELF          => $self,
101
               );
102

  
103 80
  my $output;
104
  if (!$options->{raw}) {
105
    my $parser = $self->_template_obj;
106
    $parser->process($source, \%params, \$output) || croak $parser->error;
81
  if ($options->{raw}) {
82
    $output = $$template;
107 83
  } else {
108
    $output = $$source;
84
    $output = $self->presenter->render(
85
      $template, $options,
86
      %locals,
87
      SELF => $self,
88
    );
109 89
  }
110 90

  
111 91
  print $output unless $options->{inline} || $options->{no_output};
......
129 109
  $file->close;
130 110
}
131 111

  
112
sub presenter {
113
  return SL::Presenter->get;
114
}
115

  
132 116
sub controller_name {
133 117
  my $class = ref($_[0]) || $_[0];
134 118
  $class    =~ s/^SL::Controller:://;
......
233 217
  }
234 218
}
235 219

  
236
sub _template_obj {
237
  my ($self) = @_;
238

  
239
  $self->{__basepriv_template_obj} ||=
240
    Template->new({ INTERPOLATE  => 0,
241
                    EVAL_PERL    => 0,
242
                    ABSOLUTE     => 1,
243
                    CACHE_SIZE   => 0,
244
                    PLUGIN_BASE  => 'SL::Template::Plugin',
245
                    INCLUDE_PATH => '.:templates/webpages',
246
                    COMPILE_EXT  => '.tcc',
247
                    COMPILE_DIR  => $::lx_office_conf{paths}->{userspath} . '/templates-cache',
248
                    ERROR        => 'templates/webpages/generic/exception.html',
249
                  }) || croak;
250

  
251
  return $self->{__basepriv_template_obj};
252
}
253

  
254 220
1;
255 221

  
256 222
__END__
......
369 335
parameters are slurped into C<%locals>.
370 336

  
371 337
What is rendered and how C<$template> is interpreted is determined by
372
the options I<type>, I<inline>, I<partial> and I<no_layout>.
338
the options I<type>, I<inline>, I<partial> and I<no_layout>. The
339
actual rendering is handled by L<SL::Presenter/render>.
373 340

  
374 341
If C<< $options->{inline} >> is trueish then C<$template> is a string
375 342
containing the template code to interprete. Additionally the output
376 343
will not be sent to the browser. Instead it is only returned to the
377 344
caller.
378 345

  
379
If C<< $options->{raw} >> is trueish, the function will treat the input as
380
already parsed, and will not filter the input through Template. Unlike
381
C<inline>, the input is taked as a reference.
346
If C<< $options->{raw} >> is trueish, the function will treat the
347
input as already parsed, and will not filter the input through
348
Template. This also means that L<SL::Presenter/render> is not
349
called either. Unlike C<inline>, the input is taken as a reference.
382 350

  
383 351
If C<< $options->{inline} >> is falsish then C<$template> is
384 352
interpreted as the name of a template file. It is prefixed with
......
400 368
trueish). Setting C<< $options->{no_layout} >> to trueish will prevent
401 369
this.
402 370

  
403
The template itself has access to the following variables:
404

  
405
=over 2
406

  
407
=item * C<AUTH> -- C<$::auth>
408

  
409
=item * C<FORM> -- C<$::form>
410

  
411
=item * C<LOCALE> -- C<$::locale>
412

  
413
=item * C<LXCONFIG> -- all parameters from C<config/kivitendo.conf>
414
with the same name they appear in the file (first level is the
415
section, second the actual variable, e.g. C<system.dbcharset>,
416
C<features.webdav> etc)
417

  
418
=item * C<LXDEBUG> -- C<$::lxdebug>
419

  
420
=item * C<MYCONFIG> -- C<%::myconfig>
421

  
422
=item * C<SELF> -- the controller instance
423

  
424
=item * All items from C<%locals>
425

  
426
=back
371
The template itself has access to several variables. These are listed
372
in the documentation to L<SL::Presenter/render>.
427 373

  
428 374
Unless C<< $options->{inline} >> is trueish the function will send the
429 375
output to the browser.
......
563 509
mechanism was used then this is not C<dispatch> but the actual method
564 510
name the dispatching resolved to.
565 511

  
512
=item C<presenter>
513

  
514
Returns the global presenter object by calling
515
L<SL::Presenter/get>.
516

  
566 517
=back
567 518

  
568 519
=head2 PRIVATE FUNCTIONS

Auch abrufbar als: Unified diff