Module:Stack
From Project Nakagami
Documentation for this module may be created at Module:Stack/doc
local p = {} --package
-- Allowed Arguments:
-- count: The number to elaborate.
-- stacksize: The size of stacks, default 64, but sometimes 16 or other.
-- link: The page to link.
function p.AddStackBreakout(frame)
local DEFAULT_STACK_SIZE = 64
local SPAN_CLASS = 'stack-breakout-text' -- the class attribute on the text span element
local Count = tonumber(frame:getArgument('count'):expand())
if not Count then return end
local StackSize = tonumber(frame:getArgument('stacksize'):expand())
if not StackSize then StackSize = DEFAULT_STACK_SIZE end
local FullStacks = math.floor(Count / StackSize)
local PlusItems = Count - (FullStacks * StackSize)
local PlusText = ''
if PlusItems > 0 then PlusText = ' + ' .. PlusItems end
local LinkDest = frame:getArgument('link'):expand()
if not LinkDest then LinkDest = '' end
local TextHTML = mw.html.create('span');
TextHTML:wikitext(Count);
if FullStacks >= 2 then
local StackHTML = TextHTML:tag('span');
StackHTML:addClass(SPAN_CLASS)
StackHTML:wikitext(' (' .. FullStacks .. 'x' .. StackSize .. PlusText .. ')');
end
if LinkDest ~= '' then
if LinkDest:find('//') then -- External Link
return '[' .. LinkDest .. ' ' .. tostring(TextHTML) .. ']'
else -- Internal Link
return '[[' .. LinkDest .. '|' .. tostring(TextHTML) .. ']]'
end
else
return tostring(TextHTML)
end
end
return p