Module:Page data: Difference between revisions
From International Robin Hood Bibliography
mNo edit summary |
mNo edit summary |
||
Line 8: | Line 8: | ||
function p.setData(frame) | function p.setData(frame) | ||
pFrame = frame:getParent() | pFrame = frame:getParent() | ||
local categories, properties = '', '' | local categories, properties, multiproperties = '', '', '' | ||
pageName = getFrameParam('PageName') | pageName = getFrameParam('PageName') | ||
if isValidParam(pageName) then | if isValidParam(pageName) then | ||
Line 16: | Line 16: | ||
local idx = 1 | local idx = 1 | ||
while(idx < 11) do | while(idx < 11) do | ||
local cat, propname, propval = getFrameParam('Cat' .. idx), getFrameParam('PropName' .. idx), getFrameParam('PropVal' .. idx) | local cat, propname, propval, mpropname, mpropval = getFrameParam('Cat' .. idx), getFrameParam('PropName' .. idx), getFrameParam('PropVal' .. idx), getFrameParam('MultiPropName' .. idx), getFrameParam('MultiPropVal' .. idx) | ||
if isValidParam(cat) or ( isValidParam(propname) and isValidParam(propval) ) then | if isValidParam(cat) or ( isValidParam(propname) and isValidParam(propval) ) or ( isValidParam(mpropname) and isValidParam(mpropval) ) then | ||
if isValidParam(cat) then categories = categories .. bra .. 'Category:' .. cat .. ket end | if isValidParam(cat) then categories = categories .. bra .. 'Category:' .. cat .. ket end | ||
if isValidParam(propname) and propname ~= 'Utitle' and isValidParam(propval) then | if isValidParam(propname) and propname ~= 'Utitle' and isValidParam(propval) then | ||
properties = properties .. '|' .. bra .. propname .. '=' .. propval | properties = properties .. '|' .. bra .. propname .. '=' .. propval | ||
end | |||
if isValidParam(mpropname) and isValidParam(mpropval) then | |||
multiproperties = multiproperties .. cur .. '#set:|' .. mpropname .. '=' .. mpropval .. '|+sep=;' .. lie | |||
end | end | ||
idx = idx + 1 | idx = idx + 1 | ||
Line 28: | Line 31: | ||
properties = cur .. '#set:' .. properties .. lie | properties = cur .. '#set:' .. properties .. lie | ||
end | end | ||
if not testing then return frame:preprocess(properties .. categories) | if not testing then return frame:preprocess(properties .. multiproperties .. categories) | ||
else return properties .. categories end | else return properties .. multiproperties .. categories end | ||
end | end | ||
Latest revision as of 12:40, 24 May 2022
Documentation for this module may be created at Module:Page data/doc
local p = {} local util = require 'Module:Utilities' local pageName = nil local pFrame local bra, ket, cur, lie, testing = '[[', ']]', '{{', '}}', false function p.setData(frame) pFrame = frame:getParent() local categories, properties, multiproperties = '', '', '' pageName = getFrameParam('PageName') if isValidParam(pageName) then testing = setTestState() pageName = util.ucSanitize(pageName) properties = 'Utitle=' .. pageName local idx = 1 while(idx < 11) do local cat, propname, propval, mpropname, mpropval = getFrameParam('Cat' .. idx), getFrameParam('PropName' .. idx), getFrameParam('PropVal' .. idx), getFrameParam('MultiPropName' .. idx), getFrameParam('MultiPropVal' .. idx) if isValidParam(cat) or ( isValidParam(propname) and isValidParam(propval) ) or ( isValidParam(mpropname) and isValidParam(mpropval) ) then if isValidParam(cat) then categories = categories .. bra .. 'Category:' .. cat .. ket end if isValidParam(propname) and propname ~= 'Utitle' and isValidParam(propval) then properties = properties .. '|' .. bra .. propname .. '=' .. propval end if isValidParam(mpropname) and isValidParam(mpropval) then multiproperties = multiproperties .. cur .. '#set:|' .. mpropname .. '=' .. mpropval .. '|+sep=;' .. lie end idx = idx + 1 else break end end properties = cur .. '#set:' .. properties .. lie end if not testing then return frame:preprocess(properties .. multiproperties .. categories) else return properties .. multiproperties .. categories end end function getFrameParam(paramName) local paramVal = nil if isValidParam(paramName) then paramVal = pFrame.args[paramName] if paramVal == '' then paramVal = nil end end return paramVal end function isValidParam(param) return param ~= nil and param ~= '' end function setTestState() local test = getFrameParam('Test') local testState = false if isValidParam(test) and test == 'true' then bra = 'BRABRA' ket = 'KETKET' cur = 'CURCUR' lie = 'LIELIE' testState = true end return testState end return p