Module:Template input utils: Difference between revisions
to-table functions remove original values from args table; this is now toggleable |
mNo edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
-- TODO: move tip functions here? See [[Module:Template input parse]] | -- TODO: move tip functions here? See [[Module:Template input parse]] | ||
-- TODO: | |||
-- Add param name normalization: params close enough to snake_case are normal- | |||
-- ized to snake_case | |||
-- 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. | -- - Numbered <anything> to table extract args and places them into a table. | ||
-- Normalize params to snake case (may change to a different form later); | |||
-- anything close enough to snake case is converted to snake case: | |||
-- TRAIN_CASE, KEBEB-CASE, no dashes (OK!) | |||
-- PascalCase, camelCase (will not convert properly) | |||
-- Function work-in-progress | |||
function p.normalize_params(args) | |||
-- Local function for normalizing strings | |||
-- Spaces and dashes turn into underscores | |||
-- and all capital letters become lowercase | |||
local function normalize(input_string) | |||
local cleaned_string = string.gsub(string.lower(input_string), "[%-%s]", "_") | |||
end | |||
end | |||
-- 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 38: | Line 58: | ||
-- 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.numbered_header_data_args_to_table(args, max_num, header_fmt, data_fmt | function p.numbered_header_data_args_to_table(args, max_num, keep_originals, is_strict_pair, header_fmt, data_fmt) | ||
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" | ||