Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 287e81e0

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 287e81e0c99c7e203b9c78bcd6a1cf1a7c28d6f6
  • Vorgänger 36a33b59
  • Nachfolger ea974a5a

render() in Controller+Presenter: Support für Typ "text"

Unterschiede anzeigen:

SL/Controller/Base.pm
82 82
  }
83 83

  
84 84
  # Only certain types are supported.
85
  croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json)$/;
85
  croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json|text)$/;
86 86

  
87 87
  # The "template" argument must be a string or a reference to one.
88 88
  $template = ${ $template }                                       if ((ref($template) || '') eq 'REF') && (ref(${ $template }) eq 'SL::Presenter::EscapedText');
......
112 112
      $::form->{header} = 1;
113 113
      my $content_type  = $options->{type} eq 'html' ? 'text/html'
114 114
                        : $options->{type} eq 'js'   ? 'text/javascript'
115
                        : $options->{type} eq 'text' ? 'text/plain'
115 116
                        :                              'application/json';
116 117

  
117 118
      print $::form->create_http_response(content_type => $content_type,
......
401 402

  
402 403
=item C<type>
403 404

  
404
The template type. Can be C<html> (the default), C<js> for JavaScript
405
or C<json> for JSON content. Affects the extension that's added to the
406
file name given with a non-reference C<$template> argument, the
407
content type HTTP header that is output and whether or not the layout
408
will be output as well (see description of C<layout> below).
405
The template type. Can be C<html> (the default), C<js> for JavaScript,
406
C<json> for JSON and C<text> for plain text content. Affects the
407
extension that's added to the file name given with a non-reference
408
C<$template> argument, the content type HTTP header that is output and
409
whether or not the layout will be output as well (see description of
410
C<layout> below).
409 411

  
410 412
=item C<process>
411 413

  
SL/Presenter.pm
40 40
  }
41 41

  
42 42
  # Only certain types are supported.
43
  croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json)$/;
43
  croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json|text)$/;
44 44

  
45 45
  # The "template" argument must be a string or a reference to one.
46 46
  $template = ${ $template }                                       if ((ref($template) || '') eq 'REF') && (ref(${ $template }) eq 'SL::Presenter::EscapedText');
......
49 49
  # Look for the file given by $template if $template is not a reference.
50 50
  my $source;
51 51
  if (!ref $template) {
52
    $source = "templates/webpages/${template}." . $options->{type};
52
    my $ext = $options->{type} eq 'text' ? 'txt' : $options->{type};
53
    $source = "templates/webpages/${template}.${ext}";
53 54
    croak "Template file ${source} not found" unless -f $source;
54 55

  
55 56
  } elsif (ref($template) eq 'SCALAR') {
......
223 224

  
224 225
=item C<type>
225 226

  
226
The template type. Can be C<html> (the default), C<js> for JavaScript
227
or C<json> for JSON content. Affects only the extension that's added
228
to the file name given with a non-reference C<$template> argument.
227
The template type. Can be C<html> (the default), C<js> for JavaScript,
228
C<json> for JSON and C<text> for plain text content. Affects only the
229
extension that's added to the file name given with a non-reference
230
C<$template> argument.
229 231

  
230 232
=item C<process>
231 233

  

Auch abrufbar als: Unified diff