Jump to content

Module:Card: Difference between revisions

From The Petit Planet Wiki
ReisuDesign (talk | contribs)
No edit summary
ReisuDesign (talk | contribs)
No edit summary
Line 24: Line 24:
local notext = args.notext or false
local notext = args.notext or false
local quality = args.quality or args.q
local quality = args.quality or args.q
quality = Ilib.verifyQuality(args.q)
-- mw.logObject(args)
-- mw.logObject(args)
local prefix = args.prefix or ''
local prefix = args.prefix or ''

Revision as of 08:42, 10 November 2025

Module documentation
This Lua module is used primarily on pages in the Main namespace. It can be found on 2,433 pages, or on about 60.66% of those pages.
Edits to this Lua module will be widely noticed. To avoid large-scale disruption and unnecessary server load, any changes to this Lua module should be tested in its sandbox or testcases subpages. The tested changes can then be added to this page in one single edit.
Please consider discussing any changes in the wiki's Discord.

This module implements {{Card}}.

To update, see: Module:CentralData.

local p = {}
local lib = require('Module:Feature')
local LL = require('Module:Link label')._main
local Ilib = require('Module:Icon')

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		parentFirst = true,
		removeBlanks = false,
		wrapper = { 'Template:Card' }
	})
	return p._main(args)
end

function p._main(args)
	local item = args.name or args[1]
	if not item then return mw.html.create() end -- if no input then return blank
	local link = args.nolink and '' or (args.link or item)
	local ext = args.ext or 'png'
	local amount = args.amount or args.x or args[2]
	local text = args.text or args[3]
	local note = args.note
	local nolink = args.nolink or false
	local notext = args.notext or false
	local quality = args.quality or args.q
	-- mw.logObject(args)
	local prefix = args.prefix or ''
	local suffix = args.suffix or ''
	prefix = prefix:gsub('{space}', ' ')
	suffix = suffix:gsub('{space}', ' ')
	
	local card = mw.html.create():tag('div'):addClass('custom-card noborder')
	local card_body = card:tag('div'):addClass('custom-card-body')
	local card_image = card_body:tag('div'):addClass('custom-card-image')
	local card_caption = card:tag('div'):addClass('custom-card-caption')
	
	-- main card image
	local filename = table.concat({prefix, item, suffix})
	card_image:wikitext('[[File:', filename, '.', ext, '|51px|link=', link, ']]')
	
	-- quality icon if valid
	if quality then
		card_body:addClass(' quality-' .. quality)
	end
	
	-- amount if any
	if lib.isNotEmpty(amount) then
		amount = tonumber(amount) ~= nil and lib.thousandsSeparator(amount) or amount
		card_body:tag('div'):addClass('custom-card-amount'):wikitext(amount)
	end
	
	-- default caption
	if args.show_caption then
		card_caption:tag('br')
		if link == '' then card_caption:wikitext(item)
		elseif link == item then card_caption:wikitext(LL(item))
		else card_caption:wikitext('[[', link, '|', item, ']]')
		end
	end
	
	-- append custom text if any
	if lib.isNotEmpty(text) then
		card_caption:tag('br')
		card_caption:wikitext(text)
	end
	
	-- ending note if any
	if lib.isNotEmpty(note) then
		card_caption:tag('br')
		card_caption:tag('small'):wikitext('(', note, ')')
	end
	
	-- mw.logObject(card) -- debug
	return card
end

return p