X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster%2FHTML.pm;h=f08b66be3faadb6dca1b64fa77105410e700cb2f;hb=928a611fa7fa8f1eb3c8689dd6f83890bf190728;hp=ebbc145e22cd3bd9f328c3e3a8da27b749d9e9c8;hpb=cc11db2f3c4006b4f3d3a5a5ab58eb30bf907441;p=plack-app-gruntmaster.git diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index ebbc145..f08b66b 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -9,8 +9,17 @@ use HTML::TreeBuilder; use POSIX qw//; use Data::Dumper qw/Dumper/; +my $optional_end_tags = {%HTML::Tagset::optionalEndTag, tr => 1, td => 1, th => 1}; + sub ftime ($) { POSIX::strftime '%c', localtime shift } -sub literal ($) { HTML::Element::Library::super_literal shift // '' } +sub literal ($) { + my ($html) = @_; + return unless $html; + my $b = HTML::TreeBuilder->new; + $b->ignore_unknown(0); + $b->parse($html); + HTML::Element::Library::super_literal $b->guts->as_HTML(undef, undef, $optional_end_tags); +} sub HTML::Element::edit_href { my ($self, $sub) = @_; @@ -55,13 +64,22 @@ sub render { my ($tmpl, $lang, %args) = @_; $lang //= 'en'; my $meat = _render($tmpl, $lang, %args); - _render('skel', $lang, %args, meat => $meat) + my $html = _render('skel', $lang, %args, meat => $meat); + if ($tmpl eq 'pb_entry') { # Move sidebar to correct position + my $builder = HTML::TreeBuilder->new; + $builder->ignore_unknown(0); + my $tree = $builder->parse_content($html); + $tree->fid('content')->postinsert($tree->fid('sidebar')); + $html = $tree->as_HTML(undef, undef, $optional_end_tags) + } + $html } sub render_article { my ($art, $lang, %args) = @_; $lang //= 'en'; my $title = read_file "a/$art.$lang.title"; + chomp $title; my $meat = read_file "a/$art.$lang"; _render('skel', $lang, title => $title , meat => $meat, %args) } @@ -73,10 +91,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')}); $_->attr('smap', undef) for $tree->look_down(sub {$_[0]->attr('smap')}); - $tree->as_HTML; + $tree->as_HTML(undef, undef, $optional_end_tags); } sub process_skel { @@ -175,7 +191,7 @@ sub process_pb_entry { $tree->fid('job_log')->edit_href(sub{$_ .= "&private=$args{private}"}) if $args{private}; $tree->fid('solution')->detach unless $args{solution}; $_->detach for $tree->fclass('rc'); # requires contest - $tree->fid('solution_modal')->fclass('modal-body')->replace_content(literal $args{solution}); + $tree->fid('solution_modal')->replace_content(literal $args{solution}); } if ($args{cansubmit}) { $tree->fid('nosubmit')->detach; @@ -267,10 +283,6 @@ sub process_log { $elem->find('a')->edit_href(sub{s/$/&$str/}) if $str; } $tree->fclass('current')->replace_content("Page $args{current_page} of $args{last_page}"); - - my @detach; - push @detach, $args{args}{$_} ? $tree->fclass($_) : () for qw/problem contest owner/; - $_->detach for @detach; } sub process_st {