Module:TagDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
m (Fix icon image)
No edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- Credit: User:Avaren
-- Credit: User:Avaren
local Utils = require('Module:Utils')
local L = require('Module:Localization')


local p = {}
local p = {}


-- Grabs args from the parent frame
local function icon_frame(name, link, bg, text, expensive)
-- Trims and parses the args into a table, then returns the table
     local icon = Utils.build_icon(name, link, nil, bg, nil, expensive)
function norm()
     return '<div style="border: 5px outset #A9A9A9; background: #DCDCDC; display:inline-block; width: auto; padding: 10px; margin: 10px; text-align: center; vertical-align: middle;">' .. icon .. text ..'</div>'
     local origArgs = mw.getCurrentFrame():getParent().args
     local args = {}
   
    for k, v in pairs( origArgs ) do
        v = mw.text.trim( tostring( v ) )
        if v ~= '' then
            args[k] = v
        end
    end
   
    return args
end
end


-- build tag list
-- build tag list
function p.tagList( args )
function p.tagList(frame)
local args = norm()
    local args = Utils.normaliseArgs(frame)
 
-- 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.'
        return '\'name\' must be specified.'
end
    end
 
    local tagName = args.name
 
    local itemData = mw.loadData("Module:ItemData")
 
    local tagList = itemData.tags
 
    local itemList = tagList[tagName]
 
    if (itemList == nil) then
        return tagName .. " could not be found in Module:ItemData"
    end


local tagName = args.name
    local text = ""
local itemData = require( "Module:ItemData" )
local tagList = itemData.tags
local itemList = tagList[tagName]
if (itemList == nil) then
return tagName .. " could not be found in the tag data"
end


local text = ""
    local tagLink = L.t('%s Tag'):format(tagName)


text = text .. '<div style="border: 5px outset #A9A9A9; background: #DCDCDC; display:inline-block; width: auto; padding: 10px; margin: 10px; text-align: center; vertical-align: middle;">'
    text = text .. icon_frame(L.tag(tagName) .. 'Tag', tagLink, 'iconWhite', '<h3>[[' .. tagLink .. ']]</h3>', false)
text = text .. '<div class="iconContainer">'
text = text .. '<div class="iconStack">[[File:'..string.gsub(tagName, ' ', '')..'_Icon.png|class=iconWhite|link='..tagName..']]</div>'
text = text .. '<div class="iconBorder"></div></div>'
text = text .. '<h3>'..tagName..'</h3></div>'


text = text .. '\n\n\nItems with the [['..tagName..']] tag:\n'
    local tagCount = Utils.tableLen(itemList)
    if tagCount > 98 then
        expensive = true
    else
        expensive = false
    end


for k, item in pairs(itemList) do
    text = text .. '\n\n\n' .. string.format(L.t('Item with the %s Tag:', tagCount), tagName) .. '\n'


text = text .. '<div style="border: 5px outset #A9A9A9; background: #DCDCDC; display:inline-block; width: auto; padding: 10px; margin: 10px; text-align: center; vertical-align: middle;">'
    for _, item in pairs(itemList) do
text = text .. '<div class="iconContainer">'
        text = text .. icon_frame(item, item, nil, '<h3>[[' .. item .. ']]</h3>', expensive)
text = text .. '<div class="iconStack">[[File:'..string.gsub(item, ' ', '')..'_Icon.png|class=iconBlue|link='..item..']]</div>'
    end
text = text .. '<div class="iconBorder"></div></div>'
 
text = text .. '<h3>'..item..'</h3></div>'
    return text
end


-- text = text .. '{{IconFrame|file='..item..'_Icon.png|link = '..item..'|text = <h3>[['..item..']]</h3>}}'
end
return text
end
return p
return p

Latest revision as of 19:23, 16 March 2021

Documentation[edit source]

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 Utils = require('Module:Utils')
local L = require('Module:Localization')

local p = {}

local function icon_frame(name, link, bg, text, expensive)
    local icon = Utils.build_icon(name, link, nil, bg, nil, expensive)
    return '<div style="border: 5px outset #A9A9A9; background: #DCDCDC; display:inline-block; width: auto; padding: 10px; margin: 10px; text-align: center; vertical-align: middle;">' .. icon .. text ..'</div>'
end

-- 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 itemData = mw.loadData("Module:ItemData")

    local tagList = itemData.tags

    local itemList = tagList[tagName]

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

    local text = ""

    local tagLink = L.t('%s Tag'):format(tagName)

    text = text .. icon_frame(L.tag(tagName) .. 'Tag', tagLink, 'iconWhite', '<h3>[[' .. tagLink .. ']]</h3>', false)

    local tagCount = Utils.tableLen(itemList)
    if tagCount > 98 then
        expensive = true
    else
        expensive = false
    end

    text = text .. '\n\n\n' .. string.format(L.t('Item with the %s Tag:', tagCount), tagName) .. '\n'

    for _, item in pairs(itemList) do
        text = text .. icon_frame(item, item, nil, '<h3>[[' .. item .. ']]</h3>', expensive)
    end

    return text
end

return p