Home
Random
Log in
Settings
About Bronze and Iron: An Andal Invasions AGOT Roleplay Project
Disclaimers
Bronze and Iron: An Andal Invasions AGOT Roleplay Project
Search
Editing
Module:Infobox maker
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local getArgs = require('Module:Arguments').getArgs local tt = require('Module:TableTools') local ib = require('Module:Infobox').infobox local ii = require('Module:InfoboxImage').InfoboxImage local ul = require('Module:Ul').main local listify = require('Module:Listify') local function is_empty(s) -- This function checks whether a string is empty return s == nil or s == '' end local p = {} p.init = {} p.row_counter = 1 p.subheader_counter = 1 p.image_counter = 1 p.args = {} p.categories = {} function p.initialize(args) p.init = args end function p.add_category(args) local name = args.name or "" local key = args.key or "" if not is_empty(name) then if is_empty(key) then table.insert(p.categories, "[[Category:" .. name .. "]]") else table.insert(p.categories, "[[Category:" .. name .. "|" .. key .. "]]") end end end function p.add_classes(args) for _, v in ipairs{ 'bodyclass', 'titleclass', 'aboveclass', 'imageclass', 'belowclass', } do if is_empty(p.args[v]) then p.args[v] = args[v] else p.args[v] = p.args[v] .. " " .. args[v] end end end function p.add_styles(args) for _, v in ipairs{ 'bodystyle', 'titlestyle', 'abovestyle', 'imagestyle', 'captionstyle', 'headerstyle', 'labelstyle', 'datastyle', 'belowstyle', } do if is_empty(p.args[v]) then p.args[v] = args[v] else p.args[v] = p.args[v] .. args[v] end end end function p.add_title(args) p.args.title = args.title end function p.add_above(args) p.args.above = args.above end function p.add_below(args) p.args.below = args.below end function p.add_subheader(args) local subheader = args.subheader or "" local n = tostring(p.subheader_counter) if not is_empty(subheader) then p.args['subheader' .. n] = subheader p.args['subheaderrowclass' .. n] = args.subheaderrowclass p.args['subheaderclass' .. n] = args.subheaderclass p.subheader_counter = p.subheader_counter + 1 return true end return false end function p.add_image(args) local image = { image = args.image, size = args.size, maxsize = args.maxsize, sizedefault = args.sizedefault, alt = args.alt, border = args.border, suppressplaceholder = args.suppressplaceholder, } local n = tostring(p.image_counter) p.args['image' .. n] = ii{args=image} p.args['imagerowclass' .. n] = args.imagerowclass p.args['caption' .. n] = args.caption p.image_counter = p.image_counter + 1 end function p.add_row(args) local label = args.label or "" local data = args.data or "" local rowstyle = args.rowstyle or "" local rowclass = args.rowclass or "" local class = args.class or "" local n = tostring(p.row_counter) if not is_empty(data) then p.args['label' .. n] = label p.args['data' .. n] = data p.args['rowstyle' .. n] = rowstyle p.args['rowclass' .. n] = rowclass p.args['class' .. n] = class p.row_counter = p.row_counter + 1 return true end return false end function p.add_rows(args) local prefix = args.prefix or "" local default = args.default or "" local rowstyle = args.rowstyle or "" local rowclass = args.rowclass or "" local class = args.class or "" p.init[prefix .. '1'] = p.init[prefix .. '1'] or p.init[prefix] p.init[prefix .. '_label1'] = p.init[prefix .. '_label1'] or p.init[prefix .. '_label'] local add = false local n = tt.affixNums(p.init, prefix) for _, i in ipairs(n) do add = p.add_row{ label = p.init[prefix .. tostring(i) .. '_label'] or default, data = p.init[prefix .. tostring(i)], rowstyle = rowstyle, rowclass = rowclass, class = class, } or add end return add end function p.add_row_list(args) local singular = args.singular or "" local plural = args.plural or "" local prefix = args.prefix or "" local rowstyle = args.rowstyle or "" local rowclass = args.rowclass or "" local class = args.class or "" p.init[prefix .. '1'] = p.init[prefix .. '1'] or p.init[prefix] local n = tt.affixNums(p.init, prefix) local m = listify(p.init[prefix .. '1']) if #n > 1 then local list = {} for _, i in ipairs(n) do table.insert(list, p.init[prefix .. tostring(i)]) end return p.add_row{ label = plural, data = ul(list), rowstyle = rowstyle, rowclass = rowclass, class = class, } elseif #m > 1 then return p.add_row{ label = plural, data = ul(m), rowstyle = rowstyle, rowclass = rowclass, class = class, } else return p.add_row{ label = singular, data = m[1], rowstyle = rowstyle, rowclass = rowclass, class = class, } end end function p.add_header(args) local header = args.header or "" local rowstyle = args.rowstyle or "" local rowclass = args.rowclass or "" local n = tostring(p.row_counter) if not is_empty(header) then p.args['header' .. n] = header p.args['rowstyle' .. n] = rowstyle p.args['rowclass' .. n] = rowclass p.row_counter = p.row_counter + 1 return true end return false end function p.add_section(args) local header = args.header or "" local rowstyle = args.rowstyle or "" local rowclass = args.rowclass or "" local rows = args.rows or {} local add = false local h = tostring(p.row_counter) p.row_counter = p.row_counter + 1 for i, row in ipairs(rows) do if row.rowtype == 'header' then add = p.add_header(row) or add elseif row.rowtype == 'list' then add = p.add_row_list(row) or add elseif row.rowtype == 'rows' then add = p.add_rows(row) or add elseif row.rowtype == 'section' then add = p.add_section(row) or add else add = p.add_row(row) or add end end if add == true then p.args['header' .. h] = header p.args['rowstyle' .. h] = rowstyle p.args['rowclass' .. h] = rowclass end return add end function p.add_repeated_section(args) local header_prefix = args.header_prefix or "" local rowstyle = args.rowstyle or "" local rowclass = args.rowclass or "" local rows = args.rows or {} local add = true local counter = 1 while add == true do local n = tostring(counter) local section = { header = p.init[header_prefix .. n], rowstyle = rowstyle, rowclass = rowclass, rows = rows, } for _, row in ipairs(section.rows) do if row.rowtype == 'header' then row.header = p.init[header_prefix .. n .. row.argprefix] elseif row.rowtype == 'list' then row.prefix = header_prefix .. n .. row.argprefix elseif row.rowtype == 'rows' then row.prefix = header_prefix .. n .. row.argprefix else row.data = p.init[header_prefix .. n .. row.argprefix] end end add = p.add_section(section) counter = counter + 1 end end function p.make_infobox() return ib(p.args) .. mw.text.listToText(p.categories, '') end return p
Summary:
Please note that all contributions to Bronze and Iron: An Andal Invasions AGOT Roleplay Project are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) (see
Bronze and Iron An Andal Invasions AGOT Roleplay Project:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Infobox maker/doc
(
edit
)