FANDOM


-- <pre>
-- Portable Infobox builder
-- Version 0.0.1
--
-- Author(s):
--   - Cqm <http://c.wikia.com/wiki/Cqm>
--
 
local Infobox = {}
 
local metatable = {}
local methodtable = {}
 
--
-- Permitted tags, attributes and child tags to be used for error checking
-- As found on <http://c.wikia.com/Help:Infoboxes/Tags>
--
 
-- tags that can be used in the infobox
local tags = {
    -- basic tags
    infobox    = true,
    title      = true,
    data       = true,
 
    -- output modifiers
    label      = true,
    default    = true,
    format     = true,
 
    -- image tags
    image      = true,
    alt        = true,
    caption    = true,
 
    -- other tags
    group      = true,
    header     = true,
    navigation = true
}
 
-- which tags can contain child tags and what those child tags can be
-- if set to false, it means it can only contain wikitext
local childTags = {
    infobox    = { data=true, image=true, group=true, title=true },
    title      = { default=true, format=true },
    data       = { default=true, format=true, label=true },
    label      = false,
    default    = false,
    format     = false,
    image      = { alt=true, caption=true, default=true }, -- @todo check default
    alt        = { default=true },
    caption    = { default=true, format=true },
    group      = { data=true, header=true, image=true },
    header     = false,
    navigation = false
}
 
-- allowed attributes for each tag
-- if set to false, it means that no attributes are permitted
local tagAttrs = {
    infobox    = { theme=true, ['theme-source']=true, layout=true },
    title      = { source=true },
    data       = { source=true },
    label      = false,
    default    = false,
    format     = false,
    image      = { source=true },
    alt        = { source=true },
    caption    = { source=true },
    group      = { layout=true, show=true, collapse=true },
    header     = false,
    navigation = false
}
 
metatable.__index = methodtable
 
metatable.__tostring = function ( t )
    local ret = {}
    t:build( ret )
    return ret
end
 
--
-- 
--
-- @param tagName {string}
-- @return {boolean}
local function isValidTag( tagName )
    if tagName == nil or tagName == '' then
        return false
    end
 
    return tags[tagName] == true
end
 
--
--
--
-- @param parentName
-- @param childName
-- @return {boolean}
--
local function isValidChild( parentName, childName )
    if childTags[parentName] == nil or childTags[parentName] == false then
        return false
    end
 
    return childTags[parentName][childName] == true
end
 
--
--
--
-- @param tagName {string}
-- @param args {table}
--
local function createBuilder( tagName, args )
    if not isValidTag( tagName ) then
        -- throw error
    end
end
 
--
--
--
-- @param t
-- @param builder
--
local function appendBuilder( t, builder )
end
 
--
--
--
-- @param t
-- @param ret
--
methodtable._build = function ( t, ret )
end
 
--
--
--
function Infobox.create()
end
 
return Infobox

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.