Jump to content

Module:Create plant stub

From Wikipedia, the free encyclopedia
require('strict')
local p = {}
local pargs = {}

local function firstToUpper(str)
    return (str:gsub("^%l", string.upper))
end
local function getArgs (frame, args)

	local parents = mw.getCurrentFrame():getParent()

	for k,v in pairs(parents.args) do
		--check content
		if v and v ~= "" then
			args[k]=v --parents.args[k]
		end
	end

	for k,v in pairs(frame.args) do
		--check content
		if v and v ~= "" then
			args[k]=v 
		end
	end
end


p.main = function (frame)

	getArgs(frame,pargs)
	local genus = pargs['genus'] 
	local species = pargs['species']
	local common = pargs['common_name'] 
	
	if not (genus and species) then 
		return "ERROR: require genus and species parameter" 
	end
	
	local output = ""
	
	local short = pargs['short'] or "Species of plant in the genus " ..pargs['genus']
	
	output = output .. "{{short description|" .. short .. "}}"
	
	--speciesbox
	output = output .. "\n{{speciesbox"
	output = output .. "\n|image = " .. pargs['image'] or ""
	output = output .. "\n|genus = " .. genus .. "\n|species = " .. species
	output = output .. "\n}}"
    
    --lede
    output = output ..	"\n'''''" .. firstToUpper(genus) .. " " .. species .. "'''''"
    if common then
       output = output .. ", also called the '''" .. common .. "''',"
    end
    output = output .. " is a species of " .. pargs['type'] or "flowering plant" .. "in the genus ''[[" ..genus "]]''"
    
    if pargs['distribution'] then 
    	output = output ..  ", native to " .. pargs['distribution']
	end
	output = output .. ". " .. (pargs['comment'] or "")
	
	-- subtaxa --
	
	local subtaxa = pargs['subtaxa']
	if subtaxa then
		output = output .. "\n==Subtaxa==" .. "\nThe following subtaxa are recognised:\n"
        frame.args[1] = subtaxa 
        frame.args['nolink'] = true -- subspecies shouldn't be linked
		output = output .. require('Module:FishRef/utilities').format_species_list(frame)
		--output = output ..
	end
	
	-- end stuff
	output = output .. "\n==References=="
	output = output .. "\n{{reflist}}"
	output = output .. "\n\n{{taxonbar|from1=" .. (pargs['taxonbar'] or "") ..  "}}"
	output = output .. "\n" .. pargs['categories'] or ""
	
	return output
	
	
 	
end
return p