Module:Theosophist volumes

From Teopedia

Documentation for this module may be created at Module:Theosophist volumes/doc

-- Lists of links to the volumes of “The Theosophist” for its header,
-- Template:Theosophist volume.
--
-- The journal has run since 1879, so the list is far longer than for other
-- periodicals in Teopedia: two rows of links (the contents of a volume and
-- its electronic edition) exceed the per-page iteration limit of the Loops
-- extension, which is why the rows are built here instead.
local p = {}

local function number(value, fallback)
    return tonumber(mw.text.trim(value or '')) or fallback
end

-- {{#invoke:Theosophist volumes|list|last=147}}          -- contents
-- {{#invoke:Theosophist volumes|list|last=147|suffix=/Text}} -- electronic edition
function p.list(frame)
    local first = number(frame.args.first, 1)
    local last = number(frame.args.last, 0)
    local suffix = mw.text.trim(frame.args.suffix or '')
    if last < first then
        return '<div class="error">Theosophist volumes: the last volume is not set.</div>'
    end
    local out = {}
    for volume = first, last do
        table.insert(out, '[[Theosophist/Vol' .. volume .. suffix .. '|' .. volume .. ']]')
    end
    return table.concat(out, ' ')
end

return p