Module:Infobox: Difference between revisions
When a parameter is nil, make sure the function is called with it being set to nil (previously, all other parameters would be shifted left one)
No edit summary |
(When a parameter is nil, make sure the function is called with it being set to nil (previously, all other parameters would be shifted left one)) |
||
(19 intermediate revisions by 6 users not shown) | |||
Line 4:
-- <nowiki>
require('strict')
local editbutton = require('Module:Edit button')
local smwutils = require('Module:SMW Utils')
Line 23 ⟶ 24:
args_smw = {}, -- parameters parsed for smw
infobox_name = nil, -- template name
classes = {}, -- list of classes to add, using the default_version
param_names = {}, -- ordered param list
params = {}, -- param definitions
Line 48 ⟶ 50:
obj:store_smw()
obj:parse_categories()
if obj.args_raw.__dump then▼
end▼
return obj
end
Line 60 ⟶ 59:
--]]
function Infobox.param(param_name)
local param = {
property = 'args_parsed',
param_name = param_name,
Line 73 ⟶ 72:
--]]
function Infobox.raw_param(param_name)
local param = {
property = 'args_raw',
param_name = param_name,
Line 86 ⟶ 85:
--]]
function Infobox.smw_param(param_name)
local param = {
property = 'args_smw',
param_name = param_name,
Line 173 ⟶ 172:
_cell:wikitext(content)
-- Add the switch data if multiple values exist
local data_attr_param = self:add_switch_data(v.content)
if data_attr_param then
_cell:attr('data-attr-param', data_attr_param)
Line 196 ⟶ 195:
return self
end
--[[
Line 211 ⟶ 209:
-- config: table containing configuration parameters
---- infobox_name = mandatory unique identifier for this infobox, used for css
----
--]]
function Infobox:config(config)
Line 219 ⟶ 217:
elseif k == 'max_buttons' then
self.max_buttons = tonumber(v)
elseif k == 'class' then
if type(v) == 'string' then
self.classes = {v}
elseif type(v) == 'table' then
self.classes = v
end
end
end
Line 234 ⟶ 238:
--]]
function Infobox:parse_versions()
local function insert_version_name(version_name)
table.insert(self.version_names, version_name)
if smwutils.valid_subobject_name(version_name) == false then
Line 365 ⟶ 369:
local func_params = func.params
local func_fetched_params = {}
local i = 1
for _, func_param in ipairs(func_params) do
i = i + 1
end
return func_name(unpack(func_fetched_params))
Line 405 ⟶ 411:
:addClass('infobox')
:addClass('infobox-'..self.infobox_name)
local class_name = self:get_param(class, self.default_version)
if type(class_name) == 'string' then
self.rtable:addClass('infobox-'..mw.ustring.gsub(class_name, '%s', '_'))
end
▲ end
-- Create the switch datatable if multiple versions
if self.versions > 1 then
Line 462 ⟶ 474:
local property = self.params[param_name].smw_property
if property then
local value = self:get_param(self.smw_param(param_name), version)
if value ~= nil then
subobject[property] = value
Line 543 ⟶ 555:
name = 'smw__' + name
end
local data_param = self.switch_datatable:tag('span'):attr('data-attr-param', name)
-- Add each version to the datatable
for version=1, self.versions do
local text = self:get_param(content, version)
if text == nil then
text = self.params[content.param_name].empty
Line 568 ⟶ 580:
-- Create categories
local category_text = ''
if mw.title.getCurrentTitle():inNamespace(0) then
▲ for key, _ in pairs(self.categories) do
for key, _ in pairs(self.categories) do
category_text = category_text..'[[Category:'..key..']]'
end
end
local dump = ''
setmetatable(self, nil)
dump = '<nowiki>'..mw.dumpObject(self)..'</nowiki>'
setmetatable(self, Infobox)
end
return tostring(self.rtable) .. tostring(self.switch_datatable) .. error_text .. category_text .. dump
end
|