More actions
Created page with "local p = {} function p.infobox(frame) local args = frame:getParent().args local infobox = mw.html.create('table') :addClass('infobox') :css('width', '300px') :css('border', '1px solid #aaa') -- Title if args.title then infobox:tag('tr') :tag('th') :attr('colspan', '2') :css('text-align', 'center') :wikitext(args.title) end -- Image if args.image then infobox:tag('tr') :tag('td') :attr('colspan', '2') :css('text-align', 'center')..." |
No edit summary |
||
Line 2: | Line 2: | ||
function p.infobox(frame) | function p.infobox(frame) | ||
local args = frame:getParent().args | |||
local html = mw.html.create('table') | |||
:addClass('infobox') | |||
:css({ width = '300px', border = '1px solid #aaa', ['background-color'] = '#f9f9f9' }) | |||
local function addRow(label, key) | |||
local value = args[key] | |||
if value and value ~= '' then | |||
html:tag('tr') | |||
:tag('th'):wikitext(label):done() | |||
:tag('td'):wikitext(value) | |||
end | |||
end | |||
-- Title | |||
local title = args['title'] or mw.title.getCurrentTitle().text | |||
html:tag('tr') | |||
:tag('th') | |||
:attr('colspan', '2') | |||
:css({ ['text-align'] = 'center', ['font-size'] = '120%' }) | |||
:wikitext(title) | |||
-- Image | |||
if args.image then | |||
html:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | |||
:css('text-align', 'center') | |||
:wikitext('[[File:' .. args.image .. '|250px]]') | |||
if args['caption-image'] then | |||
html:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | |||
:css({ ['text-align'] = 'center', ['font-size'] = '90%' }) | |||
:wikitext(args['caption-image']) | |||
end | |||
end | |||
-- Data fields (label, param name) | |||
local fields = { | |||
{'Alias', 'alias'}, | |||
{'Sex', 'gender'}, | |||
{'Nation from', 'nationality'}, | |||
{'Breed', 'breed'}, | |||
{'Coat', 'fur_color'}, | |||
{'Born', 'born'}, | |||
{'Abandoned', 'abandoned'}, | |||
{'Rescued', 'rescued'}, | |||
{'Adopted', 'adopted'}, | |||
{'Died', 'died'}, | |||
{'Cause of death', 'cause_of_death'}, | |||
{'Resting place', 'resting_place'}, | |||
{'Occupation', 'occupation'}, | |||
{'Mate(s)', 'mate(s)'}, | |||
{'Weight', 'weight'}, | |||
{'Height', 'height'}, | |||
{'Owner', 'owner'}, | |||
{'Known for', 'known_for'}, | |||
{'Sound', 'sound'}, | |||
{'Social Media', 'social_media'} | |||
} | |||
for _, pair in ipairs(fields) do | |||
addRow(pair[1], pair[2]) | |||
end | |||
return tostring(html) | |||
end | end | ||
return p | return p |
Revision as of 22:26, 6 May 2025
Documentation for this module may be created at Module:InfoboxCat/doc
local p = {}
function p.infobox(frame)
local args = frame:getParent().args
local html = mw.html.create('table')
:addClass('infobox')
:css({ width = '300px', border = '1px solid #aaa', ['background-color'] = '#f9f9f9' })
local function addRow(label, key)
local value = args[key]
if value and value ~= '' then
html:tag('tr')
:tag('th'):wikitext(label):done()
:tag('td'):wikitext(value)
end
end
-- Title
local title = args['title'] or mw.title.getCurrentTitle().text
html:tag('tr')
:tag('th')
:attr('colspan', '2')
:css({ ['text-align'] = 'center', ['font-size'] = '120%' })
:wikitext(title)
-- Image
if args.image then
html:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext('[[File:' .. args.image .. '|250px]]')
if args['caption-image'] then
html:tag('tr')
:tag('td')
:attr('colspan', '2')
:css({ ['text-align'] = 'center', ['font-size'] = '90%' })
:wikitext(args['caption-image'])
end
end
-- Data fields (label, param name)
local fields = {
{'Alias', 'alias'},
{'Sex', 'gender'},
{'Nation from', 'nationality'},
{'Breed', 'breed'},
{'Coat', 'fur_color'},
{'Born', 'born'},
{'Abandoned', 'abandoned'},
{'Rescued', 'rescued'},
{'Adopted', 'adopted'},
{'Died', 'died'},
{'Cause of death', 'cause_of_death'},
{'Resting place', 'resting_place'},
{'Occupation', 'occupation'},
{'Mate(s)', 'mate(s)'},
{'Weight', 'weight'},
{'Height', 'height'},
{'Owner', 'owner'},
{'Known for', 'known_for'},
{'Sound', 'sound'},
{'Social Media', 'social_media'}
}
for _, pair in ipairs(fields) do
addRow(pair[1], pair[2])
end
return tostring(html)
end
return p