summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-10-29 10:13:26 -0400
committerJesse Luehrs <doy@tozt.net>2013-10-29 10:13:26 -0400
commit95e314227491736459ae2a651c9148216f9980d4 (patch)
tree8266a123e079d7f108d6f4e71f9f79d2780b58b2 /lib
parent0bb1e9c969aac5ca9d924ccacfa5b21076aba806 (diff)
downloadspreadsheet-template-95e314227491736459ae2a651c9148216f9980d4.tar.gz
spreadsheet-template-95e314227491736459ae2a651c9148216f9980d4.zip
add a utf8 decoder helper
xslate doesn't provide any way to mark code inside template files as utf8, so strings in that code end up as undecoded strings, even if the rest of the template file itself is decoded. this provides a helper function you can use in your templates to explicitly decode the strings. if this ever gets fixed in xslate, i'll be able to just conditionally turn this helper function into a noop, so it shouldn't really affect forwards compatibility.
Diffstat (limited to 'lib')
-rw-r--r--lib/Spreadsheet/Template/Helpers/Xslate.pm10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Spreadsheet/Template/Helpers/Xslate.pm b/lib/Spreadsheet/Template/Helpers/Xslate.pm
index 56df981..a05ff0a 100644
--- a/lib/Spreadsheet/Template/Helpers/Xslate.pm
+++ b/lib/Spreadsheet/Template/Helpers/Xslate.pm
@@ -2,6 +2,7 @@ package Spreadsheet::Template::Helpers::Xslate;
use strict;
use warnings;
+use Encode;
use JSON;
my $JSON = JSON->new;
@@ -10,10 +11,10 @@ use Sub::Exporter 'build_exporter';
my $import = build_exporter({
exports => [
- map { $_ => \&_curry_package } qw(format c merge true false)
+ map { $_ => \&_curry_package } qw(format c merge true false u)
],
groups => {
- default => [qw(format c merge true false)],
+ default => [qw(format c merge true false u)],
},
});
@@ -65,6 +66,11 @@ sub merge {
sub true { JSON::true }
sub false { JSON::false }
+sub u {
+ my ($package, $str) = @_;
+ return Encode::decode('UTF-8', $str, Encode::FB_CROAK)
+}
+
sub _parse_range {
my ($range) = @_;