Module:Item: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 15: | Line 15: | ||
return text | return text | ||
end | end | ||
end | |||
function formatItemName(itemName) | |||
local _, _, mod, name = string.find(itemName, "([^:]+):([^:]+)") | |||
if not mod then | |||
name = itemName | |||
end | |||
name = string.gsub(name, "_", " ") | |||
name = name:gsub("^%l", string.upper) | |||
return name | |||
end | end | ||
function p.getItemNameAndIMG( frame ) | function p.getItemNameAndIMG( frame ) | ||
local arg = frame.args[1] | local arg = frame.args[1] | ||
local text = | local text = formatItemName(string.lower(arg)) | ||
local fileExists = fileModule.fileExists("File:"..text..".png") | local fileExists = fileModule.fileExists("File:"..string.lower(text)..".png") | ||
if fileExists then | if fileExists then | ||
return "[[File:"..text..".png|20px]] "..capitalizeFirstLetter(text) | return "[[File:"..string.lower(text)..".png|20px]] "..capitalizeFirstLetter(text) | ||
end | end | ||
return arg | return arg |
Revision as of 13:29, 22 October 2023
Documentation for this module may be created at Module:Item/doc
local p = {}
local fileModule = require("Module:FileExists")
local function capitalizeFirstLetter(input)
local firstLetter = input:sub(1, 1)
local restOfString = input:sub(2)
return firstLetter:upper() .. restOfString:lower()
end
local function removeMinecraftPrefix(text)
if text:sub(1, 10) == "minecraft:" then
return text:sub(11)
else
return text
end
end
function formatItemName(itemName)
local _, _, mod, name = string.find(itemName, "([^:]+):([^:]+)")
if not mod then
name = itemName
end
name = string.gsub(name, "_", " ")
name = name:gsub("^%l", string.upper)
return name
end
function p.getItemNameAndIMG( frame )
local arg = frame.args[1]
local text = formatItemName(string.lower(arg))
local fileExists = fileModule.fileExists("File:"..string.lower(text)..".png")
if fileExists then
return "[[File:"..string.lower(text)..".png|20px]] "..capitalizeFirstLetter(text)
end
return arg
end
return p