13 Articles
Project Nakagami

Module:Stack

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 = 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