X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/15b1558e299f3143ec8d89293674f9bab6ad61ed..b251cc22f355941217493073e124ba3878d5530f:/scripts/migrate_menu.pl diff --git a/scripts/migrate_menu.pl b/scripts/migrate_menu.pl index af295c777..a0cdae80d 100644 --- a/scripts/migrate_menu.pl +++ b/scripts/migrate_menu.pl @@ -105,7 +105,59 @@ sub translate_to_yaml { } open my $out_file, '>:utf8', $new_file or die $!; - print $out_file YAML::Dump(\@menu_items); + print $out_file yaml_dump(\@menu_items); +} + +sub yaml_dump { + my ($ary_ref) = @_; + # YAML dumps keys lexically sorted, which isn't what we want. + # we want this order: + my @order = qw( + parent + id + name + icon + order + access + href + module + target + params + ); + + # ...oh and we want action in params first + # + # why this? because: + # 1. parent is what is used to anchor. one could argue that id should be + # first, but parent is easier for understanding structure. + # 2. after parent the logical structure is + # 1. id + # 2. stuff related to vidual presentation (name/icon) + # 3. stuff needed for logical presentaion (order/access) + # 4. stuff related to the action after clicking it + # 3. without parent and href (the second is pretty rare) the keys are nicely + # ascending in length, which is very easy to parse visually. + + my $yaml = "---\n"; + for my $node (@$ary_ref) { + my $first = 0; + for my $key (@order) { + next unless exists $node->{$key}; + $yaml .= ($first++ ? ' ' : '- ') . $key . ": "; + if (!ref $node->{$key}) { + $yaml .= $node->{$key} . "\n"; + } else { + $yaml .= "\n"; + for ('action', grep !/^action$/, keys %{ $node->{$key} }) { + next unless exists $node->{$key}{$_}; + $yaml .= " $_: $node->{$key}{$_}\n"; + } + } + + } + } + + $yaml; } while (my ($in, $out) = each(%menu_files)) {