Module:Book

From Little-Known Galaxy Wiki
Jump to navigation Jump to search

This module is used in the {{Book}} template.

Subpages

local argsUtil = require("Module:ArgsUtil")

local p = {}

function p.main(frame)
    local args = argsUtil.merge(frame.args, frame:getParent().args)
    
    -- Use the dataset values unless overridden by template arguments
    local header = args.header or ""
    local title = args.title or ""
    local body = args[1] or args.body or ""
    local collapsed = args.collapsed or "false"

    -- Generate the content box
    return p.generateBox{
        header = header,
        title = title,
        body = body,
        collapsed = collapsed
    }
end

function p.generateBox(entry)
    local header = entry.header or ""
    local title = entry.title or ""
    local body = entry.body or ""
    local collapsed = entry.collapsed or "false"

    local content = ""

    -- Start with the outer div
    content = content .. '<div class="tablescroll" style="font-weight:600;"><div style="width:50%; min-width:300px;">\n'

    -- Add header if it exists
    if header ~= "" then
        content = content .. '<div style="font-family:serif; font-size:1.5em; color:#FFFFFF; text-align:left; border:2px solid #252350; border-radius:20px 20px 0px 0px; border-bottom:0px; background:#252350; padding:0em 0.5em;">'
        content = content .. header
        content = content .. '</div>\n'
    end

    -- Add main content div
    content = content .. '<div style="outline:2px solid #c23896; outline-offset:-10px; border:1px solid #343f7b;'
    if header ~= "" then
        content = content .. ' border-radius:0px 0px 7px 7px;'
    else
        content = content .. ' border-radius:7px;'
    end
    content = content .. ' padding: 1em 2em 3em; background:#343f7b;">\n'

    -- Add title if it exists
    if title ~= "" then
        content = content .. '<div style="font-family:serif; font-size:1.2em; color:#8B8073; text-align:center; border:2px solid #c23896; border-radius:10px/10px; background:#252350; width:fit-content; margin: 0em auto -1.5em;">'
        content = content .. '<span style="color:#ffffff; padding: 0em 0.5em;">'
        content = content .. title
        content = content .. '</span></div>\n'
    end

    -- Add collapsible content
    local collapsibleClass = "mw-collapsible"
    if collapsed == "true" then
        collapsibleClass = collapsibleClass .. " mw-collapsed"
    end
    content = content .. '<div class="' .. collapsibleClass .. '">\n'
    content = content .. '<div style="padding:2em 0em 0em; color: #ffffff;">'
    content = content .. body
    content = content .. '</div>\n'
    content = content .. '</div>\n'

    -- Close main content div
    content = content .. '</div>\n'

    -- Close outer div
    content = content .. '</div></div>'

    return content
end

return p