]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Base.pm
Add form.js markup and CSS
[gruntmaster-page.git] / lib / Gruntmaster / Page / Base.pm
index 5b93f20992e00411b7d981f0af15edfc32a1e7c6..91c2764ffb6209e30a0d0a61c174cce81d212044 100644 (file)
@@ -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;
 
@@ -24,6 +25,10 @@ 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]->({qw/level debug message/ => $_[1]})
+       };
 }
 
 ##################################################
@@ -32,18 +37,46 @@ my %orig_header_templates = (
   en => <<'HTML',
 <!DOCTYPE html>
 <title>TITLE_GOES_HERE</title>
-<link rel="stylesheet" href="/gm.css">
-<script src="/zepto.var" defer></script>
-<script src="/view.js" defer></script>
-<script src="/form.js" defer></script>
 <meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+<link rel="stylesheet" href="/css/cyborg" id="stylesheet">
+<script src="/js" type="text/javascript"></script>
+
+<nav class="navbar navbar-default navbar-static-top" role="navigation">
+<div class="container-fluid">
+<div class="navbar-header">
+<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
+<a class="navbar-brand" href="/">Gruntmaster 6000</a>
+</div>
+
+<div class="collapse navbar-collapse">
+<ul class="nav navbar-nav">
+<li><a href="/pb/">Problems</a>
+<li><a href="/ct/">Contests</a>
+<li><a href="/account">Account</a>
+</ul>
+
+<ul class="nav navbar-nav navbar-right">
+<li><a class="dropdown-toggle" data-toggle="dropdown"> Theme <span class="caret"></span></a>
+
+<ul class="dropdown-menu" role="menu">
+<li><a href="#" id="theme_slate">Gunmetal gray</a>
+<li><a href="#" id="theme_cyborg">Black</a>
+<li><a href="#" id="theme_cerulean">White</a>
+<li><a href="#" id="theme_cosmo">Metro</a>
+</ul>
+
+<li><a href="/log/">Job log</a>
+</ul>
+</div>
+</div>
+</nav>
+
+<div class="container-fluid">
 
-<span id="admin"></span>
-<div id="title"><span class="i">i</span><span class="Eval">Eval</span></div>
 <div id="subtitle">TITLE_GOES_HERE</div>
-
-<nav><ul><li><a href="/learn.var">Learn</a><li><a href="/pb/">Practice</a><li><a href="/ct/">Compete</a><li><a href="/log/">Job log</a></ul></nav>
-
+<div id="result"></div>
 HTML
 );
 
@@ -59,7 +92,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.*>) {
@@ -70,19 +104,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 +131,19 @@ 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);
+       [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language'], [ encode 'UTF-8' => $htc->output ] ]
 }
 
 sub _generate {}
 
+sub variants {
+       [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ]
+}
+
 1
This page took 0.022882 seconds and 4 git commands to generate.