Module:Item/test

local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame, {  valueFunc = function (key, value)      if key == 2 or key == 3 or key == 4 or key == 5 == locations then         return value      elseif key == 3 and key == summary then         return value      elseif value then         value = mw.text.trim(value)         return value      else         return value      end      return nil   end }) return p._main(args) end

function p._main(args) local item = args[1] local itemname = args[1] or '???' local rarity = args["rarity"] or nil local sell = args["sell"] or nil local drop = args["drop"] or nil local lost = args["lost"] or nil local locations = args["locations"] or nil local sprite = args["sprite"] or nil local rowspan = args["rowspan"] or nil --Custom rowspan for each param# local locspan = args["locspan"] or nil --Custom colspan for Locations local param2 = args[2] or nil local param3 = args[3] or nil local param4 = args[4] or nil local param5 = args[5] or nil

local row = mw.html.create -- Create base for all rows local img = mw.html.create --Create node for the item sprite local name = mw.html.create --Create node for the item name local attrrow1 = mw.html.create -- Create base attributes row local attrrow2 = mw.html.create -- Create main attributes row local paramcell = mw.html.create -- Create node for optional parameters local locrow = mw.html.create --Create node for locations row

lspan = 2 --Overall colspan for locations row. Default Is 2 and Increases for each param# cell

if rowspan then pspan = rowspan --Overall rowspan of each param# end

if not sprite then img :tag('td'):wikitext(mw.getCurrentFrame:expandTemplate { title = 'IS', args={ item } }):css('text-align', 'center') --IS cell :done elseif sprite then img :tag('td'):wikitext(''):css('text-align', 'center') :done end

if string.len(itemname) >= 12 and string.len(itemname) < 18 then name :tag('td'):wikitext(itemname):css('white-space', 'nowrap') :done else name :tag('td'):wikitext(itemname) :done end

if rarity or sell or drop or lost then --Basically "If there's an attribute" paramspan = 2 --Rowspan of each param[#] cell if rowspan then pspan = rowspan + paramspan else pspan = paramspan end

attrrow1 :tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) --Base attributes row :tag('td'):css('white-space', 'nowrap'):css('line-height', '1.2em'):attr('colspan', '2') -- Base attributes cell :tag('table') --Attributes table :node(attrrow2) --Attributes if rarity then -- Rarity attrrow2 :tag('tr') :tag('td'):wikitext(' Rarity: ', rarity ,' ') :done :done end

if sell and sell ~= 'no' then -- Sellability attrrow2 :tag('tr') :tag('td'):wikitext(' Sell Price: ', sell ,' ') :done :done elseif sell and sell == 'no' then attrrow2 :tag('td'):wikitext(' Cannot be sold. ') :done :done end

if drop == 'no' then -- Dropability attrrow2 :tag('tr') :tag('td'):wikitext(' Cannot be dropped. ') :done :done end

if lost == 'no' then -- Losability attrrow2 :tag('tr') :tag('td'):wikitext(' Cannot be lost. ') :done :done end else paramspan = 0 end

if param2 and param3 ~= 'summary' then paramcell :tag('td'):wikitext(param2):attr('rowspan', pspan) :done lspan = 3

elseif param2 and param3 == 'summary' then paramcell :tag('td'):wikitext(param2):attr('colspan', '2') :done lspan = 4 end

if param3 and param3 ~= 'summary' then paramcell :tag('td'):wikitext(param3):attr('rowspan', pspan) :done lspan = 4 elseif param3 == 'summary' then lspan = 5 end

if param4 then paramcell :tag('td'):wikitext(param4):attr('rowspan', pspan) :done lspan = 6 end

if param5 then paramcell :tag('td'):wikitext(param5):attr('rowspan', pspan) :done lspan = 7 end

if locspan then lspan = locspan end

if locations and string.find(locations, 'collaps') then --If there's collapsible content In locations locrow :tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', lspan):css('width','100%') :done elseif locations then locrow :tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', lspan) :done end

row:tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) --IS and Item row :node(img) --Item sprite cell :node(name) --Item name cell :node(paramcell) --Free space cells :node(attrrow1) --Base attributes row :done :node(locrow) --Locations row :done

return tostring(row)

end

return p

-- Copy and paste for the console <:) print(p.main)