Module:Biota infobox/test

MyWikiBiz, Author Your Legacy — Sunday October 06, 2024
< Module:Biota infobox
Revision as of 20:51, 15 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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 
			value = value:gsub("%'",""):gsub("%[",""):gsub("%]","")
			--value='Hypsiboas'
		elseif param == 'species' then
			--value = value:gsub("[%'%[%]]","")
			value = value:gsub("[%'%[]*[A-Za-z%.]* ([A-Za-z]*)[%]%']*","%1")
			--value='albopunctatus'
		elseif param == 'binomial_authority' then
			param = 'authority'
			args['binomial_authority']=nil
		end	   	
    	
    	
        table.insert (template, ' | ' .. param .. ' = ' .. value );
        args[param]=nil -- remove handled parameters
    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('image')
    p.addParam('status')
    p.addParam('status_system')
    p.addParam('status_ref')
    p.addParam('genus')
    p.addParam('species')
    p.addParam('binomial_authority')
    
	
	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