Module:TagDetails: Difference between revisions

From Eco - English Wiki
[checked revision][checked revision]
No edit summary
No edit summary
Line 11: Line 11:


     -- check that all necessary arguments are passed correctly
     -- check that all necessary arguments are passed correctly
     if args.name == nil or args.name == '' then
     if args.name == nil or args.name == '' then return '\'name\' must be specified.' end
        return '\'name\' must be specified.'
    end


     local tagName = args.name
     local tagName = args.name
Line 21: Line 19:
     local tagList = TagData.tags[tagName]
     local tagList = TagData.tags[tagName]


     if (tagList == nil) then
     if (tagList == nil) then return tagName .. " could not be found in Module:TagData" end
        return tagName .. " could not be found in Module:TagData"
    end


     local itemList = tagList.Items
     local itemList = tagList.Items
     local tagID = tagList.ID
     local tagID = tagList.ID
     local text = ""
     local text = ""



Revision as of 21:24, 2 December 2024

Documentation

This module is a part of the Template:TagDetails, and is used to generate cards that display information about Tags.

If the template is passed, this module is used with the following Modules:


-- Credit: User:Avaren

local p = {}
local Utils = require('Module:Utils')
local IconUtils = require('Module:IconUtils')
local L = require('Module:Localization')

-- build tag list
function p.tagList(frame)
    local args = Utils.normaliseArgs(frame)

    -- check that all necessary arguments are passed correctly
    if args.name == nil or args.name == '' then return '\'name\' must be specified.' end

    local tagName = args.name

    local TagData = mw.loadData("Module:TagData")

    local tagList = TagData.tags[tagName]

    if (tagList == nil) then return tagName .. " could not be found in Module:TagData" end

    local itemList = tagList.Items
    local tagID = tagList.ID
    local text = ""

    local tagLink = L.t('%s Tag'):format(tagName)
    -- Generate Icon, IconLink, and IconTextBr using IconUtils
    local IconTextBr = IconUtils.main{ name = tagID, size = 128, style = 3, link = tagLink }

    -- IconTextBr now contains the formatted icon with the text and line break
    text = text .. '<div class="IconFrame">' .. IconTextBr .. '</div>'

    text = text .. '\n\n\n' .. string.format(L.t('Item with the %s Tag:', tagCount), tagName) .. '\n'
    text = text .. '<div class="row">'
    for _, item in pairs(itemList) do
        local itemID = Utils.CheckId(item)
        local itemIconTextBr = IconUtils.main{ name = itemID, size = 128, style = 3, link = item }
        text = text .. '<div class="IconFrame">' .. itemIconTextBr .. '</div>'
    end
    text = text .. '</div>'
    return text
end

return p