Difference between revisions of "Module:Biota infobox/test"

From blackwiki
Jump to navigation Jump to search
blackwiki>Jts1882
(return the template code)
m (8 revisions imported)
 
(5 intermediate revisions by 2 users not shown)
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
 +
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)
 
function p.convert(frame)
args = frame.args
+
--args = frame:getParent().args
local template = {}
+
args = getArgs (frame);
local targs = {}
+
 
+
if args['genus'] and args['species'] then
table.insert (template, '{{speciesbox ' );
+
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
 
for k,v in pairs(args) do
 
if k == 'genus' then
 
local param = k:gsub("%'",""):gsub("%[",""):gsub("%]","")
 
k=param
 
v='Hypsiboas'
 
elseif k== 'species' then
 
v='albopunctatus'
 
end
 
 
 
    table.insert (template, table.concat ({' |'..k..'=', v}));
 
    table.insert (template, table.concat ({' |'..k..'=', v}));
    targs[k] = v
 
 
end
 
end
  
 
table.insert (template, '}}'); -- close the template
 
table.insert (template, '}}'); -- close the template
 
 
--return frame:expandTemplate{ title = 'speciesbox', args = targs }
 
 
return table.concat (template, '\n');
 
return table.concat (template, '\n');
 
end
 
end
  
 
return p
 
return p

Latest revision as of 13:24, 26 September 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 
			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