Module:Infobox Shop

From Discord Dungeons Wiki
Revision as of 08:33, 4 April 2022 by Mackan (talk | contribs) (Created page with "-------------------------- -- Module for Template:Infobox Shop -- -- ------------------------ local p = {} local infobox = require('Module:Experimental/Infobox') local onmain = require('Module:Mainonly').on_main local commas = require('Module:Addcommas')._add VariablesLua = mw.ext.VariablesLua function p.main(frame) local args = frame:getParent().args local ret = infobox.new(args) ret:defineParams{ --- General -- { name = 'name', func = 'name' }, { name =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Infobox Shop/doc

--------------------------
-- Module for [[Template:Infobox Shop]]
--
--
------------------------
local p = {}

local infobox = require('Module:Experimental/Infobox')
local onmain = require('Module:Mainonly').on_main
local commas = require('Module:Addcommas')._add
VariablesLua = mw.ext.VariablesLua

function p.main(frame)
	local args = frame:getParent().args
	local ret = infobox.new(args)

	ret:defineParams{
		--- General --
		{ name = 'name', func = 'name' },
		{ name = 'image', func = 'image' },
		{ name = 'release', func = 'release' },
		{ name = 'description', func = 'has_content' },
		{ name = 'members', func = 'yes_no' },

		{ name = 'location', func = 'has_content' },
		{ name = 'owner', func = 'has_content' },
	}

	ret:setMaxButtons(7)
	ret:create()
	
	ret:cleanParams()
	ret:customButtonPlacement(true)
	ret:setDefaultVersionSMW(true)


	ret:defineLinks({ hide = true })

	ret:useSMWSubobject({
		members = 'Store Is members only',
		location = 'Store location',
		usesinfobox = 'Uses infobox',
	})

	ret:addButtonsCaption()

	ret:defineName('Infobox Shop')
	ret:addClass('infobox-shop')
	
	ret:addRow{
		{ tag = 'argh', content = 'name', class = 'infobox-header', colspan = '20' }
	}
	:pad(20)
	:addRow{
		{ tag = 'argd', content = 'image', class = 'infobox-image infobox-full-width-content', colspan = '20' }
	}
	:addRow{
		{ tag = 'argd', content = 'description', class = 'infobox-desription infobox-full-width-content', colspan = '20' }
	}
	:pad(20)
	:addRow{
		{ tag = 'th', content = 'Released', colspan = '7' },
		{ tag = 'argd', content = 'release', colspan = '13' },
	}
	:pad(20)
	:addRow{
		{ tag = 'th', content = '[[Members]]', colspan = '7' },
		{ tag = 'argd', content = 'members', colspan = '13' },
	}

	if ret:paramDefined('location') then
		ret:pad(20)
		:addRow{
			{ tag = 'th', content = 'Location', colspan = '7' },
			{ tag = 'argd', content = 'location', colspan = '13' },
		}
	end

	if ret:paramDefined('owner') then
		ret:pad(20)
		:addRow{
			{ tag = 'th', content = 'Owner', colspan = '7' },
			{ tag = 'argd', content = 'owner', colspan = '13' },
		}
	end


	if onmain() then
		local a1 = ret:param('all')
		local a2 = ret:categoryData()
		ret:wikitext(addcategories(a1, a2))
	end

	ret:finish()

	return ret:tostring()
end

function addcategories(args, catargs)
	local ret = { 'Shops' }

	-- Add the associated category if the parameter doesn't have content
	local notdefined_args = {
		release = 'Needs release date',
		members = 'Needs members status',
	}
	for n, v in pairs(notdefined_args) do
		if catargs[n] and catargs[n].all_defined == false then
			table.insert(ret, v)
		end
	end

	-- combine table and format category wikicode
	for i, v in ipairs(ret) do
		if (v ~= '') then
			ret[i] = string.format('[[Category:%s]]', v)
		end
	end

	return table.concat(ret, '')
end

return p