| 1 | #!perl -w |
| 2 | use strictscip-perl cpan Text-Xslate v3.5.9 strict/; |
| 3 | use Test::Morescip-perl cpan Text-Xslate v3.5.9 Test/More/; |
| 4 | |
| 5 | use Text::Xslatescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/ qw(html_builder mark_raw); |
| 6 | |
| 7 | sub custom_html_escapescip-perl cpan Text-Xslate v3.5.9 main/custom_html_escape(). { # for html_escape() |
| 8 | my $s = shiftscip-perl cpan Text-Xslate v3.5.9 main/shift().; |
| 9 | return $s if refscip-perl cpan Text-Xslate v3.5.9 main/ref(). $s; |
| 10 | my %h = ( |
| 11 | '<' => '<', |
| 12 | '>' => '>', |
| 13 | q{'} => ''', |
| 14 | q{"} => '"', |
| 15 | # '&' => '&', # Don't espcae &. allowing to use character-entitfy-references(like '&#hearts) |
| 16 | ); |
| 17 | |
| 18 | $s =~ s/(.)/$h{$1} or $1/xmsge; |
| 19 | $s; |
| 20 | } |
| 21 | |
| 22 | sub custom_html_filterscip-perl cpan Text-Xslate v3.5.9 main/custom_html_filter(). { # for html() |
| 23 | my $s = shiftscip-perl cpan Text-Xslate v3.5.9 main/shift().; |
| 24 | return $s if refscip-perl cpan Text-Xslate v3.5.9 main/ref(). $s; |
| 25 | my %h = ( |
| 26 | '<' => '<', |
| 27 | '>' => '>', |
| 28 | q{'} => ''', |
| 29 | q{"} => '"', |
| 30 | # '&' => '&', # Don't espcae &. allowing to use character-entitfy-references(like '&#hearts) |
| 31 | ); |
| 32 | |
| 33 | $s =~ s/(.)/$h{$1} or $1/xmsge; |
| 34 | mark_rawscip-perl cpan Text-Xslate v3.5.9 main/mark_raw().($s); |
| 35 | } |
| 36 | |
| 37 | notescip-perl cpan Text-Xslate v3.5.9 main/note(). 'override html_escape()'; |
| 38 | { |
| 39 | my $tx = Text::Xslate->newscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/new().( |
| 40 | cache => 0, |
| 41 | verbose => 2, |
| 42 | warn_handler => sub { diescip-perl cpan Text-Xslate v3.5.9 main/die(). @_scip-perl cpan Text-Xslate v3.5.9 main/`@_`. }, |
| 43 | |
| 44 | function => { |
| 45 | html_escape => \&custom_html_escapescip-perl cpan Text-Xslate v3.5.9 main/custom_html_escape(). |
| 46 | }, |
| 47 | ); |
| 48 | |
| 49 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<div><: '<^_^>♥' :></div>}), |
| 50 | '<div><^_^>♥</div>'; |
| 51 | |
| 52 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<div><: $foo :></div>}, { foo => '<^_^>♥' }), |
| 53 | '<div><^_^>♥</div>'; |
| 54 | |
| 55 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' :>}), |
| 56 | '<div>'; |
| 57 | |
| 58 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' | raw :>}), |
| 59 | '<div>'; |
| 60 | |
| 61 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' | html :>}), |
| 62 | '<div>'; |
| 63 | } |
| 64 | |
| 65 | notescip-perl cpan Text-Xslate v3.5.9 main/note(). 'override html()'; |
| 66 | { |
| 67 | my $tx = Text::Xslate->newscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/new().( |
| 68 | cache => 0, |
| 69 | verbose => 2, |
| 70 | warn_handler => sub { diescip-perl cpan Text-Xslate v3.5.9 main/die(). @_scip-perl cpan Text-Xslate v3.5.9 main/`@_`. }, |
| 71 | |
| 72 | function => { |
| 73 | html => \&custom_html_filterscip-perl cpan Text-Xslate v3.5.9 main/custom_html_filter(). |
| 74 | }, |
| 75 | ); |
| 76 | |
| 77 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<div><: '<^_^>♥' :></div>}), |
| 78 | '<div><^_^>&hearts;</div>'; |
| 79 | |
| 80 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<div><: $foo :></div>}, { foo => '<^_^>♥' }), |
| 81 | '<div><^_^>&hearts;</div>'; |
| 82 | |
| 83 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' :>}), |
| 84 | '<div>'; |
| 85 | |
| 86 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' | raw :>}), |
| 87 | '<div>'; |
| 88 | |
| 89 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' | html :>}), |
| 90 | '<div>'; |
| 91 | |
| 92 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<div><: $foo | html :></div>}, { foo => '<^_^>♥' }), |
| 93 | '<div><^_^>♥</div>' or diescip-perl cpan Text-Xslate v3.5.9 main/die(). 'stop'; |
| 94 | } |
| 95 | |
| 96 | notescip-perl cpan Text-Xslate v3.5.9 main/note(). 'override html_escape() with type=text'; |
| 97 | { |
| 98 | my $tx_no_autoescape = Text::Xslate->newscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/new().( |
| 99 | cache => 0, |
| 100 | verbose => 2, |
| 101 | warn_handler => sub { diescip-perl cpan Text-Xslate v3.5.9 main/die(). @_scip-perl cpan Text-Xslate v3.5.9 main/`@_`. }, |
| 102 | type => 'text', |
| 103 | |
| 104 | function => { |
| 105 | html_escape => \&custom_html_escapescip-perl cpan Text-Xslate v3.5.9 main/custom_html_escape(). |
| 106 | }, |
| 107 | ); |
| 108 | |
| 109 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx_no_autoescape->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' :>}), |
| 110 | '<div>'; |
| 111 | |
| 112 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx_no_autoescape->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' | raw :>}), |
| 113 | '<div>'; |
| 114 | |
| 115 | isscip-perl cpan Text-Xslate v3.5.9 main/is(). $tx_no_autoescape->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/render_string().(q{<: '<div>' | html :>}), |
| 116 | '<div>'; |
| 117 | } |
| 118 | |
| 119 | done_testing; |
| 120 |