Module:Similar Vars
Module documentation
This documentation is transcluded from Module:Similar Vars/doc. [edit] [history] [purge]
Module:Similar Vars's function main is invoked by Template:Similar Vars.
Module:Similar Vars requires Module:Navbox.
Generates {{Similar Vars}}
navbox used in Varbits project pages.
local navbox = require('Module:Navbox')
local VariablesLua = mw.ext.VariablesLua
local p = {}
-- Create a link the the varb/varp page with the text 'NAME(index)'
local function generatePagelink(t)
if t['Variable index'] and t['Variable name'] then
return '*[['..t[1]..'|'..t['Variable name']..'('..t['Variable index']..')]]'
end
-- If missing any of the required SMW data, just return the pagelink
return '*[['..t[1]..']]'
end
local function getRelatedVars(content)
local data = mw.smw.ask({
'[[Variable content::'..content..']]',
'?=#-',
'?Variable name#-',
'?Variable index#-',
})
local lineTable = {}
if data == nil then
return ''
end
for _, t in ipairs(data) do
table.insert(lineTable, generatePagelink(t))
end
return table.concat(lineTable, "\n")
end
function p.main(frame)
local args = frame:getParent().args
local content = VariablesLua.var('content_var', 'Unknown')
local raw_content = VariablesLua.var('raw_content_var', 'Unknown')
args = {}
args['name'] = 'Similar Vars'
args['title'] = raw_content .. ' vars'
args['group1'] = getRelatedVars(content)
args['style1'] = 'text-align:center;'
if args['group1'] ~= '' then
return navbox._navbox(args)
else
return ''
end
end
return p