Difference between revisions of "Module:ItemBox"
Coa wiki 4 (talk | contribs) |
|||
| (20 intermediate revisions by 4 users not shown) | |||
| Line 6: | Line 6: | ||
local row = table:tag('tr') | local row = table:tag('tr') | ||
| − | row:tag('td'):wikitext('<b>' .. key .. '</b>') | + | row:tag('td'):attr('colspan', 1):wikitext('<b>' .. key .. '</b>') |
| − | row:tag('td'):wikitext(value) | + | row:tag('td'):attr('colspan', 3):wikitext(value) |
return row | return row | ||
end | end | ||
| − | function full_row(table, key | + | function full_row(table, key) |
local row = table:tag('tr') | local row = table:tag('tr') | ||
| − | row:tag('td'):attr('colspan', ' | + | row:tag('td'):attr('colspan', '4'):attr('style', 'text-align: center') |
:wikitext('<i>"' .. key .. '"</i>') | :wikitext('<i>"' .. key .. '"</i>') | ||
| + | |||
| + | return row | ||
| + | end | ||
| + | |||
| + | function subheader(table, title) | ||
| + | local row = table:tag('tr') | ||
| + | |||
| + | row:tag('th'):attr('colspan', '4'):attr('class', 'infobox-subheader') | ||
| + | :wikitext(title) | ||
return row | return row | ||
| Line 26: | Line 35: | ||
-- Create title header | -- Create title header | ||
local td = table:tag('tr'):tag('td') | local td = table:tag('tr'):tag('td') | ||
| − | td:addClass('infobox-header'):attr('colspan', ' | + | td:addClass('infobox-header'):attr('colspan', '4') |
:wikitext(frame.args.name) | :wikitext(frame.args.name) | ||
-- Add image box | -- Add image box | ||
| − | table:tag('tr'):tag('td'):addClass('infobox-image'):attr('colspan', | + | table:tag('tr'):tag('td'):addClass('infobox-image'):attr('colspan', 4) |
:wikitext('[[File:' .. frame.args.image .. ']]') | :wikitext('[[File:' .. frame.args.image .. ']]') | ||
| Line 37: | Line 46: | ||
-- Separation header | -- Separation header | ||
| − | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', | + | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4) |
| − | -- Item | + | -- Item Level |
| − | basic_row(table, 'Level', frame.args.level) | + | if frame.args.level then |
| + | basic_row(table, 'Level', frame.args.level) | ||
| + | end | ||
-- Optional values | -- Optional values | ||
| Line 46: | Line 57: | ||
basic_row(table, 'Obtained', frame.args.obtained) | basic_row(table, 'Obtained', frame.args.obtained) | ||
end | end | ||
| + | |||
| + | -- Item Swing Speed | ||
| + | if frame.args.speed then | ||
| + | basic_row(table, 'Speed', frame.args.speed) | ||
| + | end | ||
| + | |||
| + | --Merchant Buy/Sell | ||
| + | if frame.args.buy or frame.args.sell then | ||
| + | -- Separator | ||
| + | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2) | ||
| + | |||
| + | local row = table:tag('tr') | ||
| + | |||
| + | row:tag('th'):wikitext('<b>Buy</b>') | ||
| + | row:tag('th'):wikitext('<b>Sell</b>') | ||
| + | |||
| + | row = table:tag('tr'):attr('style', 'text-align: center') | ||
| + | row:tag('td'):wikitext(frame.args.buy or '--') | ||
| + | row:tag('td'):wikitext(frame.args.sell or '--') | ||
| + | end | ||
| + | if frame.args.merchant_price then | ||
| + | basic_row(table, 'merchant price', frame.args.merchant_price) | ||
| + | end | ||
| + | |||
| + | -- Release Date | ||
| + | if frame.args.date then | ||
| + | basic_row(table, 'Release Date', frame.args.date) | ||
| + | end | ||
| + | |||
| + | -- Tradeable | ||
| + | if frame.args.tradeable then | ||
| + | basic_row(table, 'Tradeable', frame.args.tradeable) | ||
| + | end | ||
| + | |||
| + | -- Bonuses | ||
| + | if frame.args.accuracy or frame.args.strength or frame.args.defence or frame.args.hp then | ||
| + | -- Separator | ||
| + | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4) | ||
| + | |||
| + | local row = table:tag('tr') | ||
| + | |||
| + | row:tag('th'):wikitext('<b>Accuracy</b>') | ||
| + | row:tag('th'):wikitext('<b>Strength</b>') | ||
| + | row:tag('th'):wikitext('<b>Defence</b>') | ||
| + | row:tag('th'):wikitext('<b>HP</b>') | ||
| + | |||
| + | row = table:tag('tr'):attr('style', 'text-align: center') | ||
| + | row:tag('td'):wikitext(frame.args.accuracy or '--') | ||
| + | row:tag('td'):wikitext(frame.args.strength or '--') | ||
| + | row:tag('td'):wikitext(frame.args.defence or '--') | ||
| + | row:tag('td'):wikitext(frame.args.HP or '--') | ||
| + | end | ||
| + | |||
| + | |||
| + | -- Separation header | ||
| + | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4) | ||
| + | |||
| + | -- Bonuses | ||
| + | if frame.args.control or frame.args.spellpower or frame.args.aim or frame.args.drawback then | ||
| + | -- Separator | ||
| + | |||
| + | local row = table:tag('tr') | ||
| + | |||
| + | row:tag('th'):wikitext('<b>Control</b>') | ||
| + | row:tag('th'):wikitext('<b>Spellpower</b>') | ||
| + | row:tag('th'):wikitext('<b>Aim</b>') | ||
| + | row:tag('th'):wikitext('<b>Drawback</b>') | ||
| + | |||
| + | row = table:tag('tr'):attr('style', 'text-align: center') | ||
| + | row:tag('td'):wikitext(frame.args.control or '--') | ||
| + | row:tag('td'):wikitext(frame.args.spellpower or '--') | ||
| + | row:tag('td'):wikitext(frame.args.aim or '--') | ||
| + | row:tag('td'):wikitext(frame.args.drawback or '--') | ||
| + | end | ||
| + | |||
-- Separation header | -- Separation header | ||
| − | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', | + | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4) |
return tostring(table) | return tostring(table) | ||
Latest revision as of 15:08, 13 February 2023
Documentation for this module may be created at Module:ItemBox/doc
local export = {}
local pagename = mw.title.getCurrentTitle().fullText
function basic_row(table, key, value)
local row = table:tag('tr')
row:tag('td'):attr('colspan', 1):wikitext('<b>' .. key .. '</b>')
row:tag('td'):attr('colspan', 3):wikitext(value)
return row
end
function full_row(table, key)
local row = table:tag('tr')
row:tag('td'):attr('colspan', '4'):attr('style', 'text-align: center')
:wikitext('<i>"' .. key .. '"</i>')
return row
end
function subheader(table, title)
local row = table:tag('tr')
row:tag('th'):attr('colspan', '4'):attr('class', 'infobox-subheader')
:wikitext(title)
return row
end
function export.show(frame)
local table = mw.html.create('table'):addClass('coa-infobox'):addClass('item')
-- Create title header
local td = table:tag('tr'):tag('td')
td:addClass('infobox-header'):attr('colspan', '4')
:wikitext(frame.args.name)
-- Add image box
table:tag('tr'):tag('td'):addClass('infobox-image'):attr('colspan', 4)
:wikitext('[[File:' .. frame.args.image .. ']]')
-- Item description goes right below
full_row(table, frame.args.description or '')
-- Separation header
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4)
-- Item Level
if frame.args.level then
basic_row(table, 'Level', frame.args.level)
end
-- Optional values
if frame.args.obtained then
basic_row(table, 'Obtained', frame.args.obtained)
end
-- Item Swing Speed
if frame.args.speed then
basic_row(table, 'Speed', frame.args.speed)
end
--Merchant Buy/Sell
if frame.args.buy or frame.args.sell then
-- Separator
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2)
local row = table:tag('tr')
row:tag('th'):wikitext('<b>Buy</b>')
row:tag('th'):wikitext('<b>Sell</b>')
row = table:tag('tr'):attr('style', 'text-align: center')
row:tag('td'):wikitext(frame.args.buy or '--')
row:tag('td'):wikitext(frame.args.sell or '--')
end
if frame.args.merchant_price then
basic_row(table, 'merchant price', frame.args.merchant_price)
end
-- Release Date
if frame.args.date then
basic_row(table, 'Release Date', frame.args.date)
end
-- Tradeable
if frame.args.tradeable then
basic_row(table, 'Tradeable', frame.args.tradeable)
end
-- Bonuses
if frame.args.accuracy or frame.args.strength or frame.args.defence or frame.args.hp then
-- Separator
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4)
local row = table:tag('tr')
row:tag('th'):wikitext('<b>Accuracy</b>')
row:tag('th'):wikitext('<b>Strength</b>')
row:tag('th'):wikitext('<b>Defence</b>')
row:tag('th'):wikitext('<b>HP</b>')
row = table:tag('tr'):attr('style', 'text-align: center')
row:tag('td'):wikitext(frame.args.accuracy or '--')
row:tag('td'):wikitext(frame.args.strength or '--')
row:tag('td'):wikitext(frame.args.defence or '--')
row:tag('td'):wikitext(frame.args.HP or '--')
end
-- Separation header
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4)
-- Bonuses
if frame.args.control or frame.args.spellpower or frame.args.aim or frame.args.drawback then
-- Separator
local row = table:tag('tr')
row:tag('th'):wikitext('<b>Control</b>')
row:tag('th'):wikitext('<b>Spellpower</b>')
row:tag('th'):wikitext('<b>Aim</b>')
row:tag('th'):wikitext('<b>Drawback</b>')
row = table:tag('tr'):attr('style', 'text-align: center')
row:tag('td'):wikitext(frame.args.control or '--')
row:tag('td'):wikitext(frame.args.spellpower or '--')
row:tag('td'):wikitext(frame.args.aim or '--')
row:tag('td'):wikitext(frame.args.drawback or '--')
end
-- Separation header
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 4)
return tostring(table)
end
return export