X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/8817f25b3b69622f98edfc74393ae8d88f827b7a..7af2b12887c4b1cb0cb427960c57f5b777b85315:/scripts/generate_client_js_actions.pl diff --git a/scripts/generate_client_js_actions.pl b/scripts/generate_client_js_actions.pl new file mode 100755 index 000000000..b2598b39e --- /dev/null +++ b/scripts/generate_client_js_actions.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use File::Slurp; +use List::Util qw(first max); + +my $file_name = (first { -f } qw(SL/ClientJS.pm ../SL/ClientJS.pm)) || die "ClientJS.pm not found"; +my @actions; + +foreach (read_file($file_name)) { + chomp; + + next unless (m/^my \%supported_methods/ .. m/^\);/); + + push @actions, [ 'action', $1, $2 ] if m/^\s+([a-zA-Z]+)\s*=>\s*(\d+),$/; + push @actions, [ 'comment', $1 ] if m/^\s+#\s+(.+)/; +} + +my $longest = max map { length($_->[1]) } grep { $_->[0] eq 'action' } @actions; +my $first = 1; +my $output; + +# else if (action[0] == 'hide') $(action[1]).hide(); +foreach my $action (@actions) { + if ($action->[0] eq 'comment') { + print "\n" unless $first; + print " // ", $action->[1], "\n"; + + } else { + my $args = $action->[2] == 1 ? '' : join(', ', map { "action[$_]" } (2..$action->[2])); + + printf(' %s if (action[0] == \'%s\')%s $(action[1]).%s(%s);' . "\n", + $first ? ' ' : 'else', + $action->[1], + ' ' x ($longest - length($action->[1])), + $action->[1], + $args); + $first = 0; + } +} + +printf "\n else\%sconsole.log('Unknown action: ' + action[0]);\n", ' ' x (4 + 2 + 6 + 3 + 4 + 2 + $longest + 1);