Module:Template input utils: Difference between revisions
m move tester last |
m minor renaming |
||
| Line 5: | Line 5: | ||
-- Library module for common operations with handling template input. | -- Library module for common operations with handling template input. | ||
-- - Numbered <anything> to table extract args and places them into a table. | |||
-- Extracts numbered args (from frame.args) and stores them into one table. | -- Extracts numbered args (from frame.args) and stores them into one table. | ||
| Line 34: | Line 35: | ||
-- table, as it may require further processing (EG, parsing to number, ratio, | -- table, as it may require further processing (EG, parsing to number, ratio, | ||
-- kv-pairs, etc). | -- kv-pairs, etc). | ||
function p. | function p.numbered_header_data_args_to_table(args, max_num, header_fmt, data_fmt, is_strict_pair) | ||
local max_num = max_num or 100 | local max_num = max_num or 100 | ||
local header_fmt = header_fmt or "Header %d" | local header_fmt = header_fmt or "Header %d" | ||
| Line 68: | Line 69: | ||
-- Some older infoboxes use a jagged array instead of an assoc-array, so convert | -- Some older infoboxes use a jagged array instead of an assoc-array, so convert | ||
-- two-element tables into a header-data pair, and one-element tables into | -- two-element tables into a header-data pair, and one-element tables into | ||
-- either a headerless data row, or a dataless header row. This may | -- either a headerless data row, or a dataless header row. | ||
-- easier to work with. | -- Default is to interpret size-1 arrays as data rows, which corresponds to how | ||
-- the infobox worked before it became template-ified. This old input method may | |||
-- be easier to work with. | |||
function p.jagged_array_to_header_data_pairs(rows, is_header_row) | function p.jagged_array_to_header_data_pairs(rows, is_header_row) | ||
local is_header_row = is_header_row or false | local is_header_row = is_header_row or false | ||
| Line 97: | Line 99: | ||
--test_args["Entries"] = p.numbered_args_to_table(test_args, "Entry %d", 10) | --test_args["Entries"] = p.numbered_args_to_table(test_args, "Entry %d", 10) | ||
test_args["Entries"] = p. | test_args["Entries"] = p.numbered_header_data_args_to_table(test_args, 10, "Header %d", "Entry %d") | ||
return test_args | return test_args | ||
end | end | ||
return p | return p | ||