ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.

Module:Description: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
m (Changed protection level for "Module:Description" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
 
m (Use mw.loadData to load static data once per page)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Grabs args from the parent frame
local Utils = require('Module:Utils')
-- Trims and parses the args into a table, then returns the table
function norm()
    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


-- Main entry point for the Module
-- Main entry point for the Module
function p.main()
function p.main(frame)
     -- get args from the Template
     -- get args from the Template
     local args = norm()
     local args = Utils.normaliseArgs(frame)


     -- Check if an item is given, return its description from
     -- Check if an item is given, return its description from
     -- Module:ItemData if it item is specified
     -- Module:ItemData if it item is specified
     if args.item then
     if args.item then
         local itemData = require( "Module:ItemData" )
         local itemData = mw.loadData( "Module:ItemData" )
         if itemData.items[args.item] == nil then
         if itemData.items[args.item] == nil then
             return 'None'
             return 'None'

Latest revision as of 13:01, 27 February 2021

Documentation[edit source]

This module provides the back end functionality of the Template:Description. If the template is passed an item name, this module pulls the item's description from Module:ItemData.

Usage[edit source]

See Template:Description


local p = {}

local Utils = require('Module:Utils')

-- Main entry point for the Module
function p.main(frame)
    -- get args from the Template
    local args = Utils.normaliseArgs(frame)

    -- Check if an item is given, return its description from
    -- Module:ItemData if it item is specified
    if args.item then
        local itemData = mw.loadData( "Module:ItemData" )
        if itemData.items[args.item] == nil then
            return 'None'
        elseif itemData.items[args.item].description == '' then
            return 'None'
        else
            return itemData.items[args.item].description
        end
    -- Check if text was given, return the text if so
    elseif args.text then
        return args.text
    -- Error condition, item and text are not given
    else
        local errormsg = 'Improper usage. Please see [[Template:Description]] for help'
        return errormsg
    end
end

return p