From 20d730acdbb52b5b75af783aa010609e25b73024 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 14 Dec 2015 14:15:05 +0100 Subject: [PATCH] =?utf8?q?JavaScript-Plugin:=20auch=20als=20Filter=20einse?= =?utf8?q?tzen=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Template/Plugin/JavaScript.pm | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/SL/Template/Plugin/JavaScript.pm b/SL/Template/Plugin/JavaScript.pm index 16989e9a2..48158307f 100644 --- a/SL/Template/Plugin/JavaScript.pm +++ b/SL/Template/Plugin/JavaScript.pm @@ -1,16 +1,23 @@ package SL::Template::Plugin::JavaScript; -use base qw( Template::Plugin ); -use Template::Plugin; +use base qw( Template::Plugin::Filter ); use strict; +my $cached_instance; + sub new { - my ($class, $context, @args) = @_; + my $class = shift; + + return $cached_instance ||= $class->SUPER::new(@_); +} + +sub init { + my $self = shift; + + $self->install_filter($self->{ _ARGS }->[0] || 'js'); - return bless { - CONTEXT => $context, - }, $class; + return $self; } # @@ -38,6 +45,11 @@ sub escape { return $text; } +sub filter { + my ($self, $text) = @_; + return $self->escape($text); +} + sub replace_with { return _replace_helper('replaceWith', @_); } @@ -92,6 +104,11 @@ value is not wrapped in quotes. Example: +You can also use the filter syntax instead: + + + =item C Returns code replacing the DOM elements matched by C<$selector> with -- 2.20.1