Difference between revisions of "Module:ItemBox"

From Curse of Aros
Jump to: navigation, search
Line 12: Line 12:
 
end
 
end
  
function full_row(table, key, value)
+
function full_row(table, key)
 
local row = table:tag('tr')
 
local row = table:tag('tr')
 
 
 
row:tag('td'):attr('colspan', '2'):attr('style', 'text-align: center')
 
row:tag('td'):attr('colspan', '2'):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', '2'):attr('class', 'infobox-subheader')
 +
:wikitext(title)
 
 
 
return row
 
return row
Line 52: Line 61:
 
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2)
 
table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2)
 
 
basic_row(table, 'Attack', frame.args.attack or '--')
+
local row = table:tag('tr')
basic_row(table, 'Strength', frame.args.strength or '--')
+
basic_row(table, 'Defence', frame.args.defence or '--')
+
row:tag('th'):wikitext('<b>Attack</b>')
basic_row(table, 'HP', frame.args.HP or '--')
+
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')
 +
row:tag('td'):wikitext(frame.args.attack 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
 
end
 
 

Revision as of 12:33, 17 June 2019

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'):wikitext('<b>' .. key .. '</b>')
	row:tag('td'):wikitext(value)
	
	return row
end

function full_row(table, key)
	local row = table:tag('tr')
	
	row:tag('td'):attr('colspan', '2'):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', '2'):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', '2')
		:wikitext(frame.args.name)
		
	-- Add image box
	table:tag('tr'):tag('td'):addClass('infobox-image'):attr('colspan', 2)
		: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', 2)
	
	-- Item basic attributes
	basic_row(table, 'Level', frame.args.level)
	
	-- Optional values
	if frame.args.obtained then
		basic_row(table, 'Obtained', frame.args.obtained)
	end
	
	-- Bonuses
	if frame.args.attack or frame.args.strength or frame.args.defence or frame.args.hp then
		-- Separator
		table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2)
		
		local row = table:tag('tr')
	
		row:tag('th'):wikitext('<b>Attack</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')
		row:tag('td'):wikitext(frame.args.attack 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', 2)
	
    return tostring(table)
end

return export