Module:EFloras/documentation functions

MyWikiBiz, Author Your Legacy — Thursday December 05, 2024
< Module:EFloras
Revision as of 21:23, 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
local p = {}

local output_mt = {}
function output_mt:insert(str)
	self.n = self.n + 1
	self[self.n] = str
end

-- also in [[Module:Unicode data/documentation functions]]
function output_mt:insert_format(...)
	self:insert(string.format(...))
end

output_mt.join = table.concat

output_mt.__index = output_mt

local function Output()
	return setmetatable({ n = 0 }, output_mt)
end

function p.show_resources(frame)
	local output = Output()
	
	output:insert [[
{| id="eFloras-resources" class="wikitable" style="float: right;"
! code !! style="width: 22em;" | title]]
	
	for str_number, resource_name in require "Module:TableTools".sortedPairs(
			require "Module:eFloras/data".resources,
			function (str_number1, str_number2)
				return tonumber(str_number1) < tonumber (str_number2)
			end) do
		output:insert_format("|-\n| <code>%s</code> || %s", str_number, resource_name)
	end
	
	output:insert("|}")
	
	return output:join("\n")
end

return p