X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/08a379d96eaacbc1268c3f7aff9fb2bfcee80115..cf8d01da2735d21735d562e73009546d64125d4a:/writer.plp diff --git a/writer.plp b/writer.plp index 226aa4b..99a9736 100644 --- a/writer.plp +++ b/writer.plp @@ -205,6 +205,44 @@ else { } my $title = $row->{id} ? "entry #$row->{id}" : 'new entry'; + +package Shiar_Sheet::FormRow { + sub input { + my ($row, $col, $type, $label) = @_; + my $val = $row->{$col} // ''; + $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY'; + if (ref $type eq 'ARRAY') { + return ( + sprintf('', + ); + } + elsif ($type eq 'checkbox') { + return sprintf( + join('', + '', + ), $col, $type, !!$val && ' checked', $label + ); + } + else { + my $html = ''; + $html .= qq( $_="$type->{$_}") for sort keys %{$type // {}}; + return ( + $label ? sprintf('', $col, $label) : (), + sprintf('', + $col, PLP::Functions::EscapeHTML($val), $html + ), + ); + } + } +} +bless $row, 'Shiar_Sheet::FormRow'; :>

Words <:= $title :>

@@ -214,40 +252,21 @@ my $title = $row->{id} ? "entry #$row->{id}" : 'new entry';