There are no reviewed versions of this page, so it may not have been checked for adherence to standards.

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

--require "mw.text"
--require "mw.page"

local z = {
     wikitext = require "Module:Wikitext"
}

-- This is used by template {{spaces}}.
function z.spaces(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local n = tonumber(args[1]) 
    if ( nil == n or 1 == n ) then
        return " "
    else
        return string.rep(" ",n)
    end
end

-- This is used by template {{column-width}}.
function z.column_width(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    return z.wikitext.columnwidthstyle(args[1] or "30em")
end

-- This is used by template {{collapsible list}}.
function z.collapsiblelist(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    
    local items = {}
    local index = 1
    local itemparams = { style = "line-height: inherit; margin: 0;" }
    while true do
        local arg = args[index]
        if ( nil == arg ) then break end
        local item = mw.text.tag({name="li",contents=arg,params=itemparams})
        table.insert(items, item)
        index = index + 1
    end

    local listclass 
    if ( nil ~= args.hlist ) then listclass = " hlist" else listclass = "" end
    local liststyle = args.list_style or args["list-style"] or args.liststyle or "text-align:left;"
    if ( nil == args.bullets ) then liststyle = liststyle .. "list-style:none none;margin-left:0;" end
    local listparams = { class = "NavContent" .. listclass, style = "font-size:105%; margin-top: 0; margin-bottom: 0; line-height: inherit;" .. liststyle, align = "left" }
    local list = mw.text.tag({name="ul",contents=table.concat(items),params=listparams})

    local titlestyle = args.title_style or args["title-style"] or args.titlestyle
    local headstyle = titlestyle or "background:transparent;"
    local headparams = { class = "NavHead", style = "font-size:105%;" .. headstyle }
    if ( nil == titlestyle ) then headparams.align = "left" end
    local title = args.title or "List"
    local head = mw.text.tag({name="div",contents=title,params=headparams})

    local framestate 
    if ( nil == args.expand ) then framestate = " collapsed" else framestate = "" end
    local framestyle = args.frame_style or args["frame-style"] or args.framestyle or "border:none;padding:0;"
    local frameparams = { class = "NavFrame" .. framestate, style = framestyle }    
    return mw.text.tag({name="div",contents=head .. list,params=frameparams})
end

return z