X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster%2FHTML.pm;h=8ddd9e1971b3170e9b8380be1a3d606ec2319d6c;hb=7cbc093ea2bc5b60c8882ea2358af8cb200e58fc;hp=a59533192315644b2568cab013c5fb89c00c1409;hpb=838663d1450cf5606e59c30966e2e56b0f787416;p=gruntmaster-page.git diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index a595331..8ddd9e1 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -4,12 +4,18 @@ use parent qw/Exporter/; our @EXPORT = qw/render render_article/; use File::Slurp qw/read_file/; -use HTML::Seamstress; +use HTML::Element::Library; +use HTML::TreeBuilder; use POSIX qw//; use Data::Dumper qw/Dumper/; sub ftime ($) { POSIX::strftime '%c', localtime shift } -sub literal ($) { HTML::Element::Library::super_literal shift // '' } +sub literal ($) { + my $b = HTML::TreeBuilder->new; + $b->ignore_unknown(0); + $b->parse(shift // ''); + HTML::Element::Library::super_literal $b->guts->as_HTML; +} sub HTML::Element::edit_href { my ($self, $sub) = @_; @@ -45,7 +51,7 @@ sub HTML::Element::namedlink { my %page_cache; for () { my ($tmpl, $lang) = m,tmpl/(\w+)\.(\w+),; - my $builder = HTML::Seamstress->new; + my $builder = HTML::TreeBuilder->new; $builder->ignore_unknown(0); $page_cache{$tmpl, $lang} = $builder->parse_file($_); } @@ -74,13 +80,17 @@ sub _render { $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('defmap')}); + $_->attr('smap', undef) for $tree->look_down(sub {$_[0]->attr('smap')}); $tree->as_HTML; } +my $logo = read_file 'mclogo.svg'; +$logo =~ y/\n//d; +$logo =~ s/(\s+)/ /g; + sub process_skel { my ($tree, %args) = @_; - $tree->fid('logo')->replace_with(literal scalar read_file "mclogo.svg"); + $tree->fid('logo')->replace_with(literal $logo); $tree->content_handler( title => $args{title}, content => literal $args{meat}); @@ -264,6 +274,10 @@ 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 {