Difference between revisions of "Module:Biota infobox/test"
Jump to navigation
Jump to search
blackwiki>Jts1882 (this is confusing) |
blackwiki>Jts1882 (save while ahead!) |
||
| Line 1: | Line 1: | ||
require('Module:No globals') | require('Module:No globals') | ||
| + | local getArgs = require ('Module:Arguments').getArgs; | ||
local p = {} -- exposed variables | local p = {} -- exposed variables | ||
| − | local args = {} | + | |
| + | --local pargs = {} | ||
| + | local template = {} | ||
| + | local args = {} | ||
| + | |||
| + | function p.addParam2(param,value) | ||
| + | --table.insert (template, table.concat ({' |'..param..'=', value})); -- this syntax works | ||
| + | --table.insert (template, table.concat ({' | '..param..' = ', value})); -- so does this (initial space needed) | ||
| + | --table.insert (template, table.concat ({'| '..param..' = ', value})); -- newline fails without initial space | ||
| + | end | ||
| + | function p.addParam(param) | ||
| + | |||
| + | if args[param] then | ||
| + | local value = args[param] | ||
| + | |||
| + | if param == 'genus' then | ||
| + | --local param = k:gsub("%'",""):gsub("%[",""):gsub("%]","") | ||
| + | --k=param | ||
| + | value='Hypsiboas' | ||
| + | elseif param == 'species' then | ||
| + | value='albopunctatus' | ||
| + | end | ||
| + | |||
| + | |||
| + | table.insert (template, ' | ' .. param .. ' = ' .. value ); | ||
| + | end | ||
| + | end | ||
function p.convert(frame) | function p.convert(frame) | ||
| − | args = frame:getParent().args | + | --args = frame:getParent().args |
| − | + | args = getArgs (frame); | |
| − | + | ||
| − | + | if args['genus'] and args['species'] then | |
| − | + | table.insert (template, '{{Speciesbox' ); | |
| + | elseif args['taxon'] then | ||
| + | table.insert (template, '{{Automatic taxobox ' ); | ||
| + | end | ||
| + | p.addParam('name') | ||
| + | p.addParam('genus') | ||
| + | p.addParam('species') | ||
for k,v in pairs(args) do | for k,v in pairs(args) do | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
table.insert (template, table.concat ({' |'..k..'=', v})); | table.insert (template, table.concat ({' |'..k..'=', v})); | ||
| − | |||
end | end | ||
table.insert (template, '}}'); -- close the template | table.insert (template, '}}'); -- close the template | ||
| − | |||
return table.concat (template, '\n'); | return table.concat (template, '\n'); | ||
end | end | ||
return p | return p | ||
Revision as of 16:54, 28 January 2020
Documentation for this module may be created at Module:Biota infobox/test/doc
require('Module:No globals')
local getArgs = require ('Module:Arguments').getArgs;
local p = {} -- exposed variables
--local pargs = {}
local template = {}
local args = {}
function p.addParam2(param,value)
--table.insert (template, table.concat ({' |'..param..'=', value})); -- this syntax works
--table.insert (template, table.concat ({' | '..param..' = ', value})); -- so does this (initial space needed)
--table.insert (template, table.concat ({'| '..param..' = ', value})); -- newline fails without initial space
end
function p.addParam(param)
if args[param] then
local value = args[param]
if param == 'genus' then
--local param = k:gsub("%'",""):gsub("%[",""):gsub("%]","")
--k=param
value='Hypsiboas'
elseif param == 'species' then
value='albopunctatus'
end
table.insert (template, ' | ' .. param .. ' = ' .. value );
end
end
function p.convert(frame)
--args = frame:getParent().args
args = getArgs (frame);
if args['genus'] and args['species'] then
table.insert (template, '{{Speciesbox' );
elseif args['taxon'] then
table.insert (template, '{{Automatic taxobox ' );
end
p.addParam('name')
p.addParam('genus')
p.addParam('species')
for k,v in pairs(args) do
table.insert (template, table.concat ({' |'..k..'=', v}));
end
table.insert (template, '}}'); -- close the template
return table.concat (template, '\n');
end
return p