Module:Property navbox
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Property navbox/doc
Code
local p = {}
local protected = {}
local _frame
local lang, namespace
local i18n
local categories = {}
protected.fb = require 'Module:Fallback'
function protected.getFrame()
if not _frame then
_frame = mw.getCurrentFrame()
end
return _frame
end
function protected.getLang()
if not lang then
lang = protected.getFrame():preprocess('{{int:lang}}')
end
return lang
end
function protected.setLang(arg)
if not lang then
lang = arg
return true
else
return false
end
end
function protected.getNamespace()
if not namespace then
namespace = protected.getFrame():preprocess('{{NAMESPACE}}')
end
return namespace
end
function protected.addCategory(catname)
if catname then
table.insert(categories, '[[Category:' .. catname .. ']]')
end
end
function protected.translate(str)
local lang = protected.getLang()
return mw.language.new(lang):ucfirst(protected.fb.translate(i18n, str, lang))
end
function protected.highlightDollarInFormatter(value)
local split = mw.text.split(value, '$1', true)
for i in pairs(split) do
split[i] = mw.text.nowiki(split[i])
end
return table.concat(split, "'''$1'''")
end
function protected.main(frame)
_frame = frame
i18n = p.getI18n()
local args = {}
for i, j in pairs(frame:getParent().args) do
if j ~= '' then args[i] = j end
end
p.init(args)
local obj = mw.html.create('div')
:addClass('property-navibox')
:attr('dir', mw.getLanguage(protected.getLang()):getDir())
:wikitext(frame:extensionTag('templatestyles', '', {src = 'Module:Property navbox/styles.css'}))
:tag('div')
:addClass('property-navibox-header')
:tag('ul')
:addClass('property-navibox-links plainlinks')
:wikitext('<li>' .. table.concat(p.links(args), '</li>\n<li>') .. '</li>')
:done()
:tag('div')
:wikitext(p.header(args))
:allDone()
local maindiv = mw.html.create('div')
:addClass('property-navibox-main')
:tag('table')
for _, row in ipairs(p.rows) do
if not row.label then
return error("No label defined")
end
local label = row.label
if string.sub(label, 1, 8) == 'example ' then
local formatNum = require('Module:Formatnum')
label = mw.ustring.format(p.translate('example-num'),
formatNum.formatNum(tonumber(string.sub(label, 8)), protected.getLang()))
else
label = p.translate(label)
end
local val = p.makeRow(row, args)
if val then
local node = mw.html.create('tr')
:tag('th')
:wikitext(label)
:done()
:tag('td')
:wikitext(val)
:allDone()
maindiv:node(node)
end
end
obj:node(maindiv:allDone()):allDone()
return tostring(p.before(args)) .. tostring(obj) .. tostring(p.after(args)) .. table.concat(categories, '')
end
protected.makedoc = protected.main
--------------------------------------------------------------------------------
p.rows = {}
function p.getI18n()
return {}
end
function p.init(args)
end
function p.before(args)
return ''
end
function p.header(args)
return ''
end
function p.links(args)
return {}
end
function p.makeRow(row, data)
return nil
end
function p.after(args)
return ''
end
setmetatable(p, {
__index = protected,
__newindex = function(t, key, value)
if protected[key] then
return error()
end
return value
end
})
return p