Module:Stack: Difference between revisions
From Project Nakagami
No edit summary |
No edit summary |
||
| Line 15: | Line 15: | ||
if not StackSize then StackSize = DEFAULT_STACK_SIZE end | if not StackSize then StackSize = DEFAULT_STACK_SIZE end | ||
local FullStacks = Count / StackSize | local FullStacks = math.floor(Count / StackSize) | ||
if FullStacks < 2 then return end | if FullStacks < 2 then return end | ||
local PlusItems = Count - (FullStacks * StackSize) | local PlusItems = Count - (FullStacks * StackSize) | ||
Revision as of 09:05, 15 July 2024
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)
if FullStacks < 2 then return end
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:addClass(SPAN_CLASS)
TextHTML:wikitext('(' .. FullStacks .. 'x' .. StackSize .. PlusText .. ')');
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