Module:Table Animals: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [unchecked revision] |
(Utilize new insertAnimalListTableHeader and insertAnimalListDataRow functions from Module:UtilsAnimalLists to simplify code.) |
m (Remove unused require, add documentation.) |
||
Line 2: | Line 2: | ||
local Utils = require("Module:Utils") | local Utils = require("Module:Utils") | ||
local AnimalUtils = require("Module:UtilsAnimalLists") | local AnimalUtils = require("Module:UtilsAnimalLists") | ||
local function addFootnotes(t) | local function addFootnotes(t) | ||
Line 16: | Line 15: | ||
end | end | ||
--- Create a HTML table with details on fish type animals. | |||
-- @return #string HTML table in a string. | |||
-- @author User:Demian | |||
function p.main() | function p.main() | ||
-- Import the data. | -- Import the data. |
Revision as of 22:53, 22 February 2022
Template:Doc/start Template:Template backend 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:UtilsAnimalLists")
local function addFootnotes(t)
-- Sadly I could not find a way to add HTML to the table header generated with the Lua code below.
-- <a id=\"cite_ref-1\" class=\"reference\" href=\"#cite_note-1\">[1]</a>
-- <a id=\"cite_ref-2\" class=\"reference\" href=\"#cite_note-2\">[2]</a>
table.insert(t, "<strong>Footnotes</strong>")
table.insert(t, "<div class=\"mw-references-wrap\">")
table.insert(t, "<ol class=\"references\">")
table.insert(t, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\" aria-label=\"Jump up\" title=\"Jump up\">↑</a></span> <span class=\"reference-text\">Calories consumed by predator animals who eat this animal. Not applicable to players, see the <strong>Harvest Item</strong> column for details on the player consumable food items.</span></li>")
table.insert(t, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\" aria-label=\"Jump up\" title=\"Jump up\">↑</a></span> <span class=\"reference-text\">The minimum and maximum delay between attacks. Lower values equal faster attacks.</span></li>")
table.insert(t, "</ol></div>")
end
--- 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\">" }
-- Create the table header.
AnimalUtils.insertAnimalListHeader(tbl)
-- Create the table rows.
for _, animalName in ipairs(sortedNames) do
AnimalUtils.insertAnimalListDataRow(tbl, animalName, animals[animalName])
end
table.insert(tbl, "</table>")
return table.concat(tbl," \n")
end
return p