Module:Animal

local p = {}

local data = mw.loadData('Module:Animal/data') local getArgs = require('Dev:Arguments').getArgs

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) local key = args[1] -- e.g. kitten local field = args[2] -- e.g. name local animal = data[key] or {} return animal[field] end

function p.rows(frame) local args = getArgs(frame) local root = mw.html.create('table') root:addClass('wikitable') local animals = mw.text.split(args.animals, '%s*,%s*') local fields = mw.text.split(args.fields, '%s*,%s*') local tr = root:tag('tr') for i, field in ipairs(fields) do       local th = tr:tag('th') local headerText = field -- can grab header text instead. th:wikitext(headerText) end for i, animalName in ipairs(animals) do       local tr = root:tag('tr') local animal = data[animalName] or {} for j, fieldName in ipairs(fields) do           local td = tr:tag('td') if fieldName == 'image' then local filename = animal[fieldName] local image = '???' if filename then image = '' end td:wikitext(image) elseif fieldName == 'Link' then -- skip, because we've already used it in the icon above else td:wikitext(animal[fieldName] or '???') end end end return tostring(root) end

return p