Module:Clade/example

MyWikiBiz, Author Your Legacy — Friday November 22, 2024
< Module:Clade
Revision as of 21:02, 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

Template:Module rating

See {{Clade example}}.

Usage

{{#invoke:Clade|example}}



local p = {}

function p.example(frame)
	
	local params = mw.getCurrentFrame():getParent().args
		-- build HTML table
	local exampleTable = mw.html.create('table')
	exampleTable:addClass('wikitable')
	local align = params['align'] or 'center'
	if align == 'center' then
		exampleTable:css('margin-left', 'auto')
		exampleTable:css('margin-right','auto')
	elseif align == 'right' then
		exampleTable:css('float',align)
	end
	
	local columns = {'description','code','output','comment'}
	--local headers = {'Description','Code','Output','Comment'}
    -- create header row and add requested headers
    local row = exampleTable:tag('tr')
    local headerText
    for k,v in pairs(columns) do
		if params[v] then 
			if params[v]~='' then headerText=params[v]  else headerText = firstToUpper(v) end
			row:tag('th'):wikitext(headerText) 
	    end
    end

	-- now deal with the data rows
	local i=0
	while i<10 do
		i=i+1 
		local moreRows = false
		for k,v in pairs(columns) do
			if params[v..i] then moreRows = true end
		end
		if not moreRows then break end
			
		row = exampleTable:tag('tr')
		for k,v in pairs(columns) do
			if params[v] then
				if params[v] then 
					row:tag('td'):css('text-align', 'left'):wikitext('\n' ..params[v..i]) 
				else
					row:tag('td')
				end
			end
		end
    end

	return tostring(exampleTable)
end
function firstToUpper(str)
    return (str:gsub("^%l", string.upper))
end


function p.templateStyle( frame, src )
   return frame:extensionTag( 'templatestyles', '', { src = src } );
end

-- this must be at end
return p