Jump to content

Module:Table

Unchecked
From Wikipedia

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

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

function removequotes(value)
    if ( "\"" == string.sub(value,1,1) ) then value = string.sub(value,2,-1) end
    if ( "\"" == string.sub(value,-1,-1) ) then value = string.sub(value,1,-2) end
    return value
end

-- This is used by template {{table}}.
function z.table (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 type = args.type 
    local params = z.wikitext.SplitHTMLElementParams(type)
    if ( nil == params.class ) then params.class = "wikitable" end
    local title = args.title
    if ( nil ~= title ) then title = "|+ " .. title .. "\n" end
    local index = 1
    local rows = {}
    while true do
        local row = args["row" .. index]
        if ( nil == row ) then break end
        table.insert(rows, "|-\n|" .. row .. "\n")
        index = index + 1
    end
    local body = table.concat(rows)
    return "{|" .. z.wikitext.CombineHTMLElementParams(params) .. "\n" .. title .. body .. "|}\n"    
end

return z