summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-10-29 11:52:16 -0400
committerJesse Luehrs <doy@tozt.net>2013-10-29 11:52:16 -0400
commitab2267eb083a301e120d6912e64b40eebf82666c (patch)
tree39647034a696246115888465f2017e847fb1a5bc
parent97305c7459993e61192b64628b601635a85dd9fc (diff)
downloadcatalyst-view-spreadsheet-template-ab2267eb083a301e120d6912e64b40eebf82666c.tar.gz
catalyst-view-spreadsheet-template-ab2267eb083a301e120d6912e64b40eebf82666c.zip
decode template files as utf8
-rw-r--r--lib/Catalyst/View/Spreadsheet/Template.pm2
-rw-r--r--t/lib/MyUTF8App.pm13
-rw-r--r--t/lib/MyUTF8App/Controller/Root.pm15
-rw-r--r--t/lib/MyUTF8App/View/Spreadsheet/Template.pm9
-rw-r--r--t/lib/MyUTF8App/root/index.json151
-rw-r--r--t/utf8.t329
6 files changed, 518 insertions, 1 deletions
diff --git a/lib/Catalyst/View/Spreadsheet/Template.pm b/lib/Catalyst/View/Spreadsheet/Template.pm
index 929a667..b381bec 100644
--- a/lib/Catalyst/View/Spreadsheet/Template.pm
+++ b/lib/Catalyst/View/Spreadsheet/Template.pm
@@ -137,7 +137,7 @@ sub render {
my ($c) = @_;
$self->renderer->render(
- scalar($self->template_file($c)->slurp),
+ scalar($self->template_file($c)->slurp(iomode => '<:encoding(UTF-8)')),
{
%{ $c->stash },
$self->catalyst_var => $c,
diff --git a/t/lib/MyUTF8App.pm b/t/lib/MyUTF8App.pm
new file mode 100644
index 0000000..f5c68e4
--- /dev/null
+++ b/t/lib/MyUTF8App.pm
@@ -0,0 +1,13 @@
+package MyUTF8App;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst';
+
+__PACKAGE__->config(
+ name => 'MyUTF8App',
+);
+
+__PACKAGE__->setup;
+
+1;
diff --git a/t/lib/MyUTF8App/Controller/Root.pm b/t/lib/MyUTF8App/Controller/Root.pm
new file mode 100644
index 0000000..c848f06
--- /dev/null
+++ b/t/lib/MyUTF8App/Controller/Root.pm
@@ -0,0 +1,15 @@
+package MyUTF8App::Controller::Root;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+__PACKAGE__->config(namespace => '');
+
+sub index :Path :Args(0) {}
+
+sub end : ActionClass('RenderView') {}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/lib/MyUTF8App/View/Spreadsheet/Template.pm b/t/lib/MyUTF8App/View/Spreadsheet/Template.pm
new file mode 100644
index 0000000..d1ea7f7
--- /dev/null
+++ b/t/lib/MyUTF8App/View/Spreadsheet/Template.pm
@@ -0,0 +1,9 @@
+package MyUTF8App::View::Spreadsheet::Template;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::View::Spreadsheet::Template';
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/lib/MyUTF8App/root/index.json b/t/lib/MyUTF8App/root/index.json
new file mode 100644
index 0000000..f127933
--- /dev/null
+++ b/t/lib/MyUTF8App/root/index.json
@@ -0,0 +1,151 @@
+{
+ "selection" : 0,
+ "worksheets" : [
+ {
+ "cells" : [
+ [
+ {
+ "contents" : "Colored Cell",
+ "format" : {
+ "bg_color" : "#9BBB59",
+ "color" : "#FFFF00",
+ "pattern" : "solid",
+ "size" : 12
+ },
+ "type" : "string"
+ },
+ {
+ "contents" : "Wide Cell (25.00)",
+ "type" : "string"
+ },
+ {
+ "contents" : "Bordered Cell w/ Text Wrap",
+ "format" : {
+ "border" : [
+ "thin",
+ "thin",
+ "thin",
+ "thin"
+ ],
+ "border_color" : [
+ "#000000",
+ "#000000",
+ "#000000",
+ "#000000"
+ ],
+ "text_wrap" : true
+ },
+ "type" : "string"
+ },
+ {
+ "contents" : "Middle Valigned",
+ "format" : {
+ "valign" : "vcenter"
+ },
+ "type" : "string"
+ },
+ {
+ "contents" : "Right Aligned and text wrapped",
+ "format" : {
+ "align" : "right",
+ "text_wrap" : true
+ },
+ "type" : "string"
+ }
+ ],
+ [
+ {},
+ {},
+ {},
+ {},
+ {}
+ ],
+ [
+ {
+ "contents" : 10,
+ "type" : "number"
+ },
+ {},
+ {},
+ {},
+ {}
+ ],
+ [
+ {
+ "contents" : 20,
+ "type" : "number"
+ },
+ {},
+ {},
+ {
+ "contents" : 2.5,
+ "format" : {
+ "num_format" : "\"¥\"#,##0.00"
+ },
+ "type" : "number"
+ },
+ {
+ "contents" : "« currency cell",
+ "format" : {
+ "align" : "center",
+ "color" : "#4BACC6",
+ "size" : 12
+ },
+ "type" : "string"
+ }
+ ],
+ [
+ {
+ "contents" : 30,
+ "type" : "number"
+ },
+ {},
+ {},
+ {},
+ {}
+ ],
+ [
+ {
+ "contents" : 60,
+ "formula" : "SUM(A3:A5)",
+ "type" : "number"
+ },
+ {
+ "contents" : "« formula cell",
+ "format" : {
+ "align" : "right",
+ "bg_color" : "#EEECE1",
+ "color" : "#F79646",
+ "pattern" : "solid",
+ "size" : 12
+ },
+ "type" : "string"
+ },
+ {},
+ {},
+ {}
+ ]
+ ],
+ "column_widths" : [
+ 10.83203125,
+ 25.83203125,
+ 10,
+ 15,
+ 18.1640625
+ ],
+ "name" : "Sheet1",
+ "row_heights" : [
+ 45,
+ 15,
+ 15,
+ 15,
+ 15,
+ 15
+ ],
+ "selection" : [
+ 3,
+ 4
+ ]
+ }
+ ]
+}
diff --git a/t/utf8.t b/t/utf8.t
new file mode 100644
index 0000000..0107ad1
--- /dev/null
+++ b/t/utf8.t
@@ -0,0 +1,329 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use lib 't/lib';
+
+use utf8;
+
+use Catalyst::Test 'MyUTF8App';
+use Spreadsheet::ParseXLSX;
+
+my $res = request('basic.xlsx');
+is($res->code, 200);
+
+my $data = $res->content;
+open my $fh, '<', \$data;
+my $wb = Spreadsheet::ParseXLSX->new->parse($fh);
+
+is($wb->worksheet_count, 1);
+
+my $ws = $wb->worksheet(0);
+is($ws->get_name, 'Sheet1');
+is_deeply([$ws->row_range], [0, 5]);
+is_deeply([$ws->col_range], [0, 4]);
+
+{
+ my $cell = $ws->get_cell(0, 0);
+ is($cell->unformatted, "Colored Cell");
+ is($cell->value, "Colored Cell");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [1, '#9BBB59', '#FFFFFF']);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ is($font->{Height}, 12);
+ is($font->{Color}, '#FFFF00');
+}
+
+{
+ my $cell = $ws->get_cell(0, 1);
+ is($cell->unformatted, "Wide Cell (25.00)");
+ is($cell->value, "Wide Cell (25.00)");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(0, 2);
+ is($cell->unformatted, "Bordered Cell w/ Text Wrap");
+ is($cell->value, "Bordered Cell w/ Text Wrap");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok($format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(1) x 4]);
+ is_deeply($format->{BdrColor}, [('#000000') x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(0, 3);
+ is($cell->unformatted, "Middle Valigned");
+ is($cell->value, "Middle Valigned");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 1);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(0, 4);
+ is($cell->unformatted, "Right Aligned and text wrapped");
+ is($cell->value, "Right Aligned and text wrapped");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 3);
+ is($format->{AlignV}, 2);
+ ok($format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (0..4) {
+ is($ws->get_cell(1, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(2, 0);
+ is($cell->unformatted, 10);
+ is($cell->value, 10);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (1..4) {
+ is($ws->get_cell(2, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(3, 0);
+ is($cell->unformatted, 20);
+ is($cell->value, 20);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (1..2) {
+ is($ws->get_cell(3, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(3, 3);
+ is($cell->unformatted, 2.5);
+ is($cell->value, "¥2.50");
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(3, 4);
+ is($cell->unformatted, "« currency cell");
+ is($cell->value, "« currency cell");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 2);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ is($font->{Height}, 12);
+ is($font->{Color}, '#4BACC6');
+}
+
+{
+ my $cell = $ws->get_cell(4, 0);
+ is($cell->unformatted, 30);
+ is($cell->value, 30);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (1..4) {
+ is($ws->get_cell(4, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(5, 0);
+ is($cell->unformatted, 60);
+ is($cell->value, 60);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, 'SUM(A3:A5)');
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(5, 1);
+ is($cell->unformatted, "« formula cell");
+ is($cell->value, "« formula cell");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 3);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [1, '#EEECE1', '#FFFFFF']);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ is($font->{Height}, 12);
+ is($font->{Color}, '#F79646');
+}
+
+for my $i (2..4) {
+ is($ws->get_cell(5, $i), undef);
+}
+
+
+done_testing;