--require('strict')local p = local pargs = -- parent argumentslocal lastNode=0local nodeCount=0local cladeCount=0local leafCount=0local templateStylesCount=0local infoOutputlocal reverseClade = false
--main|style= }}Template:CladeN
Release version:Usage: Template:Clade
function p.main(frame)
local cladeString = "" local maxChildren = 20 -- was 17 in the clade/cladex templates local childNumber = 0 local childCount = 0 -- number of leaves in the clade (can use to set bottom of bracket in addTaxon local totalCount = 0 pargs = frame:getParent.args -- parent arguments infoOutput = p.getCladeTreeInfo -- get info about clade structure, e.g. lastNode (last |N= child number) --add the templatestyles tag conditionally to reduce expansion size (currently diabled) when added to every clade table, it increases post‐expand include size significantly e.g. the Neosuchia page (or test version) is increase by about 8% (672 bytes each) if template styles added to all pages there are 133 stripmarkers with cladeCount
1 condition interfers with fix for additional line due to parser bug T18700 killing the strip markers also removes backlinks to references using citation templates --
--cladeString =mw.text.killMarkers(cladeString) -- also kills off strip markers using citation templates --cladeString = mw.text.unstrip(cladeString) --if cladeCountif tableStyle ~= "" then tableStyle = ' style="' .. tableStyle .. '"' -- include style= in string to suppress empty style elements end reverseClade =frame.args.reverse or pargs.reverse or false -- a global --ENFORCE GLOBAL FOR DEVELOPMENT --reverseClade = true
local captionName = pargs['caption'] or "" local captionStyle = pargs['captionstyle'] or ""
-- add an element to mimick nowiki WORKS BUT DISABLE FOR DEMO PURPOSES --cladeString = '
\n' -- open table -- (border-collapse causes problems (see talk) -- cladeString = cladeString .. 'label'..childNumber..'=' .. outerTerm cladeString = cladeString .. indent .. ' | ' .. childNumber..'=' .. '' return cladeStringend function p.getIndent(levelNumber) local indent = "\r" local extraIndent = pargs['indent'] or mw.getCurrentFrame.args['indent'] or 0 while tonumber(extraIndent) > 0 do indent = indent .. " " -- an extra indent to make aligining compound trees easier extraIndent = extraIndent - 1 end while levelNumber > 1 do indent = indent .. " " levelNumber = levelNumber-1 end return indentend function p.newickstuff(newickString) endfunction p.processNewickString(newickString,childNumber) local maxPatterns = 5 local i = 0 local pargs = pargs local pattern = pargs['newick'..tostring(childNumber)..'-pattern'] -- unnumbered option for i=1 local replace = pargs['newick'..tostring(childNumber)..'-replace'] while i < maxPatterns do i=i+1 pattern = pattern or pargs['newick'..tostring(childNumber)..'-pattern'..tostring(i)] replace = replace or pargs['newick'..tostring(childNumber)..'-replace'..tostring(i)] or "" if pattern then newickString = string.gsub (newickString, pattern, replace) end pattern = nil; replace = nil end newickString = string.gsub (newickString, "_", " ") -- replace underscore with space return newickStringend------------------------------------------------------------------------------------------ function p.test2(target) local target ="User:Jts1882/sandbox/templates/Template:Passeroidea" local result = mw.getCurrentFrame:expandTemplate return resultend------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------- --function getCladeTreeInfo this preprocessing loop gets information about the whole structure (number of nodes, leaves etc) it makes a redundant calls to the templates through transclusion, but doen't affect the template depths; it provides the global lastNode that is used to limit the main while loop--function p.getCladeTreeInfo -- enable proprocessing loop local childNumber = 0 local childCount =0 local maxChildren =20 --info veriables (these are global for now) nodeCount=0 cladeCount=0 leafCount=0 while childNumber < maxChildren do -- preprocessing loop childNumber = childNumber + 1 -- so we start with 1 local nodeLeaf,data = pargs[tostring(childNumber)] or "" -- get data from | N= local newickString = pargs['newick'..tostring(childNumber)] or "" -- get data from | labelN= local listString = pargs['list'..tostring(childNumber)] or "" -- get data from | labelN= if newickString ~= "" or nodeLeaf ~= "" or listString ~= "" then --if nodeLeaf ~= "" then childCount = childCount + 1 -- this counts child elements in this clade -- for i in string.gmatch(nodeLeaf, "||rowspan") do -- count number of rows started (transclusion) nodeCount = nodeCount + 1 end for i in string.gmatch(nodeLeaf, ' | label' .. child ..'=' .. label cladeString = cladeString .. indent .. ' | ' .. child ..'=' .. '' return cladeStringend -- this must be at endreturn p |