require('strict');
local utilities = require ('Module:WPSHIPS_utilities');local infobox_ship_flag = utilities._infobox_ship_flag;local ship_name_format = utilities._ship_name_format;local synonym_check = utilities._synonym_check;local unbulleted_list = utilities._unbulleted_list;
local get_args = require ('Module:Arguments').getArgs;
local data = mw.loadData ('Module:Infobox_ship/data');
local namespace = mw.title.getCurrentTitle.namespace;local has_unknown_params = false;
----------------------------< L I N E _ I T E M S >-----------------------------------------------------------------------------
spin through
local function line_items (args_t, params_t, infobox_ship_t, i, frame) for _, v in ipairs (params_t) do -- v is a sequence table with parameter name and associated infobox label if args_t[v[1]] then -- if parameter has a value infobox_ship_t['label' .. i] = v[2]; -- add the label infobox_ship_t['data' .. i] = unbulleted_list (args_t[v[1]]); -- and add the parameter value as data i = i + 1; -- bump the enumerator end endend
----------------------------< U N K N O W N _ P A R A M S _C H E C K >---------------------------------------
check parameters supplyed in against known parameters for that template. Emit preview warning whena parameter is unknown.
local function unknown_params_check (args_t, known_params_t, template) for k, v in pairs (args_t) do local param = k:gsub ('%d+$', '#'); -- for enumerated parameters, replace enumerator with '#' if not known_params_t[param] then -- add warning message when is not known for mw.addWarning (string.format (data.warning_fmt_str, data.warn_span_style, data.warn_code_style, template, template, data.warn_code_style, k, v)); has_unknown_params = (0
----------------------------< I N F O B O X _ S H I P _ B E G I N >------------------------------------------
fill infobox table parameters 'bodystyle' and 'title' (infobox caption); auto-article title formatting
local function infobox_ship_begin (args_t, infobox_ship_t, frame) infobox_ship_t['bodystyle'] = data.styles_t.mainbox; if args_t.infobox_caption then local name = mw.title.getCurrentTitle.text; if 'yes'
args_t.infobox_caption then -- format article title without disambiguation as infobox caption infobox_ship_t.title = ship_name_format ; else -- use value supplied in |infobox_caption= as infobox caption infobox_ship_t.title = args_t.infobox_caption; end else infobox_ship_t.title = ; -- to allow for possible displaytitle concatenation end
if args_t.display_title and ('none' ~= args_t.display_title) then -- any value but 'none' if 'ital'
--child= set to anything but 'yes'? How do that?
local function infobox_ship_image (frame) local args_t = get_args (frame); local infobox_ship_t =
unknown_params_check (args_t, data.known_infobox_ship_image_params_t, 'Infobox ship/image');
return frame:expandTemplate ; -- return a rendering of this infoboxend
--child= set to anything but 'yes'? How do that?
local function infobox_ship_career (frame) local args_t = get_args (frame); args_t.hide_header= args_t.hide_header and args_t.hide_header:lower; -- set to lowercase if set
local infobox_ship_t =
local i = 1;
if 'yes' ~= args_t.hide_header then -- |hide_header=yes then no header if not ('title'
infobox_ship_t.data1 = frame:expandTemplate ; -- return a rendering of this spoof infobox i = i + 1; end
if args_t.ship_country and args_t.ship_flag then infobox_ship_t['header' .. i] = infobox_ship_flag (args_t.ship_flag) .. '
' .. args_t.ship_country .. ''; elseif args_t.ship_country then infobox_ship_t['header' .. i] = args_t.ship_country; elseif args_t.ship_flag then infobox_ship_t['header' .. i] = infobox_ship_flag (args_t.ship_flag); end endif infobox_ship_t['header' .. i] then i = i + 1; end local error_flag; error_flag = synonym_check (args_t, 'ship_stricken', 'ship_struck', error_flag); -- error if both synonymous parameters set synonym_check (args_t, 'ship_honours', 'ship_honors', error_flag);
line_items (args_t, data.infobox_career_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters unknown_params_check (args_t, data.known_infobox_ship_career_params_t, 'Infobox ship/career');
return frame:expandTemplate ; -- return a rendering of this infoboxend
--child= set to anything but 'yes'? How do that?
local function infobox_ship_characteristics (frame) local args_t = get_args (frame); args_t.hide_header= args_t.hide_header and args_t.hide_header:lower; -- set to lowercase if set
local infobox_ship_t = local i = 1;
if 'yes' ~= args_t.hide_header then -- |hide_header=yes then no header local header = 'General characteristics'; -- the default header if args_t.header_caption then header = header .. ' ' .. args_t.header_caption; -- concatenate |header_caption= onto default header end infobox_ship_t['header' .. i] = header; -- add the header i = i + 1; -- bump the enumerator end
local error_flag; error_flag = synonym_check (args_t, 'ship_armour', 'ship_armor', error_flag); -- error if both synonymous parameters set synonym_check (args_t, 'ship_draught', 'ship_draft', error_flag); -- when both set modify with error message and category
line_items (args_t, data.infobox_characteristics_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters unknown_params_check (args_t, data.known_infobox_ship_characteristics_params_t, 'Infobox ship/characteristics');
return frame:expandTemplate ; -- return a rendering of this infoboxend
--child= set to anything but 'yes'? How do that?
local function infobox_ship_class_overview (frame) local args_t = get_args (frame); args_t.hide_header= args_t.hide_header and args_t.hide_header:lower; -- set to lowercase if set
local infobox_ship_t = local i = 1;
if 'yes' ~= args_t.hide_header then -- |hide_header=yes then no header infobox_ship_t['header' .. i] = 'Class overview'; -- add the header i = i + 1; -- bump the enumerator end
line_items (args_t, data.infobox_class_overview_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters unknown_params_check (args_t, data.known_infobox_ship_class_overview_params_t, 'Infobox ship/class');
return frame:expandTemplate ; -- return a rendering of this infoboxend
--is_ship= and |is_multi= parameters. Adds support for |hide_header= parameter
TODO: allow stand-alone when |child= set to anything but 'yes'? How do that?
local function infobox_ship_service_record (frame) local args_t = get_args (frame); args_t.hide_header= args_t.hide_header and args_t.hide_header:lower; -- set to lowercase if set
local infobox_ship_t = local i = 1;
if 'yes' ~= args_t.hide_header then -- |hide_header=yes then no header infobox_ship_t['header' .. i] = args_t.label or 'Service record'; -- add the header i = i + 1; -- bump the enumerator end
line_items (args_t, data.infobox_ship_service_record_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters unknown_params_check (args_t, data.known_infobox_ship_service_record_params_t, 'Infobox ship/service record');
return frame:expandTemplate ; -- return a rendering of this infoboxend
--infobox_ship}}
local function infobox_ship (frame) local args_t = get_args (frame);
local infobox_ship_t = -- table that holds infobox parameters
infobox_ship_begin (args_t, infobox_ship_t, frame);
for k, v in pairs (args_t) do -- copy infobox parameters from the frame into our local table local enum = k:match ('section(%d+)'); --
end unknown_params_check (args_t, data.known_infobox_ship_params_t, 'Infobox ship');
return frame:expandTemplate .. (has_unknown_params and '' or );end
----------------------------< E X P O R T S >----------------------------------------------------------------
return
Ship: | infobox_ship, infobox_ship_image = infobox_ship_image, infobox_ship_career = infobox_ship_career, infobox_ship_characteristics = infobox_ship_characteristics, infobox_ship_class_overview = infobox_ship_class_overview, infobox_ship_service_record = infobox_ship_service_record, |