Module:Box: Difference between revisions

From evermeet.cx Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
-- Module:Box
-- Module:Box
-- Version 1.1 (2017-10-18)
-- Version 1.2 (2017-10-19)
-- Author: Helmut K. C. Tessarek
-- Author: Helmut K. C. Tessarek


Line 66: Line 66:
             '|-\n' ..
             '|-\n' ..
             '|}\n' ..
             '|}\n' ..
             '|}\n'
             '|}'


     return output
     return output

Revision as of 13:10, 19 October 2017

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

-- Module:Box
-- Version 1.2 (2017-10-19)
-- Author: Helmut K. C. Tessarek

-- Creates a colored box with title and text

local box = {
    blue    = {
        bg           = '#f5faff',
        border       = '#cedff2',
        title_bg     = '#cedff2',
        title_border = '#a3b0bf',
    },
    green   = {
        bg           = '#f5fffa',
        border       = '#cef2e0',
        title_bg     = '#cef2e0',
        title_border = '#a3bfb1',
    },
    grey    = {
        bg           = '#f9f9f9',
        border       = '#ddd',
        title_bg     = '#eee',
        title_border = '#afa3bf',
    },
    yellow  = {
        bg           = '#FFFFF5',
        border       = '#F8E47A',
        title_bg     = '#FFFFCC',
        title_border = '#a3b0bf',
    },    
}

function renderBox(args)
    local color  = ''
    local tmpcol = args["color"]
    local width  = args["width"] or ''
    local height = args["height"] or ''
    local title  = args["title"] or ''
    local text   = args["text"] or ''

    -- if no color is specified, or if the color does not exist, color is set to grey
    if type(box[tmpcol]) ~= 'nil' then
        color = tmpcol
    else
        color = 'grey'
    end

    local tline  = ''
    local output = ''

    if title == '' and text == '' then
        return ''
    end

    if title ~= '' then
        tline = '! <p style="margin:0; background:' .. box[color]["title_bg"] ..'; font-size:120%; font-weight:bold; border:1px solid ' .. box[color]["title_border"] ..'; text-align:left; color:#000; padding:0.2em 0.4em;">' .. title ..'</p>\n'
    end

    output = '{|style="width:' .. width .. '; height:' .. height .. '; border-spacing:8px; margin:0px -8px"\n' ..
             '|class="MainPageBG" style="border:1px solid ' .. box[color]["border"] .. '; background:' .. box[color]["bg"] .. '; vertical-align:top; color:#000"|\n' ..
             '{|width="100%" cellpadding="2" cellspacing="5" style="vertical-align:top; background:' .. box[color]["bg"] .. ';"\n' ..
             tline ..
             '|-\n' ..
             '|style="color:#000"|' .. text .. '\n' ..
             '|-\n' ..
             '|}\n' ..
             '|}'

    return output
end

local function showT(frame)
    -- Called by "{{box|...}}".
    return renderBox(frame:getParent().args)
end

local function show(frame)
    -- Called by "{{#invoke:box|show|...}}".
    return renderBox(frame.args)
end

return {
    showT = showT,
    show = show,
}