Module:Table Fish: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [unchecked revision] |
(Created page with "local p = {} local Utils = require("Module:Utils") local AnimalUtils = require("Module:UtilsAnimalLists") --- Create a HTML table with details on fish type animals. -- @return #string HTML table in a string. -- @author User:Demian function p.main() -- Import the data. local animals = require("Module:AnimalData").animals -- Sort animals by their name so the generated table will be pre-sorted on page load. local sortedNames = Utils.getSortedKeys(animals) -- Table to...") |
m (Fix logic error.) |
||
Line 13: | Line 13: | ||
-- Table to insert data into. | -- Table to insert data into. | ||
local tbl = { "<table class=\"wikitable sortable\">" } | local tbl = { "<table class=\"wikitable sortable\">" } | ||
-- Temporary variable to store animal data in. | |||
local data; | |||
-- Create the table header. | -- Create the table header. | ||
Line 19: | Line 21: | ||
-- Create the table rows. | -- Create the table rows. | ||
for _, animalName in ipairs(sortedNames) do | for _, animalName in ipairs(sortedNames) do | ||
data = animals[animalName] | |||
if AnimalUtils.isFishAnimal(data) then | if AnimalUtils.isFishAnimal(data) then | ||
AnimalUtils.insertAnimalListDataRow(tbl, animalName, | AnimalUtils.insertAnimalListDataRow(tbl, animalName, data) | ||
end | end | ||
end | end |
Revision as of 23:02, 22 February 2022
local p = {}
local Utils = require("Module:Utils")
local AnimalUtils = require("Module:UtilsAnimalLists")
--- Create a HTML table with details on fish type animals.
-- @return #string HTML table in a string.
-- @author User:Demian
function p.main()
-- Import the data.
local animals = require("Module:AnimalData").animals
-- Sort animals by their name so the generated table will be pre-sorted on page load.
local sortedNames = Utils.getSortedKeys(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 = 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