From: Marius Gavrilescu Date: Sat, 21 Mar 2015 17:04:21 +0000 (+0200) Subject: Add static mode X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=6533844f1a2ec6b162b696c31a623a4dc8ee72bb;p=plack-app-gruntmaster.git Add static mode --- diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 9284acc..c9965d0 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -114,10 +114,11 @@ sub dispatch_request{ response_filter { my ($r) = @_; return $r if ref $r ne 'Plack::App::Gruntmaster::Response'; - my @hdrs = ('X-Forever' => 1, 'Cache-Control' => "$privacy, max-age=$r->{maxage}"); - push @hdrs, Vary => 'Authorization' if $privacy eq 'private'; + my $vary = 'X-Static'; + $vary .= ', Authorization' if $privacy eq 'private'; + my @hdrs = ('X-Forever' => 1, 'Cache-Control' => "$privacy, max-age=$r->{maxage}", Vary => $vary); return [200, ['Content-Type' => 'application/json; charset=utf-8', @hdrs], [encode_json $r->{params}]] if $format eq 'json'; - my $ret = render $r->{template}, 'en', title => $r->{title}, %{$r->{params}}; + my $ret = render $r->{template}, 'en', title => $r->{title}, %{$r->{params}}, maybe static => $env->{HTTP_X_STATIC} + 1; [200, ['Content-Type' => 'text/html; charset=utf-8', @hdrs], [encode 'UTF-8', $ret]] }, }, @@ -182,7 +183,7 @@ sub dispatch_request{ sub (/) { redispatch_to '/index' }, sub (/favicon.ico) { redirect '/static/favicon.ico' }, - sub (/:article) { [200, ['Content-Type' => 'text/html; charset=utf-8', 'Cache-Control' => 'public, max-age=3600', 'X-Forever' => 1], [render_article $_{article}, 'en']] } + sub (/:article) { [200, ['Content-Type' => 'text/html; charset=utf-8', 'Cache-Control' => 'public, max-age=3600', 'X-Forever' => 1, Vary => 'X-Static'], [render_article $_{article}, 'en', maybe static => $env->{HTTP_X_STATIC}]] } }, sub (POST) { diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index 1e0f788..3195b62 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -50,11 +50,11 @@ sub render { } sub render_article { - my ($art, $lang) = @_; + my ($art, $lang, %args) = @_; $lang //= 'en'; my $title = read_file "a/$art.$lang.title"; my $meat = read_file "a/$art.$lang"; - _render('skel', $lang, title => $title , meat => $meat) + _render('skel', $lang, title => $title , meat => $meat, %args) } sub _render { @@ -66,6 +66,8 @@ sub _render { $tree->defmap(smap => \%args); my $process = __PACKAGE__->can("process_$tmpl"); $process->($tree, %args) if $process; + $_->detach for $tree->look_down(static => $args{static} ? 'no' : 'yes'); + $_->attr('static', undef) for $tree->look_down(sub {$_[0]->attr('static')}); $tree->as_HTML; } diff --git a/tmpl/pb_entry.en b/tmpl/pb_entry.en index 8246c42..6398e63 100644 --- a/tmpl/pb_entry.en +++ b/tmpl/pb_entry.en @@ -16,14 +16,14 @@ Job log
Solution -

Submit solution

+

Submit solution

The contest has finished.
To submit solutions to this problem, please visit the problem outside the contest.
-
+
diff --git a/tmpl/skel.en b/tmpl/skel.en index 39b4dda..6ae836a 100644 --- a/tmpl/skel.en +++ b/tmpl/skel.en @@ -17,7 +17,7 @@