X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FWeb%2FOof.pm;h=9c62d54214b154020c066f3554f17c82267683bc;hb=2f1de030471417c7be33909e5787d2b42343c6a7;hp=186fb2fc4e931df41d8b01ac51efa4ed90b8b99e;hpb=a9e59992ff637f0e320ac0af63340b17063ddea3;p=app-web-oof.git diff --git a/lib/App/Web/Oof.pm b/lib/App/Web/Oof.pm index 186fb2f..9c62d54 100644 --- a/lib/App/Web/Oof.pm +++ b/lib/App/Web/Oof.pm @@ -44,7 +44,7 @@ my $postage_per_item = $ENV{OOF_POSTAGE_PER_ITEM} // 50; ################################################## my %db; -my ($form, $continue, $order, $details, $pay, $display); +my ($form, $continue, $order, $details, $pay, $display, $down); { sub parse_html { @@ -60,6 +60,7 @@ my ($form, $continue, $order, $details, $pay, $display); $details = parse_html 'details'; $pay = parse_html 'pay'; $display = parse_html 'display'; + $down = parse_html 'down'; } sub stringify_money { sprintf "£%.2f", $_[0] / 100 } @@ -281,6 +282,17 @@ sub details_app { $tree->fid('pictures')->find('li')->iter3(\@pics, \&details_list_element); $tree->fid('jsonld')->replace_content(encode_json product_to_schemaorg '', %data); + $tree->fid('dd_stock')->replace_content($data{stock}); + $tree->fid('dd_price')->replace_content(stringify_money $data{price}); + for (qw/brand model/) { + if ($data{$_}) { + $tree->fid("dd_$_")->replace_content($data{$_}); + } else { + $tree->fid("dt_$_")->detach; + $tree->fid("dd_$_")->detach; + } + } + for my $ahref ($tree->find('a')) { $ahref->attr(href => "/form?highlight=$id") if $ahref->attr('href') eq '/'; } @@ -349,6 +361,18 @@ sub app { $res; } }; + enable sub { + my $app = shift; + sub { + if (-f 'down.html') { + my $down_lit = HTML::Element::Library::super_literal read_file 'down.html'; + my $tree = $down->clone; + $tree->fid('content')->replace_content($down_lit); + return [503, ['Content-type' => 'text/html; charset=utf-8'], [$tree->as_HTML]] + } + $app->(@_) + } + }; mount '/' => sub { [301, [Location => '/form'], []] }; mount '/form' => \&form_app; mount '/continue' => \&continue_app;