Module:FBI QR code: Difference between revisions
From Hacks Guide Wiki
More actions
m Ihaveahax moved page Module:FBI QR codes to Module:FBI QR code without leaving a redirect: match template name |
No edit summary |
||
| (22 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local args = {} | |||
local p = {} | local p = {} | ||
| Line 23: | Line 25: | ||
-- 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) | ||
local nums = {} | local nums = {} | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
| Line 33: | Line 35: | ||
end | end | ||
function p.makeSections(frame | function p.makeSections(frame) | ||
local sections = {} | local sections = {} | ||
local nums = union(getArgNums('name' | local nums = union(getArgNums('name'), getArgNums('url')) | ||
for k, v in ipairs(nums) do | for k, v in ipairs(nums) do | ||
local name = args['name' .. tostring( | local name = args['name' .. tostring(num)] | ||
local url = args[' | local url = args['name' .. tostring(num)] | ||
if name and url then | if name and url then | ||
local qr = frame: | local qr = frame:callParserFunction('#qrlite', {url, format = 'svg', margin = '3'}) | ||
table.insert(sections, {name, | table.insert(sections, {name, qr..frame:preprocess('<br>['..url..' '..url..']')}) | ||
end | end | ||
end | end | ||
| Line 49: | Line 51: | ||
end | end | ||
function p. | function p.makeTabber(sections) | ||
local | local tabber = mw.html.create('tabber') | ||
for k, v in ipairs(sections) do | for k, v in ipairs(sections) do | ||
tabber:wikitext('|-|'..v[1]..'=\n\n', v[2]) | |||
end | end | ||
return | return tostring(tabber) | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local parent = frame:getParent() | local parent = frame:getParent() | ||
-- adapted from [[Module:Infobox]] | |||
if frame == mw.getCurrentFrame() then | |||
args = frame:getParent().args | |||
else | |||
args = frame | |||
end | |||
local sections = p.makeSections(parent | local sections = p.makeSections(parent) | ||
return p.makeTabber(sections) | |||
return p.makeTabber( | |||
end | end | ||
return p | return p | ||