Template-Plugin-JavaScript-0.02/ 000755 000771 000024 00000000000 11502215206 017437 5 ustar 00miyagawa staff 000000 000000 Template-Plugin-JavaScript-0.02/Changes 000644 000771 000024 00000000301 11502215063 020725 0 ustar 00miyagawa staff 000000 000000 Revision history for Perl extension Template::Plugin::JavaScript
0.02 Wed Dec 15 11:42:31 PST 2010
- Escapes HTML tags too (cho45)
0.01 Fri Aug 20 01:00:39 2004
- original version
Template-Plugin-JavaScript-0.02/lib/ 000755 000771 000024 00000000000 11502215206 020205 5 ustar 00miyagawa staff 000000 000000 Template-Plugin-JavaScript-0.02/Makefile.PL 000644 000771 000024 00000000353 11502214653 021417 0 ustar 00miyagawa staff 000000 000000 use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'Template::Plugin::JavaScript',
'VERSION_FROM' => 'lib/Template/Plugin/JavaScript.pm', # finds $VERSION
'PREREQ_PM' => {
Test::More => 0.32,
Template => 0,
},
);
Template-Plugin-JavaScript-0.02/MANIFEST 000644 000771 000024 00000000276 11502214653 020602 0 ustar 00miyagawa staff 000000 000000 Changes
lib/Template/Plugin/JavaScript.pm
Makefile.PL
MANIFEST This list of files
t/00_compile.t
t/01_test.t
META.yml Module meta-data (added by MakeMaker)
Template-Plugin-JavaScript-0.02/META.yml 000644 000771 000024 00000001011 11502215206 020701 0 ustar 00miyagawa staff 000000 000000 --- #YAML:1.0
name: Template-Plugin-JavaScript
version: 0.02
abstract: ~
author: []
license: unknown
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
build_requires:
ExtUtils::MakeMaker: 0
requires:
Template: 0
Test::More: 0.32
no_index:
directory:
- t
- inc
generated_by: ExtUtils::MakeMaker version 6.56
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
Template-Plugin-JavaScript-0.02/t/ 000755 000771 000024 00000000000 11502215206 017702 5 ustar 00miyagawa staff 000000 000000 Template-Plugin-JavaScript-0.02/t/00_compile.t 000644 000771 000024 00000000130 11502214653 022015 0 ustar 00miyagawa staff 000000 000000 use strict;
use Test::More tests => 1;
BEGIN { use_ok 'Template::Plugin::JavaScript' }
Template-Plugin-JavaScript-0.02/t/01_test.t 000644 000771 000024 00000001364 11502214725 021357 0 ustar 00miyagawa staff 000000 000000 use strict;
use Template::Test;
use lib 'lib';
test_expect(\*DATA);
__END__
--test--
[% USE JavaScript -%]
document.write("[% FILTER js %]
Here's some text going on.
[% END %]");
--expect--
document.write("\nHere\'s some text going on.\n");
--test--
[% USE JavaScript -%]
document.write("[% FILTER js %]
You & I
[% END %]");
--expect--
document.write("\nYou \x26 I\n");
--test--
[% USE JavaScript -%]
var t = "[% FILTER js %]
\"+alert(1)//
[% END %]";
--expect--
var t = "\n\\\"+alert(1)//\n";
--test--
[% USE JavaScript -%]
--expect--
Template-Plugin-JavaScript-0.02/lib/Template/ 000755 000771 000024 00000000000 11502215206 021760 5 ustar 00miyagawa staff 000000 000000 Template-Plugin-JavaScript-0.02/lib/Template/Plugin/ 000755 000771 000024 00000000000 11502215206 023216 5 ustar 00miyagawa staff 000000 000000 Template-Plugin-JavaScript-0.02/lib/Template/Plugin/JavaScript.pm 000644 000771 000024 00000002627 11502215201 025624 0 ustar 00miyagawa staff 000000 000000 package Template::Plugin::JavaScript;
use strict;
use vars qw($VERSION);
$VERSION = '0.02';
require Template::Plugin;
use base qw(Template::Plugin);
use vars qw($FILTER_NAME);
$FILTER_NAME = 'js';
sub new {
my($self, $context, @args) = @_;
my $name = $args[0] || $FILTER_NAME;
$context->define_filter($name, \&encode_js, 0);
return $self;
}
sub encode_js {
local $_ = shift;
return '' unless defined $_;
s!\\!\\\\!g;
s!(['"])!\\$1!g;
s!\n!\\n!g;
s!\f!\\f!g;
s!\r!\\r!g;
s!\t!\\t!g;
s!!\\x3e!g;
s!&!\\x26!g;
$_;
}
1;
__END__
=head1 NAME
Template::Plugin::JavaScript - Encodes text to be safe in JavaScript
=head1 SYNOPSIS
[% USE JavaScript %]
=head1 DESCRIPTION
Template::Plugin::JavaScript is a TT filter that filters text so it
can be safely used in JavaScript quotes.
[% USE JavaScript %]
document.write("[% FILTER js %]
Here's some text going on.
[% END %]");
will become:
document.write("\nHere\'s some text going on.\n");
=head1 AUTHOR
The original idea comes from Movable Type's C global filter.
Tatsuhiko Miyagawa Emiyagawa@bulknews.netE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L
=cut