X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;ds=inline;f=lib%2FGruntmaster%2FPage%2FBase.pm;h=cf29eacc3c56962148f012739c16bc36b0260aee;hb=6b5b5f177f66282e6ffb0166b4f73ae933777f9f;hp=7fa14970be31f20d32d6c0445e21edbfca22aa60;hpb=bb95f538bf263c0294d87cfb90d58c66117b9aab;p=plack-app-gruntmaster.git
diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm
index 7fa1497..cf29eac 100644
--- a/lib/Gruntmaster/Page/Base.pm
+++ b/lib/Gruntmaster/Page/Base.pm
@@ -12,6 +12,9 @@ use HTML::Template::Compiled;
use POSIX ();
use Gruntmaster::Data ();
use List::Util ();
+use LWP::UserAgent;
+
+my $ua = LWP::UserAgent->new;
sub import {
my $caller = caller;
@@ -24,6 +27,16 @@ sub import {
*{"${caller}::strftime"} = \&POSIX::strftime;
*{"${caller}::NAME"} = sub () { $name };
*{"${caller}::TITLE"} = sub () { $title };
+ *{"${caller}::debug"} = sub {
+ local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
+ $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]})
+ };
+ *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] };
+ *{"${caller}::purge"} = sub {
+ return unless $ENV{PURGE_HOST};
+ my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]");
+ $ua->request($req)
+ };
}
##################################################
@@ -32,18 +45,46 @@ my %orig_header_templates = (
en => <<'HTML',
+
+
TITLE_GOES_HERE
+
HTML
);
@@ -59,10 +100,11 @@ HTML
);
sub patch_templates {
- my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return;
+ my $root = 'tmpl';
+ return %{$_[0]} unless -d $root;
my ($templates, $name) = @_;
my %out = %$templates;
- for (<$root/$name*>) {
+ for (<$root/$name.*>) {
m/\.(.+)$/;
$out{$1} = read_file $_
}
@@ -70,19 +112,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]};
}
@@ -101,15 +139,21 @@ sub cook_templates {
my %templates;
sub generate{
- my ($self, $path, $lang) = @_;
+ 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, $path, $lang);
- $htc->output
+ $self->_generate($htc, $lang, @args);
+ my $out = $htc->output;
+ utf8::downgrade($out);
+ [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ $out ] ]
}
sub _generate {}
+sub variants {
+ [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ]
+}
+
1