Module:InfoboxCreator: Difference between revisions
Appearance
Godman Andrew (talk | contribs) (Created page with "local p = {} function p.main(frame) local args = frame:getParent().args local res = mw.html.create('table') res:addClass('infobox') :css('width', '22em') :css('font-size', '88%') :css('line-height', '1.5em') -- HEADER: The Creator's Name res:tag('tr'):tag('th') :attr('colspan', '2') :css('text-align', 'center') :css('font-size', '125%') :css('font-weight', 'bold') :css('background-col...") |
|||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Main function called by {{#invoke:InfoboxCreator|main}} | |||
function p.main(frame) | function p.main(frame) | ||
-- Get arguments from the parent template | |||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local res = mw.html.create('table') | local res = mw.html.create('table') | ||
res:addClass('infobox') | -- Wikipedia-standard infobox classes (requires your Common.css) | ||
res:addClass('infobox vcard') | |||
:css('width', '22em') | :css('width', '22em') | ||
-- HEADER: | -- HEADER: Moniker/Stage Name | ||
res:tag('tr'):tag('th') | res:tag('tr'):tag('th') | ||
:attr('colspan', '2') | :attr('colspan', '2') | ||
:addClass('fn') | |||
:css('text-align', 'center') | :css('text-align', 'center') | ||
:css('font-size', '125%') | :css('font-size', '125%') | ||
:css('background-color', '#cedff2') | |||
:css('background-color', '#cedff2') | |||
:wikitext(args.name or mw.title.getCurrentTitle().text) | :wikitext(args.name or mw.title.getCurrentTitle().text) | ||
-- IMAGE | -- IMAGE LOGIC | ||
if args.image then | if args.image then | ||
local imgRow = res:tag('tr') | local imgRow = res:tag('tr') | ||
| Line 30: | Line 31: | ||
:attr('colspan', '2') | :attr('colspan', '2') | ||
:css('text-align', 'center') | :css('text-align', 'center') | ||
:wikitext(args.caption) | :wikitext(args.caption) | ||
end | end | ||
| Line 36: | Line 36: | ||
-- HELPER FUNCTION FOR ROWS | -- HELPER FUNCTION FOR ROWS | ||
local function addRow(label, value) | local function addRow(label, value, class) | ||
if value and value ~= "" then | if value and value ~= "" then | ||
local row = res:tag('tr') | local row = res:tag('tr') | ||
row:tag('th') | row:tag('th'):attr('scope', 'row'):css('text-align', 'left'):wikitext(label) | ||
local td = row:tag('td'):wikitext(value) | |||
if class then td:addClass(class) end | |||
row:tag('td') | |||
end | end | ||
end | end | ||
-- | -- DATA FIELDS | ||
addRow('Birth name', args.birth_name) | addRow('Birth name', args.birth_name, 'nickname') | ||
addRow('Born', args.birth_date) | addRow('Born', args.birth_date) | ||
addRow('Origin', args.birth_place) | addRow('Origin', args.birth_place, 'adr') | ||
addRow('Nationality', args.nationality) | addRow('Nationality', args.nationality) | ||
addRow('Education', args.alma_mater) | addRow('Education', args.alma_mater) | ||
addRow('Other names', args.other_names) | addRow('Other names', args.other_names) | ||
addRow('Occupation', args.occupation) | addRow('Occupation', args.occupation, 'role') | ||
addRow('Years active', args.years_active) | addRow('Years active', args.years_active) | ||
addRow('Catchphrase', args.catchphrase) | addRow('Catchphrase', args.catchphrase) | ||
addRow('Net worth', args.net_worth) | addRow('Net worth', args.net_worth) | ||
addRow('Primary platform', args.platform) | |||
addRow('Followers', args.followers) | |||
addRow('Primary | |||
addRow(' | |||
addRow('Website', args.website) | addRow('Website', args.website) | ||