X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FBase.pm;h=bc8e9cec1b176e81c63a37cb903cbf880fdd6206;hb=31d700150e564fd3bf0eb167ef416c87aed771eb;hp=a7188d7cd4e660b3c6371be00f316bf55f54cb6e;hpb=7dc3247307f2e86af154dc449224f22ba8923c79;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index a7188d7..bc8e9ce 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -4,6 +4,7 @@ use 5.014000; use strict; use warnings; +use Encode qw/encode/; use File::Slurp qw/read_file/; use HTML::Template::Compiled; @@ -26,8 +27,10 @@ sub import { *{"${caller}::TITLE"} = sub () { $title }; *{"${caller}::debug"} = sub { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; - $_[0]->({qw/level debug message/ => $_[1]}) + $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]}) }; + *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] } + } ################################################## @@ -36,21 +39,46 @@ my %orig_header_templates = ( en => <<'HTML', TITLE_GOES_HERE - - - - + - -
iEval
-
TITLE_GOES_HERE
+ + + + + +
+ +
TITLE_GOES_HERE
+
HTML ); @@ -66,7 +94,8 @@ HTML ); sub patch_templates { - my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return %{$_[0]}; + my $root = 'tmpl'; + return %{$_[0]} unless -d $root; my ($templates, $name) = @_; my %out = %$templates; for (<$root/$name.*>) { @@ -77,19 +106,15 @@ sub patch_templates { %out } -sub reload_templates (){ $ENV{GRUNTMASTER_RELOAD_TEMPLATES} } - my %header_templates = patch_templates \%orig_header_templates, 'header'; my %footer_templates = patch_templates \%orig_footer_templates, 'footer'; sub header{ my ($language, $title) = @_; - %header_templates = patch_templates \%orig_header_templates, 'header' if reload_templates; $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger; } sub footer{ - %footer_templates = patch_templates \%orig_footer_templates, 'footer' if reload_templates; $footer_templates{$_[0]}; } @@ -110,11 +135,11 @@ my %templates; sub generate{ my ($self, $lang, @args) = @_; - $templates{$self} = { cook_templates $self->TEMPLATES, $self->NAME => $self->TITLE } if !exists $templates{$self} or reload_templates; + $templates{$self} = { cook_templates $self->TEMPLATES, $self->NAME => $self->TITLE } unless exists $templates{$self}; my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',); $self->_generate($htc, $lang, @args); - [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1]], [ $htc->output ] ] + [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language'], [ encode 'UTF-8' => $htc->output ] ] } sub _generate {}