Module:Bullet Book

From Imperivm Romanvm
Jump to navigation Jump to search

Documentation for this module may be created at Module:Bullet Book/doc

-- Name|Author|ISBN

local p = {}

local function _main(args)
    local BookSection = "* " .. (table.remove(args, 1))
    for k, v in pairs(args) do
        BookSection = BookSection .. "\n** " .. k .. ": " .. v
    end
    return BookSection
end

function p.main(frame)
	-- If called via #invoke, use the args passed into the invoking
    -- template, or the args passed to #invoke if any exist. Otherwise
    -- assume args are being passed directly in from the debug console
    -- or from another Lua module.
    -- All dates must be passed via ISO 8601 (YYYY-MM-DD) or (MM-DD)
    local origArgs
    if frame == mw.getCurrentFrame() then
    	origArgs = frame:getParent().args
    	for k, v in pairs(frame.args) do
    		origArgs = frame.args
    		break
    	end
    else
    	origArgs = frame
    end
    -- Trim whitespace and remove blank arguments.
    local args = {}
    for k, v in pairs(origArgs) do
        if type( v ) == 'string' then
            v = mw.text.trim(v)
        end
        if v ~= '' then
            args[k] = v
        end
    end
    
    -- exit if not given anything
    if args == nil or args == {} then return end
    
    return _main(args)
end

return p