#
#
# show_option_infos.cfv
#
# This shows all option_info shortcuts
# at a glance, collected from option_info.
# It checks for duplicate shortcuts, empty labels and descriptions.
#
#
include "docs.english.util"; # KHP-RC, "docs.util" should work as well but it does not!
include "templates.util.encoding";
subroutine(show_option_infos, (
debug_message("\n\n#### show_option_infos() \n");
#
#
# Track all shortcuts in "v.temp_debug.shortcuts", i.e.:
# v.temp_debug.shortcuts.rn = 1
# v.temp_debug.shortcuts.p = 1
# v.temp_debug.shortcuts.f = 2 --> The number indicates of how often a specific shortcut occurs, that's how we check for duplicates
#
#
delete_node("v.temp_debug");
v.temp_debug.shortcuts = "";
v.temp_debug.number_of_options = 0;
subroutine(build_header_row, (
'
\n';
'Shortcut | ';
'Name | ';
'Type | ';
'Label | ';
# 'Path | ';
'Description | ';
'
\n';
));
subroutine(handle_shortcut(
string shortcut), (
int count = 1;
if (?("v.temp_debug.shortcuts." . shortcut)) then (
# shortcut already exists
count = @("v.temp_debug.shortcuts." . shortcut) + 1;
);
"v.temp_debug.shortcuts." . shortcut = count;
));
subroutine(handle_option(
node the_option), (
debug_message("\n\n#### handle_option() \n");
debug_message("#### the_option : " . node_as_string(the_option) . "\n");
int option_number = @("v.temp_debug.number_of_options") + 1;
v.temp_debug.number_of_options = option_number;
string option_path = the_option;
string option_name = node_name(the_option);
string option_type;
string shortcut;
string lang_options_path = replace_first(option_path, "option_info.", "lang_options.");
string option_label;
string short_description;
string long_description;
string description;
node item;
string item_name;
bool item_has_subnodes = false;
# Note, if one item of the option node has subnodes we indicate
# that the item has subitems which are displayed in separate table
# below the current group
foreach item the_option (
if (num_subnodes(item) == 0) then (
item_name = node_name(item);
if (item_name eq "type") then (
option_type = @item;
)
else if (item_name eq "shortcut") then (
shortcut = @item;
if (shortcut ne "") then (
handle_shortcut(shortcut);
shortcut = "-" . shortcut;
);
);
)
else (
item_has_subnodes = true;
);
);
if (item_has_subnodes) then (
option_name .= '
(Item is a group of other items, see next table)
';
);
# Handle language variables
if (?(lang_options_path)) then (
# debug_message("#### lang_options_path : " . lang_options_path . "\n");
if (?(lang_options_path . ".label")) then (
option_label = @(lang_options_path . ".label");
);
if (?(lang_options_path . ".short_description")) then (
short_description = @(lang_options_path . ".short_description");
);
if (?(lang_options_path . ".long_description")) then (
long_description = expand(@(lang_options_path . ".long_description"));
);
if (short_description ne "" or long_description ne "") then (
# description = "Short
" . string_to_html(short_description) . "
Long
" . string_to_html(long_description);
description = "Short
" . string_to_html(short_description) . "
Long
" . long_description;
);
);
'\n';
'' . shortcut . ' | ';
'' . option_name . ' | ';
'' . option_type . ' | ';
'' . option_label . ' | ';
'' . description . ' | ';
'
\n';
));
subroutine(build_options_group(
node the_group), (
string group_label = replace_first(the_group, "option_info.", "");
if (contains(group_label, ".")) then (
group_label = replace_all(group_label, ".", " > ");
);
'' . group_label . '
';
'';
build_header_row();
node group_item;
foreach group_item the_group (
handle_option(group_item);
);
'
';
# If the_group contains a shortcut node there must be some mismatch
if (the_group?{"shortcut"}) then (
string shortcut = @the_group{"shortcut"};
'';
'There must be some mismatch in above group because it contains a shortcut node!
';
'Shortcut: ' . shortcut . '
';
'
';
handle_shortcut(shortcut);
);
#
#
# It is possible that a subitem of this group contains another group, however, we
# need to start a new group, hence we do it here!
#
#
node subitem;
bool is_subitem_group;
foreach group_item the_group (
is_subitem_group = false;
foreach subitem group_item (
if (num_subnodes(subitem) > 0) then (
# debug_message("\n#### K group_item: " . group_item . "\n");
# debug_message("#### K subitem: " . subitem . "\n\n");
# This item must be another group
is_subitem_group = true;
last;
);
);
if (is_subitem_group) then (
build_options_group(group_item);
);
);
));
subroutine(collect_options(
node the_options), (
# debug_message("#### collect_options:\n" . node_as_string(the_options) . "\n");
node item;
node subitem;
foreach item the_options (
debug_message("#### collect_options - " . node_name(item) . "\n");
# DEBUG_BEGIN
#if (node_name(item) eq "source") then (
# debug_message("GOT LOG SOURCE:\n" . node_as_string(item) . "\n");
#);
# DEBUG_END
# Check if we are at a node which is the group node for one or more options
node first_subnode = subnode_by_number(item, 0);
bool is_options_group_node = true;
foreach subitem first_subnode (
if (num_subnodes(subitem) > 0) then (
is_options_group_node = false;
last;
);
);
if (is_options_group_node) then (
build_options_group(item);
)
else (
collect_options(item);
);
);
));
'Option Infos
';
"This is a summary of all option infos.
";
string html = collect_options("option_info");
node debug = "v.temp_debug";
debug_message("\n" . node_as_string(debug) . "\n");
node debug_shortcuts = debug{"shortcuts"};
int number_of_options = @debug{"number_of_options"};
int number_of_shortcuts = num_subnodes(debug_shortcuts);
int number_of_duplicate_shortcuts = 0;
string duplicate_shortcuts;
# Check for duplicate shortcuts
node item;
foreach item debug_shortcuts (
if (@item > 1) then (
number_of_duplicate_shortcuts++;
duplicate_shortcuts .= "-" . node_name(item) . " (" . @item . ")
";
);
);
#
#
# Summary table
#
#
'';
'\n';
'Number of options: | ';
'' . number_of_options . ' | ';
'
\n';
'\n';
'Number of shortcuts: | ';
'' . number_of_shortcuts . ' | ';
'
\n';
'\n';
'Number of duplicate shortcuts: | ';
'' . number_of_duplicate_shortcuts . ' | ';
'
\n';
'\n';
'Duplicate shortcuts: | ';
'' . duplicate_shortcuts . ' | ';
'
\n';
'
';
#
#
# Option detail tables
#
#
html;
debug_message("#### option_info.profile.log:\n" . node_as_string("option_info.profile.log") . "\n");
));