Module:FBI QR code: Difference between revisions
From Hacks Guide Wiki
More actions
try callParserFunction instead |
m Ihaveahax moved page Module:FBI QR codes to Module:FBI QR code without leaving a redirect: match template name |
||
| (21 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| Line 25: | Line 23: | ||
-- for the specified prefix. For example, if the prefix was 'data', and | -- for the specified prefix. For example, if the prefix was 'data', and | ||
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}. | -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}. | ||
local function getArgNums(prefix) | local function getArgNums(prefix, args) | ||
local nums = {} | local nums = {} | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
| Line 35: | Line 33: | ||
end | end | ||
function p.makeSections(frame) | function p.makeSections(frame, args) | ||
local sections = {} | local sections = {} | ||
local nums = union(getArgNums('name'), getArgNums('url')) | local nums = union(getArgNums('name', args), getArgNums('url', args)) | ||
for k, v in ipairs(nums) do | for k, v in ipairs(nums) do | ||
local name = args['name' .. tostring( | local name = args['name' .. tostring(v)] | ||
local url = args[' | local url = args['url' .. tostring(v)] | ||
if name and url then | if name and url then | ||
local qr = frame: | local qr = frame:expandTemplate( { title = 'qrlite', args = { url, format = 'png', margin = '3' } } ) | ||
table.insert(sections, {name, qr.. | table.insert(sections, {name, '<p class="hb-qrcode-image">'..qr..'</p><p class="hb-qrcode-link">['..url..' '..url..']</p>'}) | ||
end | end | ||
end | end | ||
| Line 51: | Line 49: | ||
end | end | ||
function p. | function p.makeTabberData(sections) | ||
local finalSections = '' | local finalSections = '' | ||
for k, v in ipairs(sections) do | for k, v in ipairs(sections) do | ||
finalSections = finalSections..'|-|'..v[1]..'= | finalSections = finalSections..'|-|'..v[1]..'='..v[2] | ||
end | end | ||
return frame:callParserFunction('#tag | return finalSections | ||
end | |||
function p.makeTabber(frame, sections) | |||
return frame:callParserFunction('#tag', 'tabber', p.makeTabberData(sections)) | |||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local parent = frame:getParent() | local parent = frame:getParent() | ||
local sections = p.makeSections(parent) | local sections = p.makeSections(parent, parent.args) | ||
return p.makeTabber(parent, sections) | return p.makeTabber(parent, sections) | ||
end | |||
function p.template(frame) | |||
local args = {} | |||
for k,v in pairs(frame.args) do args[k] = mw.text.trim(v) end | |||
local sections = p.makeSections(frame, args) | |||
return p.makeTabber(frame, sections) | |||
end | end | ||
return p | return p | ||