Module:Infobox ship: Difference between revisions

Content deleted Content added
create;
 
No edit summary
Line 10:
 
local data = mw.loadData ('Module:Infobox_ship/data');
local has_unknown_params = false;
 
 
--[[--------------------------< L I N E _ I T E M S >-----------------------------------------------------------------------------
Line 16:
spin through <params_t> sequence. Get parameter name and matching infobox label. Look in <args_t> for parameter name. When parameter
name has a value, add infobox label and parameter value to the infobox table <infobox_ship_t>. <i> identifies where label and data
enumberatorsenumerators begin.
 
]]
Line 26:
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
end
end
 
 
--[[--------------------------< U N K N O W N _ P A R A M S _C H E C K >---------------------------------------
 
check parameters supplyed in <template> against known parameters for that template. Emit preview warning when
a parameter is unknown.
 
TODO: move styling to styles.css
 
]]
 
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 <param> is not known for <template>
mw.addWarning ('<span style="color:#d33"><code style="color: inherit; background: inherit; border: none; padding: inherit;">&#123;{'.. template .. '}}</code>: unknown parameter: <code style="color: inherit; background: inherit; border: none; padding: inherit;">|' .. k .. '=' .. v .. '</code></span>');
-- has_unknown_params = true; -- TODO: uncomment to enable categorization -- add unknown params category when infobox is rendered
end
end
Line 77 ⟶ 97:
caption1 = args_t.image_caption;
}
 
unknown_params_check (args_t, data.known_infobox_ship_image_params_t, 'Infobox ship/image');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 132 ⟶ 154:
 
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 ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 170 ⟶ 193:
 
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 ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 200 ⟶ 224:
 
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 ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 231 ⟶ 256:
 
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 ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 258 ⟶ 284:
 
end
unknown_params_check (args_t, data.known_infobox_ship_params_t, 'Infobox ship');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}) .. (has_unknown_params and '[[Category:Pages using infobox ship with unknown parameters]]' or '');
end