Module:Sandbox/Jts1882/Speciesbox Explained

require('strict')-- All Lua modules on Wikipedia must begin by defining a variable that will hold their-- externally accessible functions. They can have any name and may also hold data.local p = -- exposed variableslocal g = -- these are variables with global scope in this modulelocal info =

local parameters = require('Module:Sandbox/Jts1882/Biota infobox/param') local autotaxa = require("Module:Autotaxobox")

function p.main(frame) info.auto = "speciesbox" g.args = -- parameters.getArgs(frame, g.args, info) -- process the speciesbox parameters that must be changed before passing to taxobox/core p.speciesbox(frame) -- pass the processed arguments to the Template:Taxobox/core return frame:expandTemplate

end

function p.speciesbox(frame)

g.args['display_taxa'] = g.args['display_parents'] or 1 -- note change of parameter name local extinct = "" if g.args['extinct'] then --extinct = "†" extinct = frame:expandTemplate -- use template to get tooltip -- speciesbox also checks the genus taxonomy template for extinct parameter end --genus = Acanthocarpus (plant) local genusParts =mw.text.split(templateArgs['genus'], " ", true) -- string.match(s, '^%a*, 1) if genusParts[1] ~= "" then --templateArgs['parent']=templateArgs['genus'] -- set parent (NO, parent should override) genus = genusParts[1] end now handled by getGenus/getSpecies templates --]] g.args['taxon'] = genus .. ' ' .. g.args['species'] else -- TODO no valid taxon yet; use page name -- use first word of pagename - handled by end if not g.args['parent'] or g.args['parent']

"" then g.args['parent'] = g.args['genus'] -- set parent to genus if not supplied end --if not templateArgs['name'] or templateArgs['name']

"" then -- if page name not set templateArgs['name'] = "" .. templateArgs['taxon'] .. "" end

--TODO use g.args['name'] = frame:expandTemplate

-- set binomial : the speciesbox template seems to use genus and species before taxon name -- "| binomial = " -- documentation suggest taxon, which is followed here g.args['binomial'] = "" .. g.args['taxon'] .. "" g.args['binomial_authority'] = g.args['authority'] or nil

-- set species_name e.g. Panthera leo -> P. leo g.args['species_name'] = extinct .. "" .. string.sub(g.args['genus'],1,1) .. '. ' .. g.args['species'] .. "" g.args['species'] = g.args['species_name'] g.args['display_taxa'] = g.args['display_taxa'] -1 g.args['offset'] = 1 if g.args['subgenus'] and g.args['subgenus'] ~= "" then g.args['offset'] = g.args['offset'] + 1 g.args['subgenus_authority'] = g.args['parent_authority'] or "" end

g.args['taxon'] = nil -- no longer needed g.args['genus'] = nil -- uses parent g.args['colour'] = p.getTaxoboxColor(frame)

end

function p.getTaxoboxColor(frame) local colorAs = g.args['color_as'] or nil if info.auto and not g.args['virus_group'] then --colour_as|color as|colour as set, use template (2) else use the auto taxonnomy tree to find colour: