Revision 70654da2
Von Moritz Bunkus vor etwa 9 Jahren hinzugefügt
SL/Template/Plugin/JavaScript.pm | ||
---|---|---|
1 | 1 |
package SL::Template::Plugin::JavaScript; |
2 | 2 |
|
3 |
use base qw( Template::Plugin::Filter ); |
|
3 |
use base qw( Template::Plugin ); |
|
4 |
use Template::Plugin; |
|
4 | 5 |
|
5 | 6 |
use strict; |
6 | 7 |
|
7 |
my $cached_instance; |
|
8 |
|
|
9 | 8 |
sub new { |
10 |
my $class = shift; |
|
11 |
|
|
12 |
return $cached_instance ||= $class->SUPER::new(@_); |
|
13 |
} |
|
14 |
|
|
15 |
sub init { |
|
16 |
my $self = shift; |
|
17 |
|
|
18 |
$self->install_filter($self->{ _ARGS }->[0] || 'js'); |
|
9 |
my ($class, $context, @args) = @_; |
|
19 | 10 |
|
20 |
return $self; |
|
11 |
return bless { |
|
12 |
CONTEXT => $context, |
|
13 |
}, $class; |
|
21 | 14 |
} |
22 | 15 |
|
23 | 16 |
# |
... | ... | |
45 | 38 |
return $text; |
46 | 39 |
} |
47 | 40 |
|
48 |
sub filter { |
|
49 |
my ($self, $text) = @_; |
|
50 |
return $self->escape($text); |
|
51 |
} |
|
52 |
|
|
53 | 41 |
sub replace_with { |
54 | 42 |
return _replace_helper('replaceWith', @_); |
55 | 43 |
} |
... | ... | |
104 | 92 |
<input type="submit" value="Delete" |
105 | 93 |
onclick="if (confirm('Do you really want to delete this: [% JavaScript.escape(obj.description) %]') return true; else return false;"> |
106 | 94 |
|
107 |
You can also use the filter syntax instead: |
|
108 |
|
|
109 |
<input type="submit" value="Delete" |
|
110 |
onclick="if (confirm('Do you really want to delete this: [% obj.description | js %]') return true; else return false;"> |
|
111 |
|
|
112 | 95 |
=item C<replace_with $selector, $template, %locals> |
113 | 96 |
|
114 | 97 |
Returns code replacing the DOM elements matched by C<$selector> with |
Auch abrufbar als: Unified diff
Revert "JavaScript-Plugin: auch als Filter einsetzen können"
Dies revertet Commit 20d730acdbb52b5b75af783aa010609e25b73024. Grund
ist, dass aus bisher nicht zu analysierenden Gründen in manchen
Situationen der Template-Toolkit-Compiler oder eine andere Komponente
Quark erzeugt und daher das Plugin nicht findet.
Wenn es geht, dann sieht das compilierte Template an der Stelle wie
folgt aus:
------ snip ------
$output .= do {
my $output = '';
my $_tt_filter = $context->filter('js') || $context->throw($context->error);
------ snip ------
Wenn es aber nicht geht, dann wie folgt:
------ snip ------
$output .= do {
my $output = '';
my $_tt_filter = $context->filter($stash->get('js')) || $context->throw($context->error);
------ snip ------
Im nicht funktionierenden Fall wird das Plugin selber im Stash gesucht,
wo es aber nicht vorhanden ist.
Warum das passiert ist noch rätselhaft und wird mangels Zeit erst einmal
nicht weiter untersucht.