Details |
Last modification |
View Log
| RSS feed
| Rev |
Author |
Line No. |
Line |
| 1293 |
dpurdie |
1 |
package Codestriker::Template::Plugin::JavascriptEscape;
|
|
|
2 |
|
|
|
3 |
# Simple template toolkit plugin module for escaping the appropriate
|
|
|
4 |
# characters within a javascript string.
|
|
|
5 |
|
|
|
6 |
use Template::Plugin::Filter;
|
|
|
7 |
use Codestriker;
|
|
|
8 |
|
|
|
9 |
use base qw( Template::Plugin::Filter );
|
|
|
10 |
|
|
|
11 |
sub filter {
|
|
|
12 |
my ($self, $text) = @_;
|
|
|
13 |
|
|
|
14 |
# Escape double and single quotes and backslashes.
|
|
|
15 |
$text =~ s/\\/\\\\/g;
|
|
|
16 |
$text =~ s/\"/\\\"/g;
|
|
|
17 |
$text =~ s/\'/\\\'/g;
|
|
|
18 |
|
|
|
19 |
return $text;
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
1;
|