Module:Stack: Difference between revisions
From Project Nakagami
(Created page with "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(fr...") |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
-- stacksize: The size of stacks, default 64, but sometimes 16 or other. | -- stacksize: The size of stacks, default 64, but sometimes 16 or other. | ||
-- link: The page to link. | -- link: The page to link. | ||
-- nox: Whether to avoid prepending x before the main number. | |||
function p.AddStackBreakout(frame) | function p.AddStackBreakout(frame) | ||
local DEFAULT_STACK_SIZE = 64 | local DEFAULT_STACK_SIZE = 64 | ||
| Line 15: | Line 16: | ||
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) | ||
local PlusItems = Count - (FullStacks * StackSize) | local PlusItems = Count - (FullStacks * StackSize) | ||
local PlusText = '' | local PlusText = '' | ||
| Line 25: | Line 25: | ||
local TextHTML = mw.html.create('span'); | local TextHTML = mw.html.create('span'); | ||
TextHTML:addClass(SPAN_CLASS) | if frame:getArgument('nox'):expand() == "true" then TextHTML:wikitext(Count); | ||
else TextHTML:wikitext('x' .. Count); end | |||
if (FullStacks == 1 and PlusItems > 0) or FullStacks > 1 then | |||
local StackHTML = TextHTML:tag('span'); | |||
StackHTML:addClass(SPAN_CLASS) | |||
StackHTML:wikitext(' (' .. FullStacks .. 'x' .. StackSize .. PlusText .. ')'); | |||
end | |||
if LinkDest ~= '' then | if LinkDest ~= '' then | ||
| Line 38: | Line 43: | ||
end | end | ||
end | end | ||
return p | |||
Latest revision as of 10:16, 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.
-- nox: Whether to avoid prepending x before the main number.
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');
if frame:getArgument('nox'):expand() == "true" then TextHTML:wikitext(Count);
else TextHTML:wikitext('x' .. Count); end
if (FullStacks == 1 and PlusItems > 0) or FullStacks > 1 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