Revision b251cc22
Von Sven Schöling vor mehr als 9 Jahren hinzugefügt
scripts/migrate_menu.pl | ||
---|---|---|
105 | 105 |
} |
106 | 106 |
|
107 | 107 |
open my $out_file, '>:utf8', $new_file or die $!; |
108 |
print $out_file YAML::Dump(\@menu_items); |
|
108 |
print $out_file yaml_dump(\@menu_items); |
|
109 |
} |
|
110 |
|
|
111 |
sub yaml_dump { |
|
112 |
my ($ary_ref) = @_; |
|
113 |
# YAML dumps keys lexically sorted, which isn't what we want. |
|
114 |
# we want this order: |
|
115 |
my @order = qw( |
|
116 |
parent |
|
117 |
id |
|
118 |
name |
|
119 |
icon |
|
120 |
order |
|
121 |
access |
|
122 |
href |
|
123 |
module |
|
124 |
target |
|
125 |
params |
|
126 |
); |
|
127 |
|
|
128 |
# ...oh and we want action in params first |
|
129 |
# |
|
130 |
# why this? because: |
|
131 |
# 1. parent is what is used to anchor. one could argue that id should be |
|
132 |
# first, but parent is easier for understanding structure. |
|
133 |
# 2. after parent the logical structure is |
|
134 |
# 1. id |
|
135 |
# 2. stuff related to vidual presentation (name/icon) |
|
136 |
# 3. stuff needed for logical presentaion (order/access) |
|
137 |
# 4. stuff related to the action after clicking it |
|
138 |
# 3. without parent and href (the second is pretty rare) the keys are nicely |
|
139 |
# ascending in length, which is very easy to parse visually. |
|
140 |
|
|
141 |
my $yaml = "---\n"; |
|
142 |
for my $node (@$ary_ref) { |
|
143 |
my $first = 0; |
|
144 |
for my $key (@order) { |
|
145 |
next unless exists $node->{$key}; |
|
146 |
$yaml .= ($first++ ? ' ' : '- ') . $key . ": "; |
|
147 |
if (!ref $node->{$key}) { |
|
148 |
$yaml .= $node->{$key} . "\n"; |
|
149 |
} else { |
|
150 |
$yaml .= "\n"; |
|
151 |
for ('action', grep !/^action$/, keys %{ $node->{$key} }) { |
|
152 |
next unless exists $node->{$key}{$_}; |
|
153 |
$yaml .= " $_: $node->{$key}{$_}\n"; |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
$yaml; |
|
109 | 161 |
} |
110 | 162 |
|
111 | 163 |
while (my ($in, $out) = each(%menu_files)) { |
Auch abrufbar als: Unified diff
Menüstruktur auf YAML geändert