ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.

Module:Table Fish

From Eco - English Wiki
Documentation

This Lua module provides the backend functionality for Template:FishList. It is not intended to be used from other modules. It creates an HTML table with data from Module:AnimalData.

This module uses the following modules:


local p = {}
local Utils = require("Module:Utils")
local AnimalUtils = require("Module:UtilsAnimalTables")
local AnimalData = mw.loadData("Module:AnimalData")

--- Create a HTML table with details on fish type animals.
-- @return #string HTML table in a string.
-- @author User:Demian
function p.main()
	assert(AnimalData.animals, "Failed to data from Module:AnimalData!")

	-- Sort animals by their name so the generated table will be pre-sorted on page load.
	local sortedNames = Utils.getSortedKeys(AnimalData.animals)
	-- Table to insert data into.
	local tbl = { "<table class=\"wikitable sortable\">" }
	-- Temporary variable to store animal data in.
	local data;

	-- Create the table header.
	AnimalUtils.insertAnimalListHeader(tbl)

	-- Create the table rows.
	for _, animalName in ipairs(sortedNames) do
		data = AnimalData.animals[animalName]

		if AnimalUtils.isFishAnimal(data) then
			AnimalUtils.insertAnimalListDataRow(tbl, animalName, data)
		end
	end

	table.insert(tbl, "</table>")

	return table.concat(tbl," \n")
end

return p