HTML/Template/Compiled/Plugin/Hyphen: add
use escape "hyphen" at HTC templates to concatenate words by hyphens. This fill fix URLs with filenames generated from series or program title.
This commit is contained in:
26
lib/calcms/HTML/Template/Compiled/Plugin/Hyphen.pm
Normal file
26
lib/calcms/HTML/Template/Compiled/Plugin/Hyphen.pm
Normal file
@@ -0,0 +1,26 @@
|
||||
package HTML::Template::Compiled::Plugin::Hyphen;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
HTML::Template::Compiled->register(__PACKAGE__);
|
||||
|
||||
sub escape_whitespace {
|
||||
my ($s) = @_;
|
||||
$s =~ s/\s/-/g;
|
||||
$s =~ s/\-+/-/g;
|
||||
$s =~ s/\-$//g;
|
||||
$s =~ s/^\-//g;
|
||||
return $s;
|
||||
}
|
||||
|
||||
sub register {
|
||||
my ($class) = @_;
|
||||
my %plugs = (
|
||||
escape => {
|
||||
HYPHEN => \&escape_whitespace
|
||||
},
|
||||
);
|
||||
return \%plugs;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -8,6 +8,7 @@ use feature 'state';
|
||||
use Data::Dumper;
|
||||
use HTML::Template::Compiled();
|
||||
use HTML::Template::Compiled::Plugin::XMLEscape();
|
||||
use HTML::Template::Compiled::Plugin::Hyphen();
|
||||
|
||||
#use HTML::Template::JIT();
|
||||
use JSON();
|
||||
@@ -119,6 +120,7 @@ sub initTemplate($) {
|
||||
default_escape => $default_escape,
|
||||
cache => 1,
|
||||
utf8 => 1,
|
||||
plugin => [qw(HTML::Template::Compiled::Plugin::Hyphen)]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user